Created
June 18, 2015 07:57
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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