Skip to content

Instantly share code, notes, and snippets.

@andelf
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save andelf/2ba048643928ced1798a to your computer and use it in GitHub Desktop.

Select an option

Save andelf/2ba048643928ced1798a to your computer and use it in GitHub Desktop.
Monitor Process Creation and Quiting
import os
import commands
import time
def get_process():
procs = set()
for line in commands.getoutput("ps aux").split('\n'):
if not line: # or '%CPU' in line:
continue
proc = ' '.join(line.split()[10:])
procs.add(proc)
return procs
def run_procs_diff():
last = get_process()
while True:
time.sleep(0.5)
now = get_process()
for p in last.difference(now):
print "Q", p
for p in now.difference(last):
print "C", p
last = now
if __name__ == '__main__':
run_procs_diff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment