You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
getrusage(RUSAGE_CHILDREN) counts host reaps, not guest waits #537
sys_getrusage (src/syscall/sys.c) forwards RUSAGE_CHILDREN to the host's
getrusage. The host adds a child's usage when the host process is reaped,
which is not when the guest reaps it, and not under the guest's SIGCHLD
disposition. Two results differ from Linux.
An auto-reaped child is counted. Under SIG_IGN or SA_NOCLDWAIT, Linux
never adds the child: exit_notify() gets autoreap from do_notify_parent()
and calls release_task(), and the only writer of the parent's c* fields is
wait_task_zombie() (kernel/exit.c). The elfuse host process does not
ignore SIGCHLD itself, so XNU's reap_child_locked() rolls the child up into
p_cru, which it skips only for a parent with P_NOCLDWAIT
(bsd/kern/kern_exit.c).
A waited child is counted late. wait4 can return the child's status from
the lifecycle registry while its host process is still tearing down, and
leave the host reap to proc_deferred_reap_poll(). A getrusage right after
the wait misses the child; its usage shows up after a later wait4 entry or
the SIGALRM tick runs the sweep.
times() is not affected in either case: it reads proc_children_cpu_us(),
which the guest-side reap paths fill.
Reproduction: each child spins on CLOCK_PROCESS_CPUTIME_ID for 300 ms. Each
row is the change since the previous row, in ms.
1. SIGCHLD SIG_IGN, fork, sleep 1 s, waitpid(-1, WNOHANG) (ECHILD), sleep 1 s
2. SIGCHLD SIG_DFL, fork a child that exits at once, waitpid
3. fork the 300 ms child, waitpid
4. sleep 1 s, waitpid(-1, WNOHANG) (ECHILD)
Activity