wait和waitpid

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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值