I have a child process which has received a SIGTSTP signal.
When I call
waitpid(-1,NULL,0);
the parent blocks, but in documentation, its written that waitpid returns with pid for stopped jobs.
#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);
}
}
You missed the option
WUNTRACEDforwaitpid(3rd argument). Otherwise it doesn’t return until the job is terminated.When the
WUNTRACEDoption is set, children of the current process that are stopped due to aSIGTTIN,SIGTTOU,SIGTSTP, orSIGSTOPsignal also have their status reported (from the mac man page).