Commit 1eb58004 authored by Julien Muchembled's avatar Julien Muchembled Committed by Kirill Smelkov

shmtop: New tool to show who uses /dev/shm the most

parent 27936225
#!/usr/bin/python
import errno, os, pwd
os.chdir('/proc')
z = []
for p in os.listdir('.'):
try:
pid = int(p)
except ValueError:
continue
n = 0
x = p + '/fd'
try:
for y in os.listdir(x):
y = x + '/' + y
if os.readlink(y).startswith('/dev/shm/'):
y = os.open(y, 0)
try:
n += os.fstat(y).st_blocks
finally:
os.close(y)
except OSError, e:
if e.errno != errno.ENOENT:
raise
if n:
try:
with open(p + '/status') as x:
x = dict(x.split(':', 1) for x in x)
except IOError, e:
if e.errno != errno.ENOENT:
raise
continue
uid = map(int, x['Uid'].split())
z.append((pwd.getpwuid(uid[0]).pw_name, x['Name'].strip(), pid, n))
z.sort(key=lambda x: x[3])
from pprint import pprint as pp
pp(z)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment