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.

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§

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.