Unix waitpid是否会阻止已停止的作业?

Unix waitpid是否会阻止已停止的作业?,unix,process,Unix,Process,我有一个子进程,它收到了SIGTSTP信号。 当我打电话时 waitpid(-1,NULL,0); 父块,但在文档中,它写入waitpid返回,其中包含停止作业的pid #include<unistd.h> #include<stdio.h> #include<signal.h> #include<sys/wait.h> main() { int pid; if( (pid=fork()) > 0) { sleep(5);

我有一个子进程,它收到了SIGTSTP信号。 当我打电话时

waitpid(-1,NULL,0);
父块,但在文档中,它写入waitpid返回,其中包含停止作业的pid

#include<unistd.h>
#include<stdio.h>
#include<signal.h>
#include<sys/wait.h>
main() {
int pid;
if( (pid=fork()) > 0) {
    sleep(5);
    if(kill(pid,SIGTSTP) < 0)
        printf("kill error\n");
    int status;
    waitpid(-1,&status,0);
    printf("Returned %d\n",WIFSTOPPED(status));
}
else if(pid==0) {
    while(1);
}
}
#包括
#包括
#包括
#包括
main(){
int-pid;
如果((pid=fork())>0){
睡眠(5);
if(压井(pid,SIGTSTP)<0)
printf(“终止错误\n”);
智力状态;
waitpid(-1,状态为0(&S);
printf(“返回%d\n”,WIFSTOPPED(状态));
}
否则如果(pid==0){
而(1),;
}
}

您错过了
waitpid
(第三个参数)的
WUNTRACED
选项。否则,在作业终止之前它不会返回


设置
WUNTRACED
选项时,由于
SIGTTIN
sigttoo
SIGTSTP
SIGSTOP
信号而停止的当前进程的子进程也会报告它们的状态(从mac手册页)。

您错过了
waitpid
WUNTRACED
选项(第3个参数)。否则,它在作业终止之前不会返回


设置
WUNTRACED
选项时,由于
SIGTTIN
sigttoo
SIGTSTP
SIGSTOP
信号而停止的当前进程的子进程也会报告其状态(从mac手册页).

非常感谢你的回答。我应该好好阅读文档。我在我的大程序中浪费了两个小时寻找其他错误。非常感谢你的回答。我应该好好阅读文档。我在我的大程序中浪费了两个小时寻找其他错误。