Created
November 30, 2016 10:07
-
-
Save ictlyh/bf999d2d16435c397a5d3d5f455f241e to your computer and use it in GitHub Desktop.
Demo of creating zombie process.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Demo of creating zombie process. | |
* Build: gcc test-zombie.c -o test-zombie | |
* Run: ./test-zombie | |
*/ | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <errno.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
pid_t pid; | |
pid = fork(); | |
if (pid < 0) | |
{ | |
perror("fork error:"); | |
exit(1); | |
} | |
else if (pid == 0) | |
{ | |
printf("I am child process.I am exiting.\n"); | |
exit(0); | |
} | |
printf("I am father process.I will sleep two seconds\n"); | |
//等待子进程先退出 | |
sleep(2); | |
//输出进程信息 | |
system("ps -o pid,ppid,state,tty,command"); | |
printf("father process is exiting.\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Program output: