Python 进程检查

之前写过一个PHP进程检查,相对于php,python就简洁多了,不得不说在服务器端优势还是很明显的。

        cmd = "ps aux| grep '%s'|grep -v grep " % process
	logging.info(cmd)
	out = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
	infos = out.stdout.read().splitlines()
	if len(infos) >= 1:
		print process + " runing"
	else:
		print process + ' not runing'
		print process + ' begin runing'
		cmd = "cmd here"
		os.system(cmd)
点赞