Signal Handling
Signals are messages sent to
running programs to trigger specific behavior. For example, SIGINT is sent to
all processes in the terminal foreground process group when ctrl-c is pressed.
just tries to exit when requested by a signal, but it also tries to avoid
leaving behind running child processes, two goals which are somewhat in
conflict.
If just exits leaving behind child processes, the user will have no recourse
but to ps aux | grep for the children and manually kill them, a tedious
endeavor.
Fatal Signals
SIGHUP, SIGINT, and SIGQUIT are generated when the user closes the
terminal, types ctrl-c, or types ctrl-\, respectively, and are sent to all
processes in the foreground process group.
SIGTERM is the default signal sent by the kill command, and is delivered
only to its intended victim.
When a child process is not running, just will exit immediately on receipt of
any of the above signals.
When a child process is running, just will wait until it terminates, to
avoid leaving it behind.
Additionally, on receipt of SIGTERM, just will forward SIGTERM to any
running children1.41.0, since unlike other fatal signals, SIGTERM,
was likely sent to just alone.
Regardless of whether a child process terminates successfully after just
receives a fatal signal, just halts execution.
Continuing Execution
The [continue]1.54.0 attribute can be used to make just continue
execution even if it receives a fatal signal as long as the child process it’s
running exits successfully.
With no arguments, [continue] handles SIGINT (ctrl-c) so SIGQUIT
(ctrl-\) can still be used to stop execution.
With arguments, one or more signals to handle may be given explicitly, as
"SIGHUP", "SIGINT", and "SIGQUIT".
In this example, if main.py catches SIGINT and exits successfully,
cleanup will still run and just will exit successfully:
[continue]
test: && cleanup
python3 main.py
cleanup:
echo cleanup
SIGINFO
SIGINFO is sent to all processes in the foreground process group when the
user types ctrl-t on
BSD-derived
operating systems, including macOS, but not Linux.
just responds by printing a list of all child process IDs and
commands1.41.0.
Windows
On Windows, just behaves as if it had received SIGINT when the user types
ctrl-c. Other signals are unsupported.