init adopts zombie process?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers init adopts zombie process?
# 1  
Old 07-01-2009
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  
Old 07-02-2009
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  
Old 07-02-2009
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  
Old 07-02-2009
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Zombie process

What is the overhead associated with zombie process?Is it running out of process-ID?:confused: Since some information is stored in process table.. Thanks in Advance (4 Replies)
Discussion started by: jois
4 Replies

2. UNIX for Dummies Questions & Answers

Zombie process question

Hey guys, So i did some research on the site but previous posts answered most of my questions about zombie processes but I have one question that didnt seem to get addressed "how do you find the parent or parent ID of a zombie process so you can kill it?" I know p -kill doesnt always just... (6 Replies)
Discussion started by: kingpin007
6 Replies

3. AIX

zombie process

Is there an equivilant to the preap command in AIX that would allow me to get rid of a zombie process. I am new to AIX, moving over from Solaris and in the past I have been able to preap the pid on the defunct process to clean them up. I have looked around and the best I can see is that it may... (3 Replies)
Discussion started by: sboots
3 Replies

4. Solaris

zombie process

dear friends, in an interview they asked me what is zombie process. how we can identifying these process.if can you kill all zombie process. (8 Replies)
Discussion started by: sijocg
8 Replies

5. Shell Programming and Scripting

Zombie process

Hi I need help because I don't know if it is possible to add a find inside a cat. like I have a file with the pid of the process that use to became zombie. And I have the same pid stored in the var (pid1) now, I have no clue how to check if the the find finds the pid or even if it's... (2 Replies)
Discussion started by: ruben.rodrigues
2 Replies

6. UNIX for Dummies Questions & Answers

Re: How do I recognize a zombie process?

Hey Guys, I am not really new to Unix/Linux however I was never taught how to spot a zombie process. I used top to check out the processes I was running and how the resources were looking and in the upper right it said 1 zombie, I have attached a jpeg of it. Thank you in advance for your... (4 Replies)
Discussion started by: pikecoguy
4 Replies

7. Linux

zombie process

Hi What is the command to find only the zombie processes?? How to write the code in C to fetch the no. of zombie processes?? Thanx (5 Replies)
Discussion started by: jeenat
5 Replies

8. UNIX for Advanced & Expert Users

zombie daemon process!!

My daemon process is the child of init and init has the responsibility to remove it, once it turns zombie. But I want to ask why the daemon process which is child of init turns zombie in the first place. What measures I have to take to avoid this? rish (1 Reply)
Discussion started by: rish2005
1 Replies

9. UNIX for Advanced & Expert Users

Zombie process

I would like to create a zombie process so that I can test monitoring software functionality. Any techniques? (2 Replies)
Discussion started by: swhitney
2 Replies

10. UNIX for Dummies Questions & Answers

Zombie process

How do i kill a zombie process. Is it that only root can kill a zombie process. (8 Replies)
Discussion started by: orca
8 Replies
Login or Register to Ask a Question