Skip to content

Instantly share code, notes, and snippets.

@rram
Created July 25, 2022 19:27
Show Gist options
  • Save rram/6811cb1340bf6f1f5e8f1502f90a488d to your computer and use it in GitHub Desktop.
Save rram/6811cb1340bf6f1f5e8f1502f90a488d to your computer and use it in GitHub Desktop.
Show a file read process counter for a specific file and program
#!/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