java进程的守护进程脚本

当jar程序执行异常中断时,希望系统能够自动启动。通过以下shell脚本监控程序一直运行。

#/bin/bash
while true;
do
  count=`ps -ef | grep test.jar | grep -v grep|wc -l`
  if [ ${count} -lt 1 ]; then
    nohup java -jar test.jar &
  else
    echo "process is running"
  fi
  sleep 3
done

原文地址:https://www.cnblogs.com/30go/p/9068646.html