Created
September 23, 2021 09:57
-
-
Save jelmervdl/2c3a86456118cfba47ae19c6be20b7e5 to your computer and use it in GitHub Desktop.
Print read progress of pids with open files
This file contains hidden or 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 | |
find-open-files() { | |
find /proc/$1/fd/ -maxdepth 1 -lname '/*' -not -lname '/dev/*' -printf "%f\n" | |
} | |
format-file() { | |
readlink -f /proc/$1/fd/$2 | |
} | |
progress-file() { | |
pos=$(cat /proc/$1/fdinfo/$2 | awk '$1 == "pos:" {print $2}') | |
size=$(stat -L --format '%s' /proc/$1/fd/$2) | |
echo $((pos * 100 / size))'%' | |
} | |
progress() { | |
local pid=$1 | |
for file in $(find-open-files $pid); do | |
echo $(progress-file $pid $file) $(format-file $pid $file) | |
done | |
} | |
for pid in $*; do | |
progress $pid | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment