waitpid() with WUNTRACED flag? (was Re: Hang on ctrl+Z after the MPSAFE tsleep/wakeup commit)

YONETANI Tomokazu qhwt+dfly at les.ath.cx
Tue Dec 27 00:24:23 PST 2005


On Mon, Dec 26, 2005 at 11:27:44PM -0800, Matthew Dillon wrote:
> :Content-Type: text/plain; charset=us-ascii
> :Content-Disposition: attachment; filename="a.c"
> :...
> 
>     I think it's the same issue.  The ^Z effects all processes in
>     the process group.  waitpid in the parent tries to return the
>     stopped state of the child, but the parent itself is stopped
>     and the status is not returned until you 'fg'.  This starts
>     both parent and child, but then the parent processes the
>     return from the waitpid and stops itself again.

Ok, the code doesn't really reflect my question here; on computers here
running other OSes, including DragonFly 1.2.x-RELEASE, waitpid() (or wait4)
doesn't return after ^Z+`fg' even with WUNTRACED (I can confirm this by the
fact that warnx() doesn't print "WSTOPSIG(%d) = %d\n" message), thus no such
problem exists.  I don't know if it's an (POSIX-ly or SUS-ly?) expected
behavior, but are we going to change that?

> :	for (;;) {
> :		caught = waitpid(pid, &st, WUNTRACED);
> :		warnx("waitpid returned %d\n", caught);
> :		errno = WEXITSTATUS(st);
> :		if (caught == -1)
> :			return 1;
> :		else if (WIFSTOPPED(st)) {
> :			sig = WSTOPSIG(st);
> :			warnx("WSTOPSIG(%d) = %d\n", st, sig);
> :			sig = SIGSTOP;
> :			raise(sig);
> :			warnx("after raise(%d)\n", sig);
> :		}





More information about the Bugs mailing list