上代码
学习网络上的文章, 非常感谢
但是和我的环境有点不一样,我简单改了改程序:
[root@localhost wait]# cat waittest.c#include#include #include #include #include main(){ pid_t pc, pr; pc=fork(); if(pc<0) printf("Error occured on forking.\n"); else if(pc==0) { sleep(4); exit(0); } do { pr=waitpid(pc, NULL, WNOHANG); if(pr==0) { printf("No child exited\n"); sleep(1); } }while(pr==0); if(pr==pc) printf("successfully release child %d\n", pr); else printf("some error occured\n");}[root@localhost wait]#
结束