When I call waitpid() with the WUNTRACED|WCONTINUED options set in order to know when the child process receives SIGSTOP's and SIGCONT's. The SIGSTOP is not the problem, but I am unable to catch sigcont signal using WIFCONTINUED(stat) function but program is continuing when I am sending signal from terminal. The appended code illustrates the problem: SIGCONTs to the child do continue the child process but waitpid() remains blocked and the SIGCONT is just not noticed by the parent.
The code is however fully functional under 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);
}
}
}