Juhani Krekelä opened issue #886: init does not reliably SIGTERM orphans at sortix / Sortix

Juhani Krekelä
2025-02-22T20:26:59Z

Cleaning up unknown children in init is implemented as:

iterate through all direct children, send unknown ones SIGTERM

if there weren't any unknown children, exit

wait until either a SIGCHILD is delivered or 30 seconds pass

iterate though all direct children, and if it has been 30 seconds, send unknown ones SIGKILL

go to 2

The problem is that if we have an unknown child A, and that has a child B (that is, init → A → B), B may not get sent SIGTERM:

A is sent SIGTERM, init → {A (zombie), B}

there were unknown children (A)

SIGCHILD from A is delivered

it has not been 30 seconds, so B is not sent SIGKILL

there were unknown children (B)

no further SIGCHILD to be delivered so init wait until 30 seconds have passed

You can encounter this in practice when shutting down the system while there is an active ssh connection. sshd-session is sent SIGTERM but sortix-sh isn't, leading to the system hanging for 30 seconds.