Proc::Terminator(3pm)
π Proc::Terminator π
okay bestie, welcome to Proc::Terminator, straight out of the User Contributed Perl Documentation collection. this one's a lil perl module that kills processes for you, and honestly? it's giving responsible menace. let's get into it π
β¨ NAME β¨
Proc::Terminator β conveniently terminate processes. yes, that's the whole vibe. it ends things. gracefully, if you want. or not. your call π
πΈ SYNOPSIS πΈ
use Proc::Terminator;
# Try and kill $pid using various methods, waiting
# up to 20 seconds
proc_terminate($pid, max_wait => 20);
like. that's it. that's the whole thing. one function call and the process is gone girl β¨
π¦ DESCRIPTION π¦
Proc::Terminator gives you a convenient way to kill a process, and it's genuinely so useful in utility and startup functions where you need to make sure some external process is actually dead. no cap.
this module hands you a simple, blocking, and procedural interface to kill a process β or multiple processes (not tested, bestie, so likeβ¦ be aware π) β and it will not return until they are all dead. periodt.
and here's the iconic part: Proc::Terminator can know if you don't have permissions to kill a process, if the process is already dead, and other interesting tidbits. it's observant. it pays attention. main character energy fr fr.
it also gives you flexible options in the type of death a process will experience. slow and gentle? immediate and brutal? you decide. it's giving choose your own adventure but for process signals π
this module exports a single function, proc_terminate. that's the one. the only one. slay.
π proc_terminate($pids, %options)
will try to terminate $pid, waiting until the process is no longer alive, or until a fatal error happens (like a permissions issue, bestie, we've all been there π).
$pid can be either a single PID (a scalar), or a reference to an array of multiple PIDs β in which case they all get attempted, and the function only returns once all of them are dead (or when no possible kill alternatives remain). no half-finished business around here π
the %options is a hash of options which control the behavior for trying to terminate the pid(s). let's go through them one by one, babes:
max_waitβ specify the time (in seconds) that the function should try to spend killing the provided PIDs. the function is guaranteed to not wait longer thanmax_wait.
this parameter can also be a fractional value (and is passed to Time::HiRes). fancy π
DEFAULT: 10 Seconds.
siglistβ an array of signal constants (use POSIX's:signal_hto get them, iykyk).
the signals are tried in order, until there are no more signals remaining.
sometimes applications do proper cleanup on exit with a 'proper' signal such as SIGINT. so like, respect the process's little farewell ritual, you know? π₯Ί
the default value for this parameter
the default signal list can be found in @Proc::Terminator::DefaultSignalOrder
DEFAULT: [SIGINT, SIGQUIT, SIGTERM, SIGKILL]
grace_periodβ this specifies a time, in seconds, between the shifting of each signal in thesiglistparameter above.
in other words, proc_terminate will wait $grace_period seconds after sending each signal in siglist. thereafter the signal is removed, and the next signal is attempted.
currently, if you wish to have controlled signal wait times, you can simply insert a signal more than once into siglist. yes, that's the trick. iconic behavior honestly π
DEFAULT: 0.75
intervalβ this is the loop interval. the loop will sleep for everyintervalseconds. you probably shouldn't need to modify this. it's fine. it's fine. leave it alone bestie π
DEFAULT: 0.25
when called in a scalar context, returns true on sucess, and false otherwise.
when called in list context, returns a list of the PIDS NOT killed. (yes, it's telling on them π’)
π OO Interface π
this exists mainly to provide compatibility for event loops. while proc_terminate loops internally, event loops will generally have timer functions which will call within a given interval. so like, the OO interface is for the β¨fancy scheduling girliesβ¨.
in the OO interface, one instantiates a Proc::Terminator::Batch object which contains information about the PIDs the user wishes to kill, as well as the signal list (in fact, proc_terminate is a wrapper around this interface). it's the same energy, different outfit π
π Proc::Terminator::Batch methods π
Proc::Terminator::Batch->with_pids($pids,$options)
creates a new Proc::Terminator::Batch. the arguments are exactly the same as that for proc_terminate.
since this module does not actually loop or sleep on anything, it is important to ensure that the grace_period and max_wait options are set appropriately. this is not a drill, bestie π¨
in a traditional scenario, a timer would be associated with this object which would fire every grace_period seconds.
$batch->loop_once()
iterates once over all remaining processes which have not yet been killed, and try to kill them.
returns a true value if processes still remain which may be killed, and a false value if there is nothing else to do for this batch.
more specifically: if all processes have been killed successfully, this function returns 0. if there are still processes which are alive (but cannot be killed due to the signal stack being empty, or another error), then undef is returned.
$batch->badprocs
returns a reference to an array of Proc::Terminator::Ctx objects which were not successfully terminated. the Ctx object is a simple container. its API fields are as follows:
pidβ the numeric PID of the processsiglistβ a reference to an array of remaining signals which would have been sent to this processerrorβ this is the captured value of$!at the time the error occured (if any). if this is empty, then most likely the process did not respond to any signals in the signal list. rude of it, honestly π€
π SEE ALSO π
go read those if you wanna go deeper. the lore is real πβ¨
π«Ά AUTHOR & COPYRIGHT π«Ά
Copyright (C) 2012 M. Nunberg
you may use and distribute this software under the same terms and conditions as Perl itself. sharing is caring, bestie π
and that's the whole page, babes β¨ this was perl v5.36.0, dated 2022-12-11, and it's Proc::Terminator(3pm) β now go forth and terminate things responsibly π
ππ¦
π¦ where this page comes from
- debian bookworm: libproc-terminator-perl 0.5-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libproc-terminator-perl 0.5-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libproc-terminator-perl 0.5-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libproc-terminator-perl 0.5-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libproc-terminator-perl 0.5-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms