我认为这样的事情可能对你有用。但是,正如@carlspring 提到的,您最好在每个脚本中都有类似的内容,这样您就可以捕获相同的中断并杀死任何丢失的子进程。
随便拿
#!/bin/bash
# Store subproccess PIDS
PID1=""
PID2=""
# Call whenever Ctrl-C is invoked
exit_signal(){
echo "Sending termination signal to childs"
kill -s SIGINT $PID1 $PID2
echo "Childs should be terminated now"
exit 2
}
trap exit_signal SIGINT
# Start proccess and store its PID, so we can kill it latter
proccess1 &
PID1=$!
proccess2 &
PID2=$!
# Keep this process open so we can close it with Ctrl-C
while true; do
sleep 1
done