How to send a signal SIGINT from script to script ? BASH

Posted by debugger on Stack Overflow See other posts from Stack Overflow or by debugger
Published on 2010-03-26T16:32:57Z Indexed on 2010/03/26 22:53 UTC
Read the original article Hit count: 375

Filed under:
|
|
|
|

I want to trap a signal send from Script-A.sh to Script-B.sh so in Script-A.sh i use the command

(Send SIGINT to Script-B.sh)
kill -2 $PID_Script-B.sh

And in Script-B.sh i catch the signal and call function Clean

trap 'Clean' 2

It does not work, instead the Script-B.sh is killed right away without performing the Clean !!

What i notice also is that if i want to send SIGINT from terminal to any script that traps it, a ctrl-c will be catched correctly, but not if i specify the signal via the command kill -2 $pid_of_script

Any idea about the difference between the two method to send the SIGINT (ctrl-c VS kill -2 $pid_of_script), and how i can send a SIGINT from a script to another ?

Regards,

Debugger

© Stack Overflow or respective owner

Related posts about bash

Related posts about trap