Created
September 2, 2013 02:14
-
-
Save maliubiao/6408685 to your computer and use it in GitHub Desktop.
locate opened files
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
#! /usr/bin/env python | |
import os | |
import sys | |
import os.path | |
proc = '/proc' | |
fullpath = '' | |
query = sys.argv[1] | |
got = '' | |
for path in os.listdir(proc): | |
try: | |
fullpath = "%s/%d/fd" % (proc, int(path)) | |
fds = os.listdir(fullpath) | |
except: | |
continue | |
for fd in fds: | |
try: | |
got = os.readlink("%s/%s" % (fullpath, fd)) | |
if query in got: | |
print "matches:",got | |
print "pid:",path | |
print "bin:",os.readlink("%s/../exe" % fullpath) | |
except: | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment