process.py26 lines · 850 B
| 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | start_pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] |
| 6 | print 'PIDs', str(start_pids) |
| 7 | |
| 8 | # we don't do an active sleep here, results in slightly increasing usage for one of your CPU cores |
| 9 | while True: |
| 10 | cur_pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] |
| 11 | for pid in cur_pids: |
| 12 | if pid in start_pids: |
| 13 | continue |
| 14 | try: |
| 15 | cmdline = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read().replace('\x00', ' ') |
| 16 | |
| 17 | if len(cmdline) == 0 or cmdline.startswith('bash') is True or \ |
| 18 | cmdline.endswith('sh') is True: |
| 19 | continue |
| 20 | start_pids.append(pid) |
| 21 | outstr = 'NEW[%s]: ' % (pid) + cmdline |
| 22 | print outstr |
| 23 | except IOError: |
| 24 | print 'PID', pid, '!exist' |
| 25 | continue |
| 26 |