【问题标题】:How to restart a program in terminal when the program exit with error?当程序错误退出时如何在终端中重新启动程序?
【发布时间】:2015-01-26 06:43:07
【问题描述】:
我编写了一个脚本来启动一个终端,该终端启动一个 java 应用程序的一些实例(一个用于选项卡),有时 java 应用程序崩溃但终端继续工作,我需要自动重新启动 java 应用程序。
我需要从终端开始,因为必须看到一些输出。
until terminal --tab -e "java -jar app.jar param0" --tab -e "java -jar app.jar param1"; do
sleep1
done
使用此代码我将重新启动终端...(如果它崩溃了)
如何重启 java 应用程序?
谢谢
【问题讨论】:
标签:
java
bash
terminal
crash
restart
【解决方案1】:
如果终端仍在运行,请使用
ps (Comment: add "| grep <search-word>" if you're looking for a specific process)
检查应用程序是否真的死了。如果不是,请尝试终止进程
ps aux (Comment: Will show the process ID you need for the next command)
kill -9 <Process ID> (This will destroy the process and lose all unsaved data)
然后,您只需再次运行脚本。
【解决方案2】:
在一个循环中。使用 ps 和 grep 检查该过程仍在运行。如果不重新开始。成功