Skip to main content

Module process

Module process 

Source
Expand description

Child processes started in a session of their own, such as shell commands, so they never read the terminal and are killed as a group, and the Launcher that says how every tool starts them. A Process it spawns takes its input, hands its output over line by line, and is stopped gently or killed with its whole group.

A process that dies without stopping its children, such as on SIGKILL, leaves their groups running. record_groups keeps the groups not reaped yet in a file, for a supervisor that outlives it to kill.

Structs§

Group
A Process’s group, to stop from another thread. It acts only while the process runs: once it was reaped, its id may name another process.
KillOnDrop
Stops a Process’s group when dropped: kept in a future that waits for the process on another thread (blocking), it asks the group to stop (SIGTERM) the moment the future is dropped, such as when a call is interrupted or the app quits, and kills it STOP_GRACE later if it still runs. The thread waiting for the process must go on reaping it meanwhile, as Process::run does.
Launcher
How tools start processes: under a wrapper program (a sandbox such as bwrap … --, nice -n 10, a container’s exec), in a directory, with variables set and removed. Every command it builds is detached. A host that hands one launcher to every tool that starts processes (Shell, a background job, a formatter) puts them all under the same policy.
Process
A process Launcher::spawn started, the leader of a process group of its own. Dropping it while it runs kills the group and reaps it.
Spawn
How Launcher::spawn connects a process.

Enums§

Ended
How Process::run’s wait ended.
OutputLine
A piece of a process’s output, as Process::lines hands it over: a line with its \n, or the end of the output without one. A line longer than 64 KB comes in pieces. Bytes that are not UTF-8 are replaced.

Constants§

LEDGER_VARIABLE
The variable every command a Launcher builds carries while record_groups keeps a ledger: the ledger’s path.
STOP_GRACE
How long a process asked to stop (SIGTERM) has to end before it is killed: time for a transport that hangs up the command it runs on another machine when it is stopped to do so.

Functions§

detach
Starts command in a new session, which also makes it the leader of a new process group. With no controlling terminal, a program that opens /dev/tty for a prompt (ssh, git, sudo) fails at once instead of drawing over the view and stopping on a terminal read. Git is also told not to prompt.
kill_group
Kills the process group child leads, created by detach; elsewhere, the child alone.
kill_group_of
Kills the process group led by the process leader. Its id names that group while the leader is not reaped or any member lives: the kernel does not reuse the id of a process group that exists. Once the leader was reaped and the group emptied, the id is free again, so callers kill within moments of the reap.
list_group
Lists the group leader leads in the ledger record_groups keeps, for a process started outside Launcher::spawn, such as an MCP server’s: the supervisor then kills it should this process die without stopping it. unlist_group takes it off once it is killed.
record_groups
From now on keeps the id of each process group a Launcher spawned and this process has not reaped yet in the file at path, one per line, rewritten whole on each change, and marks every command a launcher builds with LEDGER_VARIABLE set to path. A supervisor that outlives this process, such as rig’s launcher, kills the groups listed once it died without stopping them, each only while its leader still carries the mark: a listed id that names another process by then, its own reaped, is left alone. A file that cannot be written lists nothing new.
unlist_group
Takes the group leader leads off the ledger (list_group).