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

Matthew Dillon dillon at apollo.backplane.com
Mon Dec 26 23:27:43 PST 2005


: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.

    I'm not sure if there's a good solution to the problem, or how
    much code uses the same sort of construct.  Even the original code
    still had this race condition, it was just a much smaller window
    of opportunity.

    One possible solution is to have the kernel wait4() check for a pending
    stop request on the parent process after being woken up but before it 
    checks the state of other processes.  This would reduce (but not
    eliminate) the window of opportunity back to what it was before
    the tsleep work went in.

						-Matt

:	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