Skip to content

Instantly share code, notes, and snippets.

@apalii
Last active August 29, 2015 14:10
Show Gist options
  • Save apalii/62516627c6506823955f to your computer and use it in GitHub Desktop.
Save apalii/62516627c6506823955f to your computer and use it in GitHub Desktop.
memory usage of some process
import psutil
for proc in psutil.process_iter():
try:
proc = proc.as_dict(attrs=['pid', 'name'])
except psutil.NoSuchProcess:
pass
else:
if proc['name'] == 'firefox':
print proc
print "mem usage ", psutil.Process(proc['pid']).get_memory_percent()
# Kill child processes :blush:
import psutil, os
def kill_proc_tree(pid, including_parent=True):
parent = psutil.Process(pid)
for child in parent.children(recursive=True):
child.kill()
if including_parent:
parent.kill()
me = os.getpid()
kill_proc_tree(me)
@apalii
Copy link
Author

apalii commented Nov 27, 2014

output :
{'pid': 2233, 'name': 'firefox'}
mem usage 8.75593977457
https://pythonhosted.org/psutil/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment