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
|