The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Zombie process ruben.rodrigues Shell Programming and Scripting 2 03-11-2009 11:13 AM
zombie process jeenat Linux 5 03-28-2008 07:36 AM
zombie daemon process!! rish2005 UNIX for Advanced & Expert Users 1 11-25-2005 09:59 AM
Zombie process swhitney UNIX for Advanced & Expert Users 2 10-22-2004 06:12 PM
Zombie process orca UNIX for Dummies Questions & Answers 8 04-26-2002 03:54 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 07-01-2009
password636 password636 is offline
Registered User
  
 

Join Date: Feb 2008
Location: China
Posts: 6
init adopts zombie process?

Hi
I tried to create a zombie process with the following program:
Code:
int main(void)
{
        pid_t pid;
        int status;

        if ((pid = fork()) < 0)
                perror("fork error");
        else if (pid == 0){ /* child process*/
                exit(0);
        }
        printf("child process ID: %d\n", pid);
        sleep(10);

        return 0;
}
I can observe the "Z" state with the ps command, but this zombie process (the child process) only exists in the duration from its termination to its parent termination. I don't wait() the child process in the parent, so why doesn't the zombie process exist after the parent terminates?

In <apue2>,
Quote:
But what happens if the parent terminates before the child? The answer is
that the init process becomes the parent process of any process whose
parent terminates. We say that the process has been inherited by init. What
normally happens is that whenever a process terminates, the kernel goes
through all active processes to see whether the terminating process is the
parent of any process that still exists.
My understanding is this: by the time the parent terminates, if there are child processes already terminated and still running, init will adopt the running ones, not the already terminated ones. (don't the "active" and "still exists" in apue2 mean this?) So a zombie child process won't be adopted by init. In my case, by the time the parent terminates, the child is not "active" and won't be adopted by init.

Besides, the child process in my program disappears immediately after the parent terminates. As I described, I don't think this is done by init, then who did?
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0