Skip to content

Instantly share code, notes, and snippets.

@FrostyX
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrostyX/95822fa5ce34ead7b140 to your computer and use it in GitHub Desktop.
Save FrostyX/95822fa5ce34ead7b140 to your computer and use it in GitHub Desktop.
Print list of processes with deleted files
#!/usr/bin/python
import psutil
import re
paths = ['/usr/bin', '/usr/sbin', '/usr/lib', '/lib']
combined = "(" + ")|(".join(paths) + ")"
processes = []
for pid in psutil.get_pid_list():
try:
p = psutil.Process(pid)
for mmap in p.get_memory_maps():
if re.match(combined, mmap.path):
if mmap.path.endswith('(deleted)'):
processes.append(p)
except psutil.AccessDenied:
pass
except psutil.NoSuchProcess:
pass
for p in set(processes):
print p.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment