Skip to content

Instantly share code, notes, and snippets.

@Ivlyth
Created July 27, 2015 12:13
Show Gist options
  • Save Ivlyth/d7e0f1f3762a56f73bfd to your computer and use it in GitHub Desktop.
Save Ivlyth/d7e0f1f3762a56f73bfd to your computer and use it in GitHub Desktop.
how_many_open_files
def how_many_open_files():
import psutil
pss = psutil.process_iter()
total_count = 0
for p in pss:
if p.num_fds() != len(p.open_files()):
print u'%s with pid %d has diff fds num %d and open files num %d'%(p.name, p.pid, p.num_fds(), len(p.open_files()))
total_count += len(p.open_files())
return total_count
how_many_open_files()
for p in sorted(list(psutil.process_iter()), key=lambda x:len(x.open_files()), reverse=True)[:30]:
print u'%s %d %d'%(p.name(), len(p.open_files()), p.num_fds())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment