我有以下script1.sh
:如果通过CTRL + C终止脚本,如何杀死由脚本启动的Java进程?
#!/bin/bash
trap 'echo "Exit signal detected..."; kill %1' 0 1 2 3 15
./script2.sh & #starts a java app
./script3.sh #starts a different java app
当我做CTRL + C,它终止script1.sh
,但Java Swing应用程序开始通过script2.sh
仍保持开放。它怎么没有杀死它?
[Bash的?我该如何使一个脚本的子进程被终止,当脚本被终止]的可能重复(http://stackoverflow.com/questions/ 7817637/bash-how-do-i-make-sub-processes-of-a-script-be-terminated-when-the-script-is) – Thilo
另外:http://stackoverflow.com/questions/360201/kill -background-process-when-shell-script-exit – Thilo
我试过了两个。如果它正在运行,它们都不会杀死真正的Java应用程序... –