Created
May 3, 2017 03:28
-
-
Save gumblex/5d8f064bda0a2413309c6620057ecc71 to your computer and use it in GitHub Desktop.
Find out each file position opened by a process
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 | |
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