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!
'Language > C&C++' 카테고리의 다른 글
[C/C++] Tips for OOP - module initialization. (0) | 2011.05.17 |
---|---|
[Linux][C/C++] strange pipe issue in linux in 'ylisp'. (0) | 2011.02.09 |
[C/C++][Linux] Tips about LD_PRELOAD (0) | 2010.12.13 |
[C/C++][linux] redirect standard io with pipe in code. (0) | 2010.12.10 |
[Linux][C/C++] 'select' function - glibc bug?? (0) | 2010.11.19 |