Last active
August 29, 2015 14:02
-
-
Save andelf/2ba048643928ced1798a to your computer and use it in GitHub Desktop.
Monitor Process Creation and Quiting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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