Skip to content

Instantly share code, notes, and snippets.

@maliubiao
Created September 2, 2013 02:14
Show Gist options
  • Save maliubiao/6408685 to your computer and use it in GitHub Desktop.
Save maliubiao/6408685 to your computer and use it in GitHub Desktop.
locate opened files
#! /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