1、Single Unix Specification支持一个取得进程终止状态的函数--waitid,此函数类似于waitpid:
pid_t wait(int *status);
pid_t waitpid(pid_t pid, int *status, int options);
int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
2、wait3和wait4
pid_t wait3(int *status, int options,struct rusage *rusage);
pid_t wait4(pid_t pid, int *status, int options,struct rusage *rusage);
3、竞争条件
- {
- pid_t pid;
-
- pid = fork();
- if(pid < 0){}
- else if(pid == 0)//一级子进程
- {
- pid = fork();
- {
- if(pid < 0){}
- else if(pid > 0)//一级子进程
- {
- exit(0);
- }
- //二级子进程,睡眠2秒后退出;也就是说二级子进程肯定会后面退出,变成孤儿进程
- sleep(2);
- printf("second child, parents");
- exit(0);
- }
- }
-
- if(waitpid(pid, NULL, 0) != pid){} //这个地方等待的pid算等待谁呢????
-
- exit(0);
- }