1.python检测linux下进程的运行
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#coding=utf8 import sys,os status_ok = 0 status_critical = 2 def check(Pid): dir,file = os.path.split(Pid) if not(os.path.exists(Pid)): print 'Critical - %s is stop.' % file sys.exit(status_critical) else: print 'OK - %s is running.' % file sys.exit(status_ok) if __name__ == '__main__': #pid = "/var/run/sshd.pid" pid = sys.argv[1] check(pid)
运行:python check_daemon.py /var/run/sshd.pid
2.shell检测linux进程运行
复制代码
1
2
3
4
5
6
7
8
9
10
11
12#!/bin/sh daemon=$1 status_ok=0 status_critical=2 pid=`ps -ef | grep -v grep | grep -v $0| grep $daemon| sed -n '1P'|awk '{print $2}'` if [ -z $pid ]; then echo "Critical - $daemon is stop." exit $status_critical else echo "OK - $daemon is running." exit $status_ok fi
sh check_daemon.sh sshd
3.linux一般用init管理进程,不过有一个用python写的模块(supervisor)也能很优秀的管理进程,而且可以管理任意运行脚本。
转载于:https://blog.51cto.com/xieyusong/1357946
最后
以上就是飞快钢笔最近收集整理的关于检测linux进程是否运行的全部内容,更多相关检测linux进程是否运行内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复