Skip to content

Instantly share code, notes, and snippets.

@insom
Created December 17, 2013 16:45
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 insom/8008090 to your computer and use it in GitHub Desktop.
Save insom/8008090 to your computer and use it in GitHub Desktop.
How old are inetd's children? #badpython
import os
import stat
from os.path import dirname
from glob import glob
import time
for cmdline in glob('/proc/*/cmdline'):
f = open(cmdline).read()
if f.startswith('/usr/sbin/inetd'):
inetd_pid = int(cmdline.split('/')[2])
ages = []
for status in glob('/proc/*/status'):
try:
lines = open(status).readlines()
for line in lines:
if line.startswith('PPid'):
ppid = int(line.split()[1])
if ppid == inetd_pid:
cmdline = open('%s/cmdline' % dirname(status)).read()
pid = int(dirname(status).split('/')[2])
inception = os.stat('%s/mounts' % dirname(status))[stat.ST_CTIME]
ages.append((int(time.time() - inception), pid))
except:
pass
ages.sort()
print ages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment