Skip to content

Instantly share code, notes, and snippets.

@nicdoye
Created June 15, 2017 13:20
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 nicdoye/96dd17ce44a0c93037fa164d2bdc345e to your computer and use it in GitHub Desktop.
Save nicdoye/96dd17ce44a0c93037fa164d2bdc345e to your computer and use it in GitHub Desktop.
Incredibly dangerous script to remove open inodes of deleted files
#!/bin/bash
while [[ $(lsof -nP +L1 | wc -l) > 1 ]]
do
pair=$(lsof -nP +L1 | tail -n 1 | awk '{print $2" " $4}')
pid=$(echo $pair | awk '{print $1}')
fd=$(echo $pair | awk '{print $2}' | sed -e 's_[a-z]__g')
file=$(mktemp)
# Race condition check on first line of lsof output
[[ ! "${pid}" =~ ^[0-9]*$ ]] && continue
cat > ${file} << EOF
define hook-quit
set confirm off
end
p close(${fd})
quit
EOF
gdb -p ${pid} -x $file
rm $file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment