Sponsored Content
Full Discussion: printing ppid,child pid,pid
Top Forums Programming printing ppid,child pid,pid Post 47045 by a25khan on Sunday 1st of February 2004 11:48:22 PM
Old 02-02-2004
perderabo,
yeah it makes sense that both child and process will execute the 3 staments, giving 6 results.
is the output in order of child,child,child,parent,parent,parent
now can u correct me if i m wrong here

0 - is the return int value that is always passed to the child to the child
this one is executed by printf("%d\n",pid);

28873 - is the pid of the child which is contained in the parent
this also executed by printf("%d\n",getpid());


28872 - is the pid of the parent
it is executed by printf("%d\n",getppid());

now running for parent
28873 - is the pid of the child
it is executed by printf("%d\n",pid);

28872 - is the pid of the parent that makes the child here
it is executed by printf("%d\n",getpid());

28086 - is the pid of the shell running this program
it is executed by printf("%d\n",getppid());

arrrrrrrrghSmilie i am confuuuuuuuused!
Hope i got that right Smilie
Sorry i am slow and ask too many questionsSmilie

Last edited by a25khan; 02-02-2004 at 12:57 AM..
 

10 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. UNIX for Advanced & Expert Users

strange pid and ppid problem

Hi all, Please look into the following code : int main() { char command; int pid, ppid; ppid = getpid(); /* Get the parent pid */ pid = fork(); /* Fork */ if ( pid ==0 ) { sprintf( command, " gdb a.out %d ", ppid ); printf( "Command line is %s\n", command ); system( command... (3 Replies)
Discussion started by: asvija
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

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... (3 Replies)
Discussion started by: dhams
3 Replies

6. UNIX for Dummies Questions & Answers

Comparing CRON PID w/Current PPID

All, I've got a script that needs to check if it was started by cron. The code seems to be right, but it's not running correctly if cron starts it. Am I getting the pid's correctly? I'm not having any luck figuring it out. :confused: Any help is appreciated! CRON_ID=$(ps -aef | grep... (1 Reply)
Discussion started by: GregWold
1 Replies

7. 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

8. UNIX for Dummies Questions & Answers

PID and PPID - please explain :(-

Hi, I need some help understanding PID and PPID that is shown by the ps -ef output. OS is Solaris 5.8. :wall: There are several Oracle databases and processes running on this server and they all have the same PPID. Does that mean they are all spawned off the same startup script? I then... (1 Reply)
Discussion started by: newbie_01
1 Replies

9. 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

10. 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
PCNTL_WAITPID(3)							 1							  PCNTL_WAITPID(3)

pcntl_waitpid - Waits on or returns the status of a forked child

SYNOPSIS
int pcntl_waitpid (int $pid, int &$status, [int $options]) DESCRIPTION
Suspends execution of the current process until a child as specified by the $pid argument has exited, or until a signal is delivered whose action is to terminate the current process or to call a signal handling function. If a child as requested by $pid has already exited by the time of the call (a so-called "zombie" process), the function returns immedi- ately. Any system resources used by the child are freed. Please see your system's waitpid(2) man page for specific details as to how wait- pid works on your system. PARAMETERS
o $pid - The value of $pid can be one of the following: possible values for $pid +-----+---------------------------------------------------+ | | | |< -1 | | | | | | | wait for any child process whose process group | | | ID is equal to the absolute value of $pid. | | | | | | | | -1 | | | | | | | wait for any child process; this is the same be- | | | haviour that the wait function exhibits. | | | | | | | | 0 | | | | | | | wait for any child process whose process group | | | ID is equal to that of the calling process. | | | | | | | |> 0 | | | | | | | wait for the child whose process ID is equal to | | | the value of $pid. | | | | +-----+---------------------------------------------------+ Note Specifying -1 as the $pid is equivalent to the functionality pcntl_wait(3) provides (minus $options). o $status -pcntl_waitpid(3) will store status information in the $status parameter which can be evaluated using the following functions: pcntl_wifexited(3), pcntl_wifstopped(3), pcntl_wifsignaled(3), pcntl_wexitstatus(3), pcntl_wtermsig(3) and pcntl_wstopsig(3). o $options - The value of $options is the value of zero or more of the following two global constants OR'ed together: possible values for $options +----------+---------------------------------------------------+ | | | | WNOHANG | | | | | | | return immediately if no child has exited. | | | | | | | |WUNTRACED | | | | | | | return for children which are stopped, and whose | | | status has not been reported. | | | | +----------+---------------------------------------------------+ RETURN VALUES
pcntl_waitpid(3) returns the process ID of the child which exited, -1 on error or zero if WNOHANG was used and no child was available SEE ALSO
pcntl_fork(3), pcntl_signal(3), pcntl_wifexited(3), pcntl_wifstopped(3), pcntl_wifsignaled(3), pcntl_wexitstatus(3), pcntl_wtermsig(3), pcntl_wstopsig(3). PHP Documentation Group PCNTL_WAITPID(3)
All times are GMT -4. The time now is 08:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy