Questions tagged [zombie-process]

On Unix and Unix-like computer operating systems, a zombie process or defunct 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.

Definition

On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution (via the exit system call) but still has an entry in the process table: it is a process in the "Terminated state". This occurs for child processes, where the entry is still needed to allow the parent process to read its child's exit status: once the exit status is read via the wait system call, the zombie's entry is removed from the process table and it is said to be "reaped". A child process always first becomes a zombie before being removed from the resource table. In most cases, under normal system operation zombies are immediately waited on by their parent and then reaped by the system – processes that stay zombies for a long time are generally an error and cause a resource leak.

The term zombie process derives from the common definition of zombie — an undead person. In the term's metaphor, the child process has "died" but has not yet been "reaped". Also, unlike normal processes, the kill command has no effect on a zombie process.

Zombie processes should not be confused with orphan processes: an orphan process is a process that is still executing, but whose parent has died. These do not remain as zombie processes; instead, (like all orphaned processes) they are adopted by init (process ID 1), which waits on its children. The result is that a process that is both a zombie and an orphan will be reaped automatically. Wikipedia

How do I see if there are zombie processes on a system?

Run “ps aux” and look for a Z in the STAT column.

How do I remove zombie processes from a system?

Well, first you can wait. It’s possible that the parent process is intentionally leaving the process in a zombie state to ensure that future children that it may create will not receive the same pid. Or perhaps the parent is occupied, and will reap the child process momentarily.

Secondly, you can send a SIGCHLD signal to the parent (“kill -s SIGCHLD “). This will cause well-behaving parents to reap their zombie children.

Finally, you can kill the parent process of the zombie. At that point, all of the parent’s children will be adopted by the init process (pid 1), which periodically runs wait() to reap any zombie children.

After the zombie is removed, its process identifier (PID) and entry in the process table can then be reused. However, if a parent fails to call wait, the zombie will be left in the process table, causing a resource leak. In some situations this may be desirable – the parent process wishes to continue holding this resource – for example if the parent creates another child process it ensures that it will not be allocated the same PID. On modern UNIX-like systems (that comply with SUSv3 specification in this respect), the following special case applies: if the parent explicitly ignores SIGCHLD by setting its handler to SIG_IGN (rather than simply ignoring the signal by default) or has the SA_NOCLDWAIT flag set, all child exit status information will be discarded and no zombie processes will be left.

Dangers of Zombie Processes:

Zombie processes don't use up any system resources other than a tiny amount of system memory needed to store their process descriptors. However, each zombie process retains its process ID (PID). Linux systems have a finite number of process IDs (32767 by default on 32-bit systems). If zombies are accumulating at a very quick rate (e.g., if improperly programmed server software is creating zombie processes under load), then eventually no PIDs will be available for other processes, preventing them from launching.

While a few zombie processes hanging around are no problem, they do indicate a bug with the parent process that spawned them.

Related tags

Related Links:

305 questions
14
votes
1 answer

R parallel computing and zombie processes

This is basically a follow up to the this more specialized question. There have been some posts about the creation of zombie processes when doing parallel computing in R: How to stop R from leaving zombie processes behind How to kill a doMC worker…
lord.garbage
  • 5,884
  • 5
  • 36
  • 55
14
votes
3 answers

How can I prevent zombie child processes?

I am writing a server that uses fork() to spawn handlers for client connections. The server does not need to know about what happens to the forked processes – they work on their own, and when they're done, they should just die instead of becoming…
thejh
  • 44,854
  • 16
  • 96
  • 107
13
votes
5 answers

c# MSOffice Interop Word will not kill winword.exe

I'm writing an application that needed a MSWord document parser. I'm using Microsoft.Office.Interop.Word.Document to extract the texts from the documents, but even if i use doc.Close() the document, from taskManager i can see that winword.exe are…
Krispy
  • 133
  • 1
  • 1
  • 5
13
votes
3 answers

Zombie vs Defunct processes?

Is there a difference between zombie and defunct processes? I have found the wikipedia article where it is written that this two are the same. In that case why it is needed to have 2 different terms for the same…
user2420079
  • 251
  • 3
  • 17
12
votes
1 answer

Why zombie processes exist?

Wikipedia says "A child process that terminates but is never waited on by its parent becomes a zombie process." I run this program: #include #include #include int main() { pid_t pid, ppid; printf("Hello…
user567879
  • 5,139
  • 20
  • 71
  • 105
11
votes
3 answers

Starting a daemon from PHP

For a website, I need to be able to start and stop a daemon process. What I am currently doing is exec("sudo /etc/init.d/daemonToStart start"); The daemon process is started, but Apache/PHP hangs. Doing a ps aux revealed that sudo itself changed…
ThaMe90
  • 4,196
  • 5
  • 39
  • 64
10
votes
2 answers

How do zombies harm?

From perlipc/Signals: eval { local $SIG{ALRM} = sub { die "alarm clock restart" }; alarm 10; flock(FH, 2); # blocking write lock alarm 0; }; if ($@ and $@ !~ /alarm clock restart/) { die } If the operation being timed out is system() or…
sid_com
  • 24,137
  • 26
  • 96
  • 187
10
votes
2 answers

Golang: Child Processes become Zombies

I have an application in Go that reroutes the STDIN and STDOUT of binaries and then runs them. In a nutshell I'm doing: - create command object with the binary path (lets call the object command A) - create command object with the binary path…
Anfernee
  • 1,445
  • 1
  • 15
  • 26
9
votes
6 answers

zombie process can't be killed

Is there a way to kill a zombie process? I've tried calling exit to kill the process and even sending SIGINT signal to the process, but it seems that nothing can kill it. I'm programming for Linux.
user12707
  • 294
  • 1
  • 5
  • 12
8
votes
2 answers

UNIX Zombies and Daemons

I understand that a zombie is created when a process doesn't clean-up well (its resources aren't reclaimed/reaped). After calling fork() to create a new process, the parent should always call waitpid on that process to clean it up. I also have…
John Humphreys
  • 37,047
  • 37
  • 155
  • 255
8
votes
2 answers

How do I ensure that a spawned Child process is killed if my app panics?

I'm writing a small test that starts a daemon process and tests it e.g: let server = Command::new("target/debug/server").spawn(); // do some tests server.kill(); The typical way to fail a test is to panic. Unfortunately this means that kill()…
j16r
  • 189
  • 2
  • 7
8
votes
1 answer

Where do Zombie processes go after their parent dies?

A Zombie process is a process that has completed execution, but still has an entry in the process table (the parent hasn't read its exit code, or in other words, it hasn't been "reaped"). An Orphan process is a process whose parent has finished,…
so.very.tired
  • 2,958
  • 4
  • 41
  • 69
7
votes
1 answer

Zombie process in python multiprocessing daemon

After researching python daemons, this walk through seemed to be the most robust: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ Now I am trying to implement a pool of workers inside the daemon class which I believe is…
Aaron Robinson
  • 406
  • 1
  • 6
  • 13
7
votes
2 answers

What does reaping children imply?

I have just had a lecture that sums reaping as: Reaping Performed by parent on terminated child (using wait or waitpid) Parent is given exit status informaton Kernel then deletes zombie child process So I understand that reaping is done by calling…
That Guy
  • 2,349
  • 2
  • 12
  • 18
7
votes
2 answers

Programmatically check for zombie child process in Linux using C

I have written a simple C program in RedHat Linux which waits for a child process using waitpid after calling execv. int main( int argc, char * argv[] ) { int pid; int status = 0; int wait_ret; const char * process_path = argv[1]; …
Nathan Owen
  • 155
  • 10
1
2
3
20 21