Last active
August 29, 2015 14:10
-
-
Save apalii/62516627c6506823955f to your computer and use it in GitHub Desktop.
memory usage of some process
This file contains 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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output :
{'pid': 2233, 'name': 'firefox'}
mem usage 8.75593977457
https://pythonhosted.org/psutil/