DragonFly BSD
DragonFly bugs List (threaded) for 2005-12
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

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

From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 26 Dec 2005 23:27:44 -0800 (PST)

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


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

[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]