Skip to main content

Module wait

Module wait 

Source
Expand description

Wait-family syscall handlers: waitpid, getpid, getppid.

§Design notes

The blocking loop follows the Aero / Maestro pattern:

loop {
    try_wait_child()       ← O(log n) scan under scheduler lock
    StillRunning → block_current_task()
                            ↑ woken by exit_current_task → wake_task_locked(parent)
}

Lost-wakeup race: if the child exits between try_wait_child returning StillRunning and block_current_task() reaching the scheduler lock, exit_current_task will have already called wake_task_locked(parent), which sets task.wake_pending = true. block_current_task() checks this flag and aborts the block, so the parent re-runs the loop immediately without sleeping.

Signal interruption: after each sleep the pending-signal flag is checked; if a signal is queued the syscall returns -EINTR so userspace can handle it before retrying.

§Plan 9 flavour

sys_waitpid encodes the exit status using the standard Linux W_EXITCODE macro (status << 8), which musl/glibc decode correctly. A separate Plan 9-style Waitmsg structure (pid + exit_code + msg[64]) is written to an optional second output pointer when the caller provides one (via the waitmsg_ptr variant—SYS_PROC_WAIT).

Structs§

Waitmsg
Plan 9-inspired exit message written to userspace by SYS_PROC_WAIT.

Constants§

WNOHANG
Do not block if no child has exited yet.

Functions§

sys_getpid
SYS_PROC_GETPID (308): return the current task’s ID.
sys_getppid
SYS_PROC_GETPPID (309): return the parent task’s ID, or 0 if none.
sys_wait
SYS_PROC_WAIT (311): Plan 9-style wait — any child, writes full Waitmsg.
sys_waitpid
SYS_PROC_WAITPID (310): wait for a child process to exit.