#!/bin/sh

MAXRSTCOUNT=;
PROCTOGO=/mnt/hgfs/code/test/show #count is the counter of test started times
count= sys_reboot()
{
echo "system is going to reboot";
reboot;
} main_loop()
{
while :
do
#########################################
ProStillRunning=$(ps -aux |grep "${PROCTOGO}" |grep -v "grep")
if [ -z "$ProStillRunning" ]; then
#start test
chmod +x ${PROCTOGO}
${PROCTOGO}
fi #the running times counter
let count=count+
echo "test running times is $count" #wait for test stoping...
sleep #########################################
done
} main_loop;

实例:

cat etc/init.d/monitor-app.sh

#!/bin/bash
sleep while [ ]
do
for procname in app
do
pgrep $procname > /dev/null
if [ -ne $? ]
then
/etc/init.d/autoapp start & ##autoapp可以是脚本,app等
fi
done
sleep
done

一个app启动脚本:

cat etc/init.d/automhclient

#! /bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin case "$1" in
start)
echo -n "Starting automhclient: "
export DISPLAY=:
cd /usr/share/qt5/app/mhclient
./automhclient &
echo
exit
;;
stop)
echo -n "Shutting down automhclient: "
killproc automhclient
echo
;;
restart)
echo -n "Restarting automhclient: "
$ stop
$ start
echo
;;
*)
echo "Usage: $0 start|stop" >&
exit
;;
esac

shell:监控进程运行状态并自动重启进程的更多相关文章

  1. C#通过代码彻底结束桌面进程explorer,解决自动重启问题

    C# 通过代码 Process.Kill 方法杀死桌面进程后,会自动重启 其实可以通过 Taskkill 指令结束桌面进程, 在命令行查看 taskkill 帮助, TASKKILL [/S syst ...

  2. centos 监控进程,并自动重启

    编辑Crontab crontab -e 按i进行编辑 */ * * * * /root/monitor.sh # 每分钟运行一遍monitor.sh脚本 * * * /sbin/reboot # 每 ...

  3. window下进程退出后自动重启

    设计思想:编写批处理脚本监控进程的运行状态,如果发现进程停止,则自动重启该进程.批处理脚本(jk.bat)和进程脚本(hello.bat)如下: 1.jk.bat @echo off rem 定义需监 ...

  4. 检测进程不存在自动重启shell脚本

    #!/bin/bash WORKDIR="/usr/local/gse/gseagent" [[ -d $WORKDIR ]] && { if ! ps aux|g ...

  5. Linux执行脚本让进程挂掉后自动重启

    1 创建循环监听脚本  autostart.sh 例: 其中futures-market-server-v3andwebsoket.jar 是要监听的执行程序 #/bin/bashwhile true ...

  6. Linux中进程杀掉总是自动重启

    <1> cat /proc/进程id/status   找到该子进程对应的父进程,将其父进

  7. Linux 进程终止后自动重启

    /opt/a.sh #! /bin/bash ps -ef | grep python3 a.py | grep -v grep | grep python3 if [ $? -ne 0 ] then ...

  8. linux下监视进程 崩溃挂掉后自动重启的shell脚本

    如何保证服务一直运行?如何保证即使服务挂掉了也能自动重启?在写服务程序时经常会碰到这样的问题.在Linux系统中,强大的shell就可以很灵活的处理这样的事务. 下面的shell通过一个while-d ...

  9. 监控redis进程,如果没有自动重启

    监控redis进程,如果没有自动重启 #Time:2016-01-22#Version:1.0 #Author:chh-huang #设置环境变量source /etc/profile#source ...

随机推荐

  1. [LeetCode]题解(python):136-Single Number

    题目来源: https://leetcode.com/problems/single-number/ 题意分析: 给定一个数组,每个数都出现了2次,只有一个出现了一次,找出这个数.要求时间复杂度O(n ...

  2. if最简单的用法

    /* Name:if最简单的用法-1 Copyright:By.不懂网络 Author: Yangbin Date:2014年2月9日 03:00:58 Description:if最简单的用法,真则 ...

  3. 个人收集资料整理-WinForm

    [2016-03-23 20:29:56] 别人收集常用: http://www.cnblogs.com/babycool/p/3541192.html

  4. RedisTemplate.htm

    http://docs.spring.io/spring-data/redis/docs/current/api/org/springframework/data/redis/core/RedisTe ...

  5. perl 爬取同花顺数据

    use LWP::UserAgent; use utf8; use DBI; $user="root"; $passwd='xxx'; $dbh=""; $db ...

  6. Dialog with HTML skin using CDHtmlDialog and SetWindowRgn

    Introduction This program demonstrates how to use CDHtmlDialog and SetWindowRgn functions to give a ...

  7. kvm 存储

    1,virt-install --connect qemu:///system --name web01_lvm --ram 1024 --vcpus=1 --disk=/dev/vg_lvm/web ...

  8. maven项目启动

    1服务install 2 build (tomcat:run)

  9. Cocos2d-x lua游戏开发之安装Lua到mac系统

    注意:mac ox .lua version :5.15 下载lua官网的lua, 注意:最好是5.15下面.5.2的lua不支持table的getn()方法,这让我情何以堪.(获取table长度.相 ...

  10. SqlDataAdapter的方法之一Fill (DataSet dataset, String datatable)解释

    一.SqlDataAdapter的方法之一Fill (DataSet dataset, String datatable)解释:根据datatable名填充Dataset.myda.Fill(ds, ...