LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-09-2005, 07:11 AM   #1
asvija
LQ Newbie
 
Registered: Mar 2005
Posts: 1

Rep: Reputation: 0
strange pid and ppid problem


Hi all,

Please look into the following code :

int main()
{
char command[ 1024 ];
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 );
}

else if ( pid > 0 )
{
int x=1;
printf(" In parent \n" );

while( x );
printf ( "Exiting parent \n" );
}

return 0;
}

As you note, I'm trying to debug the parent from the child process.
I compiled the above program and tried running it on a linux machine. I got the gdb prompt and issued the command set x=0 from gdb prompt, so that the parent comes out of the infinite loop, and then I pressed continue in gdb. The parent exited normally in gdb. The strange fact is that the child also has exited normally without being a zombie. How could this happen ?

I tried this for many times, still I find no zombies on my machine . Can anyone please explain this behaviour

Bye
 
Old 03-10-2005, 01:53 AM   #2
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
If the child exits and the parent is still alive, then the system keeps an association of child with parent, as the exit code needs to be stored in case the parent subsequently calls a wait. The child becomes zombie till the parent does a wait.
however if the parent has exited before the child exiting, then the child is adopted by the init which reaps the exit code and the child does not become a zombie.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make ppid of a process as init without killing its parent shantha Programming 10 12-17-2004 07:36 AM
/var/run/[XXX].pid - Tcl pid code liguorir Linux - Software 1 05-20-2004 10:32 PM
Apache2 PID problem chrisknight Linux - Software 3 02-24-2004 04:36 PM
ERROR: Couldn't write pid to pid file lawrencegoodman Linux - Newbie 2 02-13-2004 08:05 PM
pidof -o %PPID program vanalex Linux - General 2 01-26-2004 09:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration