所以在Script-A.sh我使用命令
(Send SIGINT to Script-B.sh)
kill -2 $PID_Script-B.sh
而在Script-B.sh中,我捕获信号并调用函数Clean
trap ‘Clean’ 2
它不工作,而是Script-B.sh立即被杀死,而不执行清洁!
我也注意到,如果我想从终端发送SIGINT到陷阱的任何脚本,ctrl-c将被捕获正确,但是如果我通过命令kill -2 $pid_of_script指定信号,
关于发送SIGINT(ctrl-c VS kill -2 $pid_of_script)的两种方法之间的差异的任何想法,以及我如何从脚本发送SIGINT到另一个?
问候,
调试器
从信息bash:
Background processes are those whose process group ID differs from the
terminal’s; such processes are immune to keyboard-generated signals.
我发现如果你使用另一个信号(如SIGUSR1)来捕捉和杀死它,它可以工作.
来自man bash的附加信息:
Non-builtin commands run by bash have signal handlers set to the values inherited by the shell from its parent. When job control is not in effect,asynchronous commands ignore SIGINT and SIGQUIT in addition to these inherited handlers.
和
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.
和
Any trap on SIGCHLD is executed for each child that exits.