Skip to content

Instantly share code, notes, and snippets.

@gumblex
Created May 3, 2017 03:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gumblex/5d8f064bda0a2413309c6620057ecc71 to your computer and use it in GitHub Desktop.
Save gumblex/5d8f064bda0a2413309c6620057ecc71 to your computer and use it in GitHub Desktop.
Find out each file position opened by a process
#!/bin/bash
for fd in /proc/$1/fd/*; do
if [ ! -f "$fd" ]; then continue; fi
fdnum=$(basename "$fd")
fdinfo=/proc/$1/fdinfo/$fdnum
name=$(readlink "$fd")
size=$(stat -c "%s" "$name" 2>/dev/null || stat -c "%s" "$fd")
progress=$(grep ^pos "$fdinfo" | awk '{print $2}')
if [ $size -eq "0" ]; then
echo '['$fdnum']' "$name"':' $progress'/'$size
else
echo '['$fdnum']' "$name"':' $progress'/'$size '('$((100*$progress / $size))'%)'
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment