Zombie process

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. 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.

When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes. However, the process's entry in the process table remains. The parent can read the child's exit status by executing the wait system call, at which stage the zombie is removed. The wait call may be executed in sequential code, but it is commonly executed in a handler for the SIGCHLD signal, which the parent receives whenever a child has died.

After the zombie is removed, its process ID 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. In some situations this may be desirable, for example if the parent creates another child process it ensures that it will not be allocated the same process ID. 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.

A zombie process is not the same as an orphan process. An orphan process is a process that is still executing, but whose parent has died. They do not become zombie processes; instead, they are adopted by init (process ID 1), which waits on its children.

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, or just an uncommon decision to reap children (see example). If the parent program is no longer running, zombie processes typically indicate a bug in the operating system. As with other leaks, 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, the SIGCHLD signal can be sent to the parent manually, using the kill command. If the parent process still refuses to reap the zombie, the next step would be to 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.

Examples

Synchronously waiting for specific child processes in a (specific) order may leave zombies present longer than the above-mentioned “short period of time”. It is not necessarily a program bug.

#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
 
int main(void)
{
        pid_t pids[10];
        int i;
 
        for (i = 9; i >= 0; --i) {
                pids[i] = fork();
                if (pids[i] == 0) {
                        sleep(i+1);
                        _exit(0);
                }
        }
 
        for (i = 9; i >= 0; --i)
                waitpid(pids[i], NULL, 0);
 
        return 0;
}

See also

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • zombie process — noun A child process that has terminated but is still listed in the process table, having not yet been reaped by its parent process …   Wiktionary

  • Zombie (disambiguation) — A zombie is an undead person, or, figuratively, a very apathetic person.Zombie may also refer to:General* A derisive name for Canadian conscripts during World War II. See Conscription Crisis of 1944. * zombie , the pseudonymous photographer who… …   Wikipedia

  • Process states — In a multitasking computer system, processes may occupy a variety of states. These distinct states may not actually be recognized as such by the operating system kernel, however they are a useful abstraction for the understanding of… …   Wikipedia

  • Process (computing) — In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that… …   Wikipedia

  • Zombie — Процесс зомби, зомби (англ. zombie process, англ. defunct process) дочерний процесс в Unix системе, завершивший своё выполнение, но еще присутствующий в списке процессов операционной системы, чтобы дать родительскому процессу считать код… …   Википедия

  • Zombie chicken — is a term used for an improperly sedated chicken that awakens after being buried for compost. In the poultry industry, spent hens that are too old to lay eggs are typically killed and composted. They are not used for meat, as these chickens… …   Wikipedia

  • Zombie — This article is about the figure from Haitian religion. For the figure from films such as Night of the Living Dead , see Zombie (fictional). For the philosophical concept, see Philosophical zombie. For other uses, see Zombie (disambiguation) …   Wikipedia

  • Zombie-Prozess — Ein Zombie ist vor allem in Unix ähnlichen Betriebssystemen (wie z. B. Linux) ein Prozess, der beendet ist, aber trotzdem noch in der Prozesstabelle auftaucht und geringfügig Systemressourcen belegt. Ein Zombie richtet selbst keinen Schaden an,… …   Deutsch Wikipedia

  • Zombie (comics) — Superherobox| caption= Tales of the Zombie #1 (Aug. 1973). Art by Boris Vallejo. comic color=background:#ff8080 character name=Zombie real name=Simon William Garth publisher=Marvel Comics debut= Menace #5 (Jul 1953) creators=Stan Lee Bill Everett …   Wikipedia

  • zombie —    In Unix and other operating systems, a dead process that has not yet been deleted from the process table.    Most zombies disappear almost immediately, although from time to time, you may find one that is impossible to delete without rebooting …   Dictionary of networking

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”