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
409
votes
7 answers

Do zombies exist ... in .NET?

I was having a discussion with a teammate about locking in .NET. He's a really bright guy with an extensive background in both lower-level and higher-level programming, but his experience with lower level programming far exceeds mine. Anyway, He…
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
221
votes
9 answers

How to kill zombie process

I launched my program in the foreground (a daemon program), and then I killed it with kill -9, but I get a zombie remaining and I m not able to kill it with kill -9. How to kill a zombie process? If the zombie is a dead process (already killed), how…
MOHAMED
  • 41,599
  • 58
  • 163
  • 268
83
votes
9 answers

Zombie process vs Orphan process

A Zombie is created when a parent process does not use the wait system call after a child dies to read its exit status, and an orphan is child process that is reclaimed by init when the original parent process terminates before the child. In terms…
MarkAWard
  • 1,699
  • 2
  • 16
  • 28
82
votes
15 answers

Ensuring subprocesses are dead on exiting Python program

Is there a way to ensure all created subprocess are dead at exit time of a Python program? By subprocess I mean those created with subprocess.Popen(). If not, should I iterate over all of the issuing kills and then kills -9? anything cleaner?
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
51
votes
5 answers

Killing a defunct process on UNIX system

I have a defunct process on my system: abc 22093 19508 0 23:29 pts/4 00:00:00 grep ProcA abc 31756 1 0 Dec08 ? 00:00:00 [ProcA_my_collect] How can I kill the above process, without a reboot of the machine? I have…
gagneet
  • 35,729
  • 29
  • 78
  • 113
36
votes
2 answers

What are Zombies and what causes them? Are there Zombie processes and Zombie objects?

I can find questions about zombies but none that directly addresses what they are and why and how they occur. There are a couple that address what zombie processes are in the context of answering a specific question but don't address the…
yabada
  • 967
  • 1
  • 9
  • 16
31
votes
1 answer

wait3 (waitpid alias) returns -1 with errno set to ECHILD when it should not

Context is this Redis issue. We have a wait3() call that waits for the AOF rewriting child to create the new AOF version on disk. When the child is done, the parent is notified via wait3() in order to substitute the old AOF with the new one. However…
antirez
  • 18,314
  • 5
  • 50
  • 44
24
votes
2 answers

Create zombie process

I am interested in creating a zombie process. To my understanding, zombie process happens when the parent process exits before the children process. However, I tried to recreate the zombie process using the following code: #include…
user3354832
  • 655
  • 3
  • 6
  • 13
24
votes
2 answers

Xcode leaving zombie processes after running iOS tests/simulator

After working in Xcode on an iOS app for a few days, I've noticed that there are over 100 zombie processes hanging around. It appears that there is one for each time that I ran unit tests, and possibly one for each time I ran the full app in the…
Mike Mertsock
  • 11,825
  • 7
  • 42
  • 75
21
votes
3 answers

Python-daemon doesn't kill its kids

When using python-daemon, I'm creating subprocesses likeso: import multiprocessing class Worker(multiprocessing.Process): def __init__(self, queue): self.queue = queue # we wait for things from this in Worker.run() ... q =…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
21
votes
2 answers

Docker container refuses to get killed after run command turns into a zombie

first thing first. my system info and versions: $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 13.04 Release: 13.04 Codename: raring $ sudo docker version Client version: 0.9.0 Go version (client):…
AnandKumar Patel
  • 980
  • 9
  • 18
18
votes
1 answer

Proper way of handling threads in kernel?

I've seen bits of scattered information all around, but I can't seem to get to one final answer. How do you clean up a zombie thread in kernel? Just to make sure, and produce a final correct way of handling threads in kernel, I would like to ask…
Shahbaz
  • 46,337
  • 19
  • 116
  • 182
16
votes
2 answers

Remove zombie processes using parallel package

After I have played around for some time using R's parallel package on my Debian-based machine I still can't find a way to remove all zombie child-processes after a computation. I'm searching for a general and OS independent solution. Below a simple…
user625626
  • 1,102
  • 2
  • 10
  • 16
15
votes
6 answers

Why do processes spawned by cron end up defunct?

I have some processes showing up as in top (and ps). I've boiled things down from the real scripts and programs. In my crontab: * * * * * /tmp/launcher.sh /tmp/tester.sh The contents of launcher.sh (which is of course marked…
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
14
votes
1 answer

How to clear GPU memory occupied by zombie process if it's parent is init?

nvidia-smi screenshot The process with PID 14420 is a zombie process and its parent id is 1(init). I want to clear 4436MiB memory occupied by this zombie process without rebooting. How should I proceed?
vikasreddy
  • 339
  • 3
  • 7
1
2 3
20 21