广告
返回顶部
首页 > 资讯 > 服务器 >Shell实现判断进程是否存在并重新启动脚本分享
  • 621
分享到

Shell实现判断进程是否存在并重新启动脚本分享

重新启动是否存在脚本 2022-06-04 21:06:05 621人浏览 独家记忆
摘要

简洁版: #! /bin/bash # author caoxin # time 2012-10-10 # program : 判断进行是否存在,并重新启动 function check(){

简洁版:


#! /bin/bash
# author caoxin
# time 2012-10-10 
# program : 判断进行是否存在,并重新启动


function check(){
  count=`ps -ef |grep $1 |grep -v "grep" |wc -l`
  #echo $count
  if [ 0 == $count ];then
    nohup python /runscript/working/$1 &
  fi
}

check behaviors.py

详细版:


#!/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 $count

sec=7
#开始一个循环,以判断进程是否关闭

for var in 1 2
do
 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
 fi
done

#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 &

--结束END--

本文标题: Shell实现判断进程是否存在并重新启动脚本分享

本文链接: https://www.lsjlt.com/news/18215.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作