blob: f8873e7b84fbf18f7695c254e05ca688f42a3095 (
plain)
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
|
#!/usr/bin/env python
import os
start_pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
print 'PIDs', str(start_pids)
# we don't do an active sleep here, results in slightly increasing usage for one of your CPU cores
while True:
cur_pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
for pid in cur_pids:
if pid in start_pids:
continue
try:
cmdline = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read().replace('\x00', ' ')
if len(cmdline) == 0 or cmdline.startswith('bash') is True or \
cmdline.endswith('sh') is True:
continue
start_pids.append(pid)
outstr = 'NEW[%s]: ' % (pid) + cmdline
print outstr
except IOError:
print 'PID', pid, '!exist'
continue
|