Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Jan 2006 14:27:41 +0100
From:      Peter <bagoap@xs4all.nl>
To:        freebsd-questions@freebsd.org
Subject:   wait(2) does not return after SIGCONT
Message-ID:  <7.0.1.0.2.20060122134143.02183648@thuiswater.nl>

next in thread | raw e-mail | index | archive | help
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);
		}
	}
}




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7.0.1.0.2.20060122134143.02183648>