fixed many things, including a memory leak.
it doesn't forget about previously seen pids if WNOHANG set.
it doesn't hang in some cases when WNOHANG set.
it returns status correctly for things it has put on the list.
it handles pid 0 consistently
(posix says same process group; here it has always been equivalent to -1,except in the wait4 version one part did and another didn't)
it now fills in a struct rusage if provided (though most of it is zero).
it should be easier to follow:
see if there is a wait record already;
if not
and WNOHANG set, see if wait will not block (if it will, return);
otherwise wait for the pid requested and enlist all wait records that do not match;
set optional status and rusage;
free the record and return pid.
its source format is more plan 9-ish.
i've added struct rusage to sys/resource.h,
and in sys/wait.h made the declarations of wait4
and rusage conditional on _BSD_EXTENSION,
and wait4 says struct rusage* not void*
Unix has indeed got very smelly. according to linux lists, posix is
going to add another wait variant, so watch this space ... i can't wait.
|