Expand description
Signalling, waiting for and reaping child processes without hitting another process which reused their PID.
Structsยง
- Process ๐
- A child process of the server, which can be signalled without hitting another process that reused its PID.
- Stat ๐
- The fields of
/proc/<pid>/statwhich follow the parenthesized command name, which may contain spaces and parentheses itself.
Enumsยง
- Child
Exit ๐ - How a child exited, see
wait_child.
Constantsยง
- EXIT_
CODE_ ๐UNKNOWN - The exit code of a process whose exit status is not known, because it did neither exit nor get killed by a signal, or waitpid failed after its pidfd got readable.
- EXIT_
CODE_ ๐WAIT_ FAILED - The exit code of a process whose exit status the blocking wait, used
without pidfds, could not get, for example because it got reaped already.
It is the same as
EXIT_CODE_TIMED_OUTfor compatibility, the pidfd wait reportsEXIT_CODE_UNKNOWNinstead. - PIDFD_
RETRY_ ๐MAX - PIDFD_
RETRY_ ๐MIN - The bounds of the delay between the waits for an exited process which is
not waitable yet, unless its pidfd wakes the wait up earlier, see
try_pidfd_wait. The waits go on as long as its tracer does not wait for it, like for a process stuck in the kernel. - WAITPID_
STACK_ ๐SIZE - Stack size of the waitpid threads, which only wait and log.
Staticsยง
- PROC_
CHILDREN ๐ - Whether the kernel lists the children of a thread, see
children. - REAP_
LOCK ๐ - Taken for writing while the server reaps one of its children, and for reading while it checks that one was not reaped yet and signals it. A child found unreaped under the read lock stays unreaped until the signals were sent. So neither its PID nor the ID of its process group, which it keeps referring to as a zombie, can be taken by another process meanwhile. The server is the only one which reaps its children.
Functionsยง
- child_
pid ๐ - The PID of a spawned child by the ID which the standard library reports, or tokio, which has none anymore once the child got reaped.
- children ๐
- The children of all threads of this process. The kernel lists them in
/proc/self/task/<tid>/children, which needsCONFIG_PROC_CHILDREN, fall back to scanning all processes without it. The list is not complete if a thread exited while listing them. - children_
by_ ๐scan - The children of this process, found by scanning all processes.
- group_
has_ ๐child - Whether a child of this process belongs to the process group. The
children the kernel lists come first, only without a member among them
all processes get scanned: the lists are reliable for stopped children
only. A listed child may have got reaped meanwhile, tokio does not take
the
REAP_LOCK, so its parent gets checked again. - has_
zombie ๐ - Whether a child of any thread of this process exited and was not reaped yet, without reaping it.
- is_
child ๐ - Whether the process is a child of the server which was not reaped yet, a
zombie included. Only such a PID is safe to register, see
ChildReaper::create_child. - is_
subreaper ๐ - Whether the processes which the children of the server leave behind get
reparented to it, which the server sets up at its start, see
init::set_up_serving. The tests do not. One which cannot tell counts as a subreaper. - is_
zombie ๐ - Whether the process is a zombie.
- parse_
pid ๐ - Parse a PID, which is positive.
- peek_
exit ๐ - The exit code of a child which exited, without waiting or reaping it,
none while it runs. Fails with
ECHILDif there is no such child of the server, also once it got reaped. - pidfd_
open ๐ - Open a pidfd for the process, which also works for one that already exited but was not reaped yet. The descriptor is close-on-exec.
- pidfd_
send_ ๐signal - Send a signal through a pidfd, none only checks that the process still exists.
- pids ๐
- The PIDs of all processes, without the ones of their threads.
- positive_
pid ๐ - A PID, which is positive. Zero and negative numbers refer to process groups when signalling.
- read_
pid_ ๐file - Read a PID file like the runtimes write it, the number may be followed by a line ending.
- reap_
guard ๐ - Hold while reaping a child of the server, see
REAP_LOCK. - signal_
name ๐ - The name of a signal, or its number if nix does not know it, like the real-time signals.
- signals_
group ๐ - Whether the process group of a child gets signalled. Group 1 would end up as kill(-1), which kills everything conmon-rs is allowed to, and the group of this server would kill it as well. A container process which did not get a group of its own shares the one of its runtime, which runs in a group of its own.
- spawn_
waitpid_ ๐thread - Run a blocking waitpid on a dedicated thread. It blocks for the lifetime of the process, so it must not occupy a thread of the bounded blocking pool, which serves the file I/O of all containers. If no thread can be spawned, for example because of a pids limit, queue it on the pool rather than failing the wait.
- try_
pidfd_ ๐wait - Wait for the exit of
pidthrough itspidfdwith async polling. None if the pidfd cannot be waited for. - wait_
child ๐ - The waitid(2) behind
wait_exit, which also reports real-time signals, along with the PID of the child. - wait_
exit ๐ - Wait for the exit of a child like waitid(2) with
WEXITEDandflags, and return its exit code, the one of a signal like a shell reports it. None if it still runs, withWNOHANG. The wait of nix fails withEINVALfor a child killed by a real-time signal, which it does not know, after the kernel reaped it already. - wait_
for_ ๐exit - Wait for the exit of a registered child like
wait_for_exit_code, through the pidfd it holds already, so that the wait opens none of its own. Without one, on kernels before 5.3, the wait falls back like for a PID. - wait_
for_ ๐exit_ code - Wait for a process to exit using pidfd_open for async polling, with a blocking waitpid fallback for older kernels.
- wait_
for_ ๐exit_ code_ blocking - Wait for the exit without reaping, which then happens under the
reap_guard. - wait_
for_ ๐exit_ code_ on_ thread - Wait for a process to exit with a blocking wait on a thread of its own,
without pidfds, see
spawn_waitpid_thread. - wait_
for_ ๐exit_ with - Wait for the exit of
pidthrough itspidfd, or on a thread without one, seewait_for_exit_code. - zombie_
children ๐ - The zombie children of this process, and whether the list is
complete, see
children.