metering_processes.py
# -*- coding: utf-8 -*-
import os
import time
import ConfigParser
s1 = 'nohup '
s2 = ' > '
s3 = ' 2>&1 &'
def fun(s):
r = os.popen('ps aux | grep %s'%s).read()
return r
def fun_main():
cp = ConfigParser.ConfigParser()
cp.read('metering_processes.conf')
sts = cp.sections()
for st in sts:
command = cp.get(st, 'command')
execute_file = cp.get(st, 'execute_file')
log_file = cp.get(st, 'log_file')
r = fun(execute_file)
r_vice = command + ' ' + execute_file
s = s1 + r_vice + s2 +log_file + s3
if r_vice not in r:
os.system(s)
if __name__ == '__main__':
while 1:
fun_main()
time.sleep(300)
metering_processes.conf
[tmp_vice]
command=python
execute_file=/root/tmp_vice.py
log_file=/root/tmp_vice_log
[tmp]
command=python
execute_file=/root/tmp.py
log_file=/root/tmp_log