What is a zombie?

What is a zombie?


When a program forks and the child finishes before the parent, the
kernel still keeps some of its information about the child in case the
parent might need it -- for example, the parent may need to check the
child's exit status. To be able to get this information, the parent
calls wait(); when this happens, the kernel can discard the
information.



In the interval between the child terminating and the parent calling
wait(), the child is said to be a `zombie'. (If you do `ps', the
child will have a `Z' in its status field to indicate this.) Even
though it's not running, it's still taking up an entry in the process
table. (It consumes no other resources, but some utilities may show
bogus figures for e.g. CPU usage; this is because some parts of the
process table entry have been overlaid by accounting info to save
space.)



This is not good, as the process table has a fixed number of entries and
it is possible for the system to run out of them. Even if the system
doesn't run out, there is a limit on the number of processes each user
can run, which is usually smaller than the system's limit. This is one
of the reasons why you should always check if fork() failed, by
the way!



If the parent terminates without calling wait(), the child is `adopted'
by init, which handles the work necessary to cleanup after the
child. (This is a special system program with process ID 1 -- it's
actually the first program to run after the system boots up).






Home FAQ