Skip to content

Instantly share code, notes, and snippets.

@gojomo
Created June 18, 2015 07:57
Show Gist options
  • Save gojomo/d109f56735b49fa22f09 to your computer and use it in GitHub Desktop.
Save gojomo/d109f56735b49fa22f09 to your computer and use it in GitHub Desktop.
lspid.sh: given pid, list open files & seek offsets (effectively watch progress, if util scans large file front to back)
#!/bin/bash
TARGET_PID=$1
shift
cd /proc/$TARGET_PID/fd/
if [ -n "$1" ]
then
TARGET_FDS=$@
else
TARGET_FDS=*
fi
for fd in $TARGET_FDS
do
stat -c"%N" $fd
offset=`head -1 /proc/$TARGET_PID/fdinfo/$fd | cut -f2`
length=`stat -L -c"%s" $fd`
echo -n "$offset/$length "
if [ $length -gt 0 ]
then
echo "($(($offset*100/$length))%)"
else
echo
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment