'Zombie'에 해당되는 글 1건

  1. 2010.12.14 [C/C++][Linux] Avoiding making zombie process

[C/C++][Linux] Avoiding making zombie process

Language/C&C++ 2010.12.14 18:09

If parent doesn't use 'wait' system call for it's child, that child becomes zombie after end of execution.
(At zombie state, all allocated resources are removed, but it is still in process table for parent to get child's exit status.)
Here is very simple example

int
main (int argc, char* argv[]) {
    if (fork ()) { /* parent */
        [*A]
        sleep(999999);
    } else { /* child */
        sleep(1);
    }
    return 0;
}

In this case, child becomes zombie.
Simplest way to avoid making zombie is get exit status of child by use 'wait' system call at signal handler for SIGCHLD.
The point is, "DO NOT forget about getting child's exit status not to make zombie!"
At above example following codes should be added at [*A]

int status; wait(&status);

Done!

신고
tags : ,
Trackback 0 : Comment 0