Last active
August 29, 2015 13:57
-
-
Save daleobrien/9798645 to your computer and use it in GitHub Desktop.
List of processes on linux
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
#!/usr/bin/env python | |
import os | |
def list_process(): | |
for pid in os.listdir('/proc'): | |
if not pid.isdigit(): | |
continue | |
try: | |
process = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read() | |
if process: | |
yield process | |
except IOError: # proc has already terminated | |
continue | |
if __name__ == '__main__': | |
for p in list_process(): | |
print p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment