#!/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. SSD的优势

    谈过SSD的发展历史后,现在我们来讲解下SSD相比传统HDD(机械硬盘)的优势. 相信很多读者只要有听说过SSD,必定都会听到对SSD优点的一个字总结:快! 但这一个字要如何去理解呢?很多人可能还不太 ...

  2. Making your first driver - complete walkthrough(使用VisualDDK)

    This article describes how to create, build and debug your first driver using Visual Studio and Visu ...

  3. delphi如何获得当前操作系统语言环境

    function GetWindowsLanguage: string; var WinLanguage: ..] of char; begin VerLanguageName(GetSystemDe ...

  4. HDU 5820 Lights(扫描线+zkw线段树)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5820 [题目大意] 在一个大小为50000*50000的矩形中,有n个路灯. 询问是否每一对路灯之 ...

  5. Open virtual effects in Ubuntu 12.04LTS

    Need install below packages: compiz compiz-core compiz-fusion-plugins-extra+ compiz-fusion-plugins-m ...

  6. CSS换行1

    1.你定死表格的宽度,即给表格一个宽度值(是数值,不是百分比)   2.强制不换行 div{//white-space:不换行;normal 默认;nowrap强制在同一行内显示所有文本,直到文本结束 ...

  7. css版hover现边框

    需要注意的是  hover中要给盒子加:position:relative; <style type="text/css"> *{margin:0;padding:0; ...

  8. C#线程(一)

    本篇作为自己简要的笔记和整理,自己英语略渣  就不翻译了 参考http://www.albahari.com/threading 这里有翻译的http://www.cnblogs.com/miniwi ...

  9. sort函数简单调用方法

    向量调用sort函数排序,一般有三个参数,即为sort(v.begin(),v.end(),cmp),第三个传入的是比较函数的地址(函数名),决定你比较的性质,运用灵活 #include<ios ...

  10. imx:MfgTool

    MfgTool使用方法: MfgTool很妖,写进去的img的名字一定要符合配置文件里面的命名标准. 具体要参见:        MFG_TOOL\Profiles\Linux\OS Firmware ...