-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_manager.py
executable file
·59 lines (51 loc) · 1.4 KB
/
process_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'''************************************************************************
> File Name: process_manager.py
> Author: libo
> Mail: [email protected]
> Created Time: Mon 03 Dec 2018 11:42:33 AM CST
*********************************************************************'''
#!/usr/bin/python
import psutil
import signal
import time
import os
import sys
def specific_pid(p_name_list):
pids = psutil.pids()
pname_list = {}
for p in p_name_list:
pname_list[p] = False;
for pid in pids:
p = psutil.Process(pid)
args = p.cmdline()
#print 'args:',args
cluster_flags = 0
for arg in args:
for p in p_name_list:
if(arg.find(p) != -1 ):
pname_list[p] = True;
break;
return pid_list;
last_pid_list = {}
last_pid_dic ={}
found = False
while True:
cur_time = time.time()
pid_list = specific_pid()
for pid in pid_list:
last_pid_dic[pid]=cur_time
last_pid_list = pid_list;
if( True):
#if( len(last_pid_dic) < 5):
#if( found ):
if( True ):
for pid,v in last_pid_list.items():
os.kill(pid, signal.SIGKILL)
print 'kill ',pid
found = False
else:
found = True
else:
print('cluster work fine:',last_pid_list)
time.sleep(600)
if __name__ == '__main__':