Created
December 17, 2013 16:45
-
-
Save insom/8008090 to your computer and use it in GitHub Desktop.
How old are inetd's children? #badpython
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 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