#!/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. Oracle 数据库导入、导出

    第一步:新建一个txt文件: exp.exe jeamsluu@test file=d:\daochu.dmp log=1.log 另存为.bat格式的文件 第二步:双击运行:此时会弹出输入口令的对话 ...

  2. android之获取应用中的图片资源_获取找你妹中的图片资源

    一直不知道原来获取一个应用中的图片资源这么简单,刚才直接把apk解压,就得到了里面的一下文件,搜索一下就全部把图片资源找出来了,想要模仿应用或者自己不会ui的话,用现成的资源方便多了. 也没多少说的, ...

  3. SQL基础查询实战

    总结: 一.单表查询的情况: 1.where.....group by .. Having count(..) 2.Group by haing min(..)条件and max(..)条件(查询最低 ...

  4. 面试题19:包含min函数的栈

    CStack.h: #pragma once class CStackElement { public: CStackElement(void){} CStackElement(int data, i ...

  5. 假设给Contact的List加一个用字母排序的导航

    效果图: 这样写Layout: <? xml version="1.0" encoding="utf-8"? > <LinearLayout ...

  6. poj 4044 Score Sequence(暴力)

    http://poj.org/problem?id=4044 大致题意:给出两个班级的成绩,先按降序排序,而且没有成绩同样的.然后求连续的最长公共子序列.输出时,先输出最长公共子序列,然后按个位数字递 ...

  7. c语言中重要函数

    gets函数,从标准输入读取一行文本,一行输入由一串字符组成,以一个换行符结尾: gets函数丢弃换行符,并在该行的末尾存储一个NUL字符(类似‘\0’), 然后返回一个非NULL值. 当gets函数 ...

  8. js页面loading加载

    <html>     <head>     <title>页面正在载入</title>       <script  language=" ...

  9. C# 委托和方法

    委托是一种特殊的引用类型,它将方法也作为特殊的对象封装起来,从而将方法作为变量或参数进行传递 using System; using System.Collections.Generic; using ...

  10. redis在spring中的配置及java代码实现

    1.建一个redis.properties属性文件 # Redis Setting redis.addr = 127.0.0.1 redis.port = 6379 redis.auth = mast ...