Sponsored Content
Full Discussion: child pid in ZSH
Top Forums Shell Programming and Scripting child pid in ZSH Post 302134405 by dhams on Thursday 30th of August 2007 05:10:33 PM
Old 08-30-2007
child pid in ZSH

I am using ZSH shell in Linux.

I am calling a child program in background mode parallely (say 2-3 threads). I have problem in handling the temporary files of these child programs since the temp file names are unique for all the child process.

To distinguish i want to use the pid in the temp files. But when I use the $$ to fetch the pid it is same across all the chils process since the obtained pid is of the master program which called all these.

Could anyone help me to identify the PID of the current child process so taht i cann append in the temp file names. From the previos threads i saw there is a function called getpid() to get the pid. But am not sure of the usage..
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to kill all child process for a given PID

Is there any build in command in unix to kill all the child process for a given process ID ? If any one has script or command, please let me know. Thanks Sanjay (4 Replies)
Discussion started by: sanjay92
4 Replies

2. Programming

Child Process PID

Hi, Can anybody solve this query? A parent process forks 2 child processes. How does the child process know it's PID without the parent process sending it. Apart from the "ps-ef" option, what other options are there if any? (2 Replies)
Discussion started by: skannan
2 Replies

3. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies

4. Shell Programming and Scripting

In ksh, how does an in-line child sub-process get its own PID?

This is not the same as a few of the other posted items dealing with sub-process pids (that I saw anyway). If zot contains: echo "main mypid: $$ - lastpid: $!" ( echo "block mypid: $$ - lastpid: $! - ppid: $PPID" ps -ef > xxx sleep 5 echo "block mypid: $$ - lastpid: $! - ppid:... (6 Replies)
Discussion started by: MichLab
6 Replies

5. Shell Programming and Scripting

how to capture PID for a child script

Hi, I'm looking for a method where we can capture the PID and if possible the progress of child process especially the ones running in background. can anyone help? (6 Replies)
Discussion started by: aman jain
6 Replies

6. Red Hat

Listing all child pid and deleting it in reverse order

Hi , My problem is that I am not able to list all process id of any process. If you see pstree command it shows many process id under https. But if I run ps command its not listing all the process id for httpd. It is just listing the PPID and immediate child process id only. I... (4 Replies)
Discussion started by: pratapsingh
4 Replies

7. Shell Programming and Scripting

Getting child process id for a given PID

HI Am trying to get child process id for a PID using ksh.. ps -ef | grep xntpd root 3342472 2228308 0 12:17:40 - 0:00 /usr/sbin/xntpd root 4522024 6488316 0 12:18:56 pts/0 0:00 grep xntpd root 6291614 3342472 0 12:17:40 - 0:00 /usr/sbin/xntpd Here now i... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

8. Shell Programming and Scripting

I need to save a pid of a child started with $: su <user> -c “nohup …”

Hello, I want to save pid of a child process but I get empty file. su myuser -c "nohup ./mydaemon.sh >/dev/null 2>&1 & print $! > mydaemon.pid" This one works: nohup ./mydaemon.sh >/dev/null 2>&1 & print $! > mydaemon.pid Please help. Thank you in advance. (2 Replies)
Discussion started by: vincegata
2 Replies
wait3(2)							System Calls Manual							  wait3(2)

NAME
wait3(), wait4() - wait for child process to change state SYNOPSIS
DESCRIPTION
The and functions allow the calling process to obtain various status information for a caller's child process based on the options speci- fied. If status information is available for two or more child processes, the order of which process to report status on is not defined. The function is similar to except that waits for a specific child as indicated by the pid parameter. Note that the following call is equivalent to the call: Note that the following call is equivalent to the call: In both of the previous prototypes, on successful completion, if the resource_usage argument to or is not a null pointer, the structure that the resource_usage argument points to is filled in for the child process identified by the return value. The pid argument specifies a child process for which status is requested. The following rules define which status information is returned: o If pid is equal to (pid_t) -1, status is requested for any child process. o If pid is greater than 0, it specifies the process ID of a single child process for which status is requested. o If pid is 0, status is requested for any child process whose process group ID is equal to that of the calling process. o If pid is less than (pid_t) -1, status is requested for any child process whose process group ID is equal to the absolute value of pid. The stat_loc argument is the address where status about the specified child process is placed. The options argument is constructed from the bitwise-inclusive OR of zero or more of the following flags defined in the header file: The status of any continued child process specified by pid that has not been reported since it continued is reported to the requesting process. The and functions will not suspend execution of the calling process if status is not immediately available for one of the child processes specified by pid. This causes the wait not to be registered. This means that the registered process that is being waited on, can be waited on again with identical results, provided that the status of the child does not change in the meantime. The status of any child processes specified by pid that are stopped and whose status has not yet been reported since they stopped, will also be reported to the requesting process. The resource_usage argument points to the resource utilization structure. APPLICATION USAGE
Threads Considerations In a multi-threaded application, only the calling thread is suspended by and The and functions will not return until all threads in the process have reached the desired state. For example, and will not return until all threads have terminated. If the or options are specified, and will not return until all threads have stopped or continued respec- tively. RETURN VALUE
If or returns because the status of a child process is available, the return value is the process ID of that child process. If or returns due to the receipt of a signal, the return value receives a and is set to If or was called with the options argument where status is not available for any process specified by the pid argument, will be returned. Otherwise, (pid_t) will be returned and will be set to indicate the error. ERRORS
If or fails, is set to one of the following values: The calling process has no existing unwaited-for child processes; or the states specified by the options argument are invalid for the set of processes specified by the pid argument. Problems were encountered in the retrieval of status information for the specified child process. The or function has been interrupted by a signal. The value in the location pointed to by the stat_loc argument is unde- fined. The options argument to or is invalid. WARNINGS
The behavior of and is affected if the signal is set to See the WARNINGS section of signal(5). Signal handlers that cause system calls to be restarted can affect the condition described above (see bsdproc(3C) and sigaction(2)). AUTHOR
The and functions were developed by HP, AT&T, and the University of California, Berkeley. SEE ALSO
exec(2), exit(2), fork(2), pause(2), wait(2), waitpid(2). wait3(2)
All times are GMT -4. The time now is 02:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy