Created
July 25, 2022 19:27
-
-
Save rram/6811cb1340bf6f1f5e8f1502f90a488d to your computer and use it in GitHub Desktop.
Show a file read process counter for a specific file and program
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 -e | |
pid=${1?No PID given} | |
file=${2?No File given} | |
size=$(stat --printf %s $file) | |
cd /proc/$pid/fd | |
for fd in * | |
do | |
if [ "$file" == "$(readlink $fd)" ]; then | |
break | |
fi | |
done | |
cd .. | |
pos=$(awk -v ORS='' '/pos/{print $2}' fdinfo/$fd) | |
echo $(echo "scale=3; $pos * 100 / $size" | bc)% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment