I think I found what we need =)
(
http://www.cactus.org/~dak/shellscript.html)
Let's google guys!
Process Handling
*
Signals
Name Number Control Character
o EXIT 0 Used to trap exiting script
o HUP 1 Logout
o INT 2 Control-C
o QUIT 3 Control-\
o KILL 9 can not be ignored or trapped
o TERM 15 Default kill
o TSTP 24 Control-Z
*
Traps
o trap "" signal-list Ignore signal
o trap "cmds" signal-list Execute commands if signal is caught
o trap signal-list Reset signal to original condition
o trap : signal-list (undocumented) ignore signal, pass to child
Signal are normally not passed to subprocesses
o Examples
trap 'rm tmpfile; exit' 0 1 2 #remove tmpfile on exit, logout, interrupt
trap "echo 'You hit Control-C'" INT
while true ; do
sleep 60
done
o Example parent child process
#!/bin/bash #parent
echo parent running
trap 'echo parent exiting; exit' 0
trap :2
child
sleep 1000
#!/bin/bash #child
echo child started. pid is $$
trap 'echo child got signal 2; exit' INT
sleep 1000