本文共 720 字,大约阅读时间需要 2 分钟。
Linux下编程实例
判断一个进程是否存在,如果不存在重启该进程:
#!/bin/bash##调用关闭jboss进程脚本stopMethodServer.sh#打印出当前的jboss进程:grep jboss查询的jboss进程,grep -v "grep" 去掉grep进程jmsThread=`ps -ef | grep gdms | grep jboss | grep -v "grep"`echo $jmsThread#查询jboss进程个数:wc -l 返回行数count=`ps -ef | grep gdms | grep jboss | grep -v "grep" | wc -l`echo $countsec=7#开始一个循环,以判断进程是否关闭for var in 1 2do if [ $count -gt 0 ]; then #若进程还未关闭,则脚本sleep几秒 echo sleep $sec second the $var time, the JMS thread is still alive sleep $sec else #若进程已经关闭,则跳出循环 echo "break" break fidone#if [ $count -eq 0 ]; then# echo "nohup startMethodServer.sh &"# nohup startMethodServer.sh &#else# echo "It's better to check the thread!!!"#fi#调用启动脚本nohup startMethodServer.sh &
转载地址:http://fxoci.baihongyu.com/