Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a zombie process manifest itself?

kill -s SIGCHLD
The above is the code for killing any zombie process, But my question is:
Is there any way by which a Zombie process manifest itself??

like image 536
Dolphin Avatar asked Aug 26 '11 06:08

Dolphin


People also ask

How does a zombie process happen?

A process in Unix or Unix-like operating systems becomes a zombie process when it has completed execution but one or some of its entries are still in the process table. If a process is ended by an "exit" call, all memory associated with it is reallocated to a new process; in this way, the system saves memory.

How does a zombie process disappear?

When a process ends via exit , 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, whereupon the zombie is removed.

What happens to a zombie process if it becomes an orphan?

Zombie processes then also becomes an orphan process. Their PCB still exists in the main memory and they also do not have a parent. These zombie process turned orphan process will then get reparented. The new parent will then collect their status and ask the kernel to clean their PCB.


1 Answers

steenhulthin is correct, but until it's moved someone may as well answer it here. A zombie process exists between the time that a child process terminates and the time that the parent calls one of the wait() functions to get its exit status.

A simple example:

/* Simple example that creates a zombie process. */

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(void)
{
    pid_t cpid;
    char s[4];
    int status;

    cpid = fork();

    if (cpid == -1) {
        puts("Whoops, no child process, bye.");
        return 1;
    }

    if (cpid == 0) {
        puts("Child process says 'goodbye cruel world.'");
        return 0;
    }

    puts("Parent process now cruelly lets its child exist as\n"
         "a zombie until the user presses enter.\n"
         "Run 'ps aux | grep mkzombie' in another window to\n"
         "see the zombie.");

    fgets(s, sizeof(s), stdin);
    wait(&status);
    return 0;
}
like image 122
Tom Zych Avatar answered Sep 17 '22 06:09

Tom Zych