Skip to main content

Module process

Module process 

Source
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>/stat which follow the parenthesized command name, which may contain spaces and parentheses itself.

Enumsยง

ChildExit ๐Ÿ”’
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_OUT for compatibility, the pidfd wait reports EXIT_CODE_UNKNOWN instead.
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 needs CONFIG_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 ECHILD if 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 pid through its pidfd with 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 WEXITED and flags, and return its exit code, the one of a signal like a shell reports it. None if it still runs, with WNOHANG. The wait of nix fails with EINVAL for 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 pid through its pidfd, or on a thread without one, see wait_for_exit_code.
zombie_children ๐Ÿ”’
The zombie children of this process, and whether the list is complete, see children.