The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 05:12 PM
Zombie process orca UNIX for Dummies Questions & Answers 8 04-26-2002 02:54 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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?
  #2 (permalink)  
Old 07-01-2009
robsonde robsonde is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 158
So what’s with the zombies??

A zombie process is a process that has completed execution but still has an entry in the process table. This entry is still needed to allow the process that started the (now zombie) process to read its exit status. The term zombie process derives from the common definition of zombie (an undead person)
In the term's colourful metaphor, the child process has died but has not yet been reaped.
Zombies can be identified in the output from the UNIX ps command by the presence of a “Z” in the “STAT” column. Zombies that exist for more than a short period of time typically indicate a bug in the parent program, the presence of a few zombies is not worrisome in itself, but may indicate a problem that would grow serious under heavier loads. Since there is no memory allocated to zombie processes except for the process table entry itself, the primary concern with many zombies is not running out of memory, but rather running out of process ID numbers.
To remove zombies from a system, remove the parent process. When a process loses its parent, init becomes its new parent. Init periodically executes the wait system call to reap any zombies with init as parent.
  #3 (permalink)  
Old 07-02-2009
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,930
Quote:
by the time the parent terminates, if there are child processes already terminated and still running, init will adopt the running ones
Init will adopt only those processes for which there is no parent process that is currently alive (or a slot in the process table entry) is no more, but in your case, child has exited first and it enters zombie state for the parent to collect the status of the created child process. Since the parent process of the child is alive very much ( in sleep mode ) init cannot adopt that, and once the parent process terminates, child stats is collected and there is no need for the child process to remain as zombie and it becomes completely relieved.
  #4 (permalink)  
Old 07-02-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,864
Right, so you can try issuing a kill -9 to the parent process before your program goes to zombie. Then it should get picked up by init.
Sponsored Links
Reply

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 01:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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