Skip to content

Instantly share code, notes, and snippets.

@liaoyw
Last active February 16, 2017 08:59
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 liaoyw/a7b1684caad84e7824867c193fba5bbe to your computer and use it in GitHub Desktop.
Save liaoyw/a7b1684caad84e7824867c193fba5bbe to your computer and use it in GitHub Desktop.
close deleted file fd
# gdb -ex 'set print thread-events off' --batch -q -x ~/df.py
import os
import os.path
import sys
import gdb
pid = open('/var/run/docker.pid', 'r').read()
print 'attach to ' + pid
gdb.execute('attach ' + pid)
os.chdir('/proc/%s/fd'%pid)
out=[]
for f in os.listdir('.'):
if not os.path.islink(f):
continue
if '(deleted)' in os.readlink(f):
#with open(f, 'w') as of:
#of.truncate(0)
out.append(gdb.execute('call close(%d)'%int(f), to_string=True))
print len(out)
gdb.execute('detach')
gdb.execute('quit')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment