Jean-mathieu CHANTREIN <jean-mathieu.chantr...@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

Attachment: signature.asc
Description: PGP signature

Reply via email to