1.wait
NAME
wait, waitpid, waitid - wait for process to change state
SYNOPSIS
#include <sys/types.h>
#include <sys/wait.h>
pid_t wait(int *status);
父进程一旦调用了wait就立即阻塞自己,由wait自动分析是否当前进程的某个子进程已经退出,如果让它找到了这样一个已经变成僵尸的子进程,wait就会收集这个子进程的信息,并把它彻底销毁后返回;如果没有找到这样一个子进程,wait就会一直阻塞在这里,直到有一个出现为止
简而言之 就是死等 一定是阻塞的, 不能等待一个特定的进程
子进程的状态保存在一个int 的status的变量中,返回子进程的id号
2.waitpid
pid_t waitpid(pid_t pid, int *status, int options);
The value of pid can be:
< -1 meaning wait for any child process
whose process group ID is equal to the absolute value of pid.
-1 meaning wait for any child process.
0 meaning wait for any child process whose
process group ID is equal to that of the calling process.
> 0 meaning wait for the child whose process ID is
equal to the value of pid.
The value of options is an OR of zero
or more of the following constants:
WNOHANG return immediately if no child has exited.
WUNTRACED also return if a child has stopped
(but not traced via ptrace(2)).
Status for traced children which have stopped is provided
even if this option is not specified.
WCONTINUED (since Linux 2.6.10)
also return if a stopped child has been resumed by
delivery of SIGCONT.
waitpid可以是非阻塞的,设置option
4801

被折叠的 条评论
为什么被折叠?



