When waitpid() is called from a threaded parent process on a child, the status
of the child is returned twice; once to the parent of the process itself, and
the second to the parent thread, currently involved in a ptrace operation on
that child process.
Is it possible that these two are returned in such a way that another child
exiting results in its status being returned inbetween the two returns from the
other child? A race condition in the kernel?
Yes, on the 2.6 linux kernel, with the current ptrace implementation, when a
non-main thread forks a trace-me child, and the main thread is doing waitpid,
the child's exit creates two wait events:
1. for the parent of the child as it exited
Because the tracing thread is not the main thread.
1. for the ptrace-ing process because the target exited
Because the main thread is not the tracing thread.
cute "feature" eh?