wait(2) does not return after SIGCONT

Peter bagoap at xs4all.nl
Sun Jan 22 05:27:54 PST 2006


Hello,

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 can't get the SIGCONTs to work. 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 (can't 
remember the exact version). Under FreeBSD it only works when the 
SIGCONT is sent directly from the parent (see the line in the example 
code that is commented-out). But this is not what I want.

What am I missing? Thanks!

(problem seen with FreeBSD 5.3, 5.4 and 6.0, i386 and adm64)

#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);
		}
	}
}



More information about the freebsd-questions mailing list