strange pid and ppid problem


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users strange pid and ppid problem
# 1  
Old 03-10-2005
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
# 2  
Old 03-10-2005
i guess the value you are setting to 'x' is having different scope
from the 'x' of while loop of parent process.
# 3  
Old 03-10-2005
If a parent dies, the child process is adopted by init. When the child dies, init will reap it. To create a zombie, the child must die and the living parent must not issue a wait.
# 4  
Old 03-10-2005
This message has been deleted

Last edited by blowtorch; 03-10-2005 at 11:35 PM.. Reason: didnt read Unix Daemon's explaination right
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

strange problem

hello all, i am having problem in accessing a directory.I dont think its a permission issue.can anyone help me out. I am using korn sell code: $ ls -ltr sc* lrwxrwxrwx 1 essbase essbase 21 Oct 8 2010 sc_ssp -> /work/nfs/nas2/sc_ssp $ cd sc_ssp ksh: sc_ssp: not found $ (6 Replies)
Discussion started by: manid
6 Replies

3. Shell Programming and Scripting

Strange problem.

Well, my script started off to do what i wanted. Now, i think its not recognizing the pattern so its not moving anything. What i have to do is execute my script command for the move to take effect. So i did that and yayy it worked. Strange thing is that my DESTDIR was empty to begin with.... (2 Replies)
Discussion started by: oxoxo
2 Replies

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

5. Shell Programming and Scripting

Problem with storage of PID's to variables

I have the following problem to be solved: I read a .csv file (tempfile), fetch the values into variables F1 to F5. Variables F1, F2, F3 are parameters used for running a program (blablaprogram). Variable F4 I want to use to store the PID-value in and variable F5 is used for storing the return... (3 Replies)
Discussion started by: zwiebertje11
3 Replies

6. Shell Programming and Scripting

Strange problem

I am using SunOS 5.9 and I don't know why all my commands are getting executed as if an extra 'enter' has been pressed. What could be the reason and how to correct it? Please help. Asty (2 Replies)
Discussion started by: Asty
2 Replies

7. Linux

very strange problem

I have installed Fedora Core on a Toshiba Satellite Pro4600 laptop recently I have experienced a rather mysterious problem if I touch anything specially the keyboard or mouse I see this stuff “67yujhnmyyy” straight away some time it won't stop for while like this... (5 Replies)
Discussion started by: kemobyte
5 Replies

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

9. UNIX for Dummies Questions & Answers

strange...problem

Hi.. Some of my application were not running properly due to lack of virtual memory.....so wht i did add one free harddisk as swap file system...and increased the swap memory.. But since than my root file system is showing 100% full thr is no space left...is thr any link between these two..... (1 Reply)
Discussion started by: Prafulla
1 Replies

10. UNIX for Dummies Questions & Answers

Strange problem.Please Help !

I¡¯m a network operator, mine is an IBM PC server 320, operating system SCO unix 3.2v4.2, triton 3.1 of Baan. Recently, my server went dead every a few hours, no sign & signal shows malfunction suddenly. It looks like a sudden power failure, but the indicator of main power supply is on. Normal... (1 Reply)
Discussion started by: lyhsm
1 Replies
Login or Register to Ask a Question