This is a tool that runs another command, and kills all the orphans it generates.
When a process is killed on Linux, its children are not automatically killed too. Instead they get reparented to the init process (the first process started by the kernel) and live on. In many cases this is not what you want.
In particular this was written to handle gitlab-runner which runs CI jobs. When a job times out gitlab-runner only kills the process that it started. Any child processes of that may be orphaned and continue running.
Anakin uses Linux's PR_SET_CHILD_SUBREAPER feature to mark itself as the "child subreaper", which means any descendants that are orphaned get reparented to this process, instead of the init process. This process then periodically polls its children and kills any that have been orphaned to it.
The easiest way to install this is with pip:
python3 -m pip install anakin2
Or if you have Rust:
cargo install anakin
There are no arguments. Just prefix your command with anakin.
Instead of
my_program --some --args
Run
anakin my_program --some --args
Logging is controlled by the following environment variables:
ANAKIN_LOG, e.g.ANAKIN_LOG=infowill print when orphans are killed. The default level iserror.ANAKIN_LOG_STYLEcontrols the colour output. It can beauto(default),alwaysornever.ANAKIN_LOG_FILEif set logs to that filename, plus the process ID. Otherwise it logs to stderr.
This is licensed under the MIT license. See the LICENSE-MIT file.