我有以下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應用程序... –