Skip to content

Instantly share code, notes, and snippets.

@daleobrien
Last active August 29, 2015 13:57
Show Gist options
  • Save daleobrien/9798645 to your computer and use it in GitHub Desktop.
Save daleobrien/9798645 to your computer and use it in GitHub Desktop.
List of processes on linux
#!/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