当我按顺序设置WUNTRACED | WCONTINUED选项调用waitpid()时 知道子进程何时收到SIGSTOP和SIGCONT。的 SIGSTOP不是问题,但是我无法使用WIFCONTINUED(stat)函数捕获sigcont信号,但是当我从终端发送信号时程序正在继续。的 附加的代码说明了问题:子代的SIGCONT 继续子进程,但waitpid()仍然被阻止,并且 父母没有注意到SIGCONT。
但是该代码在Sparc Solaris 2下完全可用
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
main() {
pid_t pid;
if ( (pid = fork()) == -1 )
printf("could not fork");
else if ( pid == 0 ) { /* child */
sleep(1); /* wait for the parent to prepair */
kill(getpid(),SIGSTOP); /* send SIGSTOP to myself */
while(1); /* loop */
}
else { /* parent */
int stat;
waitpid(pid,&stat,WUNTRACED|WCONTINUED);
while ( WIFSTOPPED(stat) || WIFCONTINUED(stat) ) {
if ( WIFSTOPPED(stat) ) {
printf("child was stopped\n");
/* if the next line is uncommented, SIGCONT is caught property */
/* kill(pid,SIGCONT); */
}
if ( WIFCONTINUED(stat) ) {
/* this part is never reached */
printf("child was continued\n");
kill(pid,SIGTERM); /* terminate child */
}
waitpid(pid,&stat,WUNTRACED|WCONTINUED);
}
}
}