[slurm-users] How to trap a SIGINT signal in a child process of a batch ?
Bjørn-Helge Mevik
b.h.mevik at usit.uio.no
Tue Apr 21 08:29:32 UTC 2020
Jean-mathieu CHANTREIN <jean-mathieu.chantrein at univ-angers.fr> writes:
> test.sh:
>
> #!/bin/bash
>
> function sig_handler()
> {
> echo "Executable interrupted"
> exit 2
> }
>
> trap 'sig_handler' SIGINT
>
> echo "BEGIN"
> sleep 200
> echo "END"
Note that bash does not interrupt any running command (except "wait")
when it receives a trapped signal, so the "sleep 200" will not be
interrupted. The "wait" command is special; it will be interrupted.
From man bash:
If bash is waiting for a command to complete and receives a signal for which a
trap has been set, the trap will not be executed until the command completes.
When bash is waiting for an asynchronous command via the wait builtin, the
reception of a signal for which a trap has been set will cause the wait builtin
to return immediately with an exit status greater than 128, immediately after
which the trap is executed.
So try using
sleep 200 &
wait
instead.
--
Regards,
Bjørn-Helge Mevik, dr. scient,
Department for Research Computing, University of Oslo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.schedmd.com/pipermail/slurm-users/attachments/20200421/ff434fdf/attachment.sig>
More information about the slurm-users
mailing list