我正在開發一個自動更新腳本,該腳本應該能夠在完成後重新啓動守護進程。退出後Java進程構建器子進程繼續
目前,我正在嘗試此:
final ArrayList<String> command = new ArrayList<String>();
String initScriptPath = Config.GetStringWithDefault("init_script", "/etc/init.d/my-daemon");
command.add("/bin/bash");
command.add("-c");
command.add("'" + initScriptPath + " restart'");
StringBuilder sb = new StringBuilder();
for (String c : command) {
sb.append(c).append(" ");
}
Log.write(LogPriority.DEBUG, "Attempting restart with: " + sb.toString());
final ProcessBuilder builder = new ProcessBuilder(command);
builder.start();
// Wait for a couple of seconds
try {
Thread.sleep(5000);
} catch (Exception e) {
}
System.exit(0);
然而System.exit似乎停止重啓?它確實停止,但不會重新開始。
所以這裏的問題等於:「是否system.exit殺死子進程」? –
@NathanHughes是的,我在標題中加入了更多的意義。 – RobinUS2