Why is a zombie process necessary?
Asked Answered
M

3

7

Wikipedia basically gives all the possible information about zombie processes that I NEED to know but just a simple line on how it might be useful..in that a conflict in PIDs will not exist in the event the parent process creates another child process.

How is this then actually "useful"? Wouldn't the PID be then available if the named zombie process were to be removed instead of being kept there?

Or are there any other reasons as to why the zombie process should exist?

Moulmein answered 7/5, 2013 at 10:30 Comment(0)
S
-3

Zombie processes are useful.

Zombie processes allow the parent to be guaranteed to be able to retrieve exit status, accounting information, and process id of the child processes.

A process that doesn't clean up its child zombies isn't programmed properly.

Stillman answered 7/5, 2013 at 16:3 Comment(3)
How would sending SIGCHLD to the parent of a zombie process remove the zombie? Do you have a reference for that? Furthermore every process that creates child processes that terminate at a certain point will create a zombie process. So the statement "A program that creates zombie processes isn't programmed properly." is also not correct. I think you meant "A process that doesn't clean up it's child zombies isn't programmed properly".Cloven
Sending SIGCHLD to the parent happens automatically when the child process exits. Unless the parent process is programmed properly, i.e. with one of the wait() calls, resending it will have zero effect, and if it is programmed properly it will already have handled the original signal, so handling it again will just confuse it and cause an error in whichever wait() call it uses.Yaelyager
It doesn't have to cause an error in the wait() call if the parents SIGCHLD handling is implemented properly. It will just cause an unnecessary signal handler invocation. Otherwise you are right: POSIX compatible OSs will send SIGCHLD if the state of a child changed, therefore manually sending SIGCHLD won't improve the situation a bit.Cloven
B
18

Zombie processes are actually really important and definitely need to exist. First it's important to understand how process creation works in Unix/Linux. The only way to create a new process is for an existing process to create a new child process via fork(). In this way, all of the processes on the system are arranged in a nice orderly tree heirarchy. Try running ps -Hu <your username> on a Linux system to see the heirarchy of processes that you own.

In many programs it is critically important for a parent process to be able to obtain basic information about its child processes that have exited. This basic information includes the exit status and resource usage of the child. When the parent is ready to get information about a dead child process it calls one of the wait() functions to wait for a child to exit and obtain exit status and resource usage info.

But what happens if a child process exits before the parent waits for it? This is where zombie processes become necessary. The operating system can't just discard the child process; the operation of the parent process may be dependent upon knowing the exit status or resource usage of the child. i.e. The parent process might need to know that the child exited abnormally, or it might be collecting CPU usage statistics for its children, etc. So, the only choice is to save off that information and make it available to the parent when it finally does call wait(). This information is what a zombie process is and it's a critical part of how process management works on Unix/Linux. Zombie processes allow the parent to be guaranteed to be able to retreive exit status, accounting information, and process id for child processes, regardless of whether the parent calls wait() before or after the child process exits.

This is why a zombie process is necessary.

Footnote: If the parent process never calls wait(), then the child process is reparented to the init process when the parent process dies, and init will wait() for the child.

Beasley answered 5/6, 2013 at 15:4 Comment(0)
Q
7

The answer is on Wikipedia as well, which is:

This entry is still needed to allow the parent process to read its child's exit status.

Quinte answered 7/5, 2013 at 10:37 Comment(0)
S
-3

Zombie processes are useful.

Zombie processes allow the parent to be guaranteed to be able to retrieve exit status, accounting information, and process id of the child processes.

A process that doesn't clean up its child zombies isn't programmed properly.

Stillman answered 7/5, 2013 at 16:3 Comment(3)
How would sending SIGCHLD to the parent of a zombie process remove the zombie? Do you have a reference for that? Furthermore every process that creates child processes that terminate at a certain point will create a zombie process. So the statement "A program that creates zombie processes isn't programmed properly." is also not correct. I think you meant "A process that doesn't clean up it's child zombies isn't programmed properly".Cloven
Sending SIGCHLD to the parent happens automatically when the child process exits. Unless the parent process is programmed properly, i.e. with one of the wait() calls, resending it will have zero effect, and if it is programmed properly it will already have handled the original signal, so handling it again will just confuse it and cause an error in whichever wait() call it uses.Yaelyager
It doesn't have to cause an error in the wait() call if the parents SIGCHLD handling is implemented properly. It will just cause an unnecessary signal handler invocation. Otherwise you are right: POSIX compatible OSs will send SIGCHLD if the state of a child changed, therefore manually sending SIGCHLD won't improve the situation a bit.Cloven

© 2022 - 2024 — McMap. All rights reserved.