Skip to content

Instantly share code, notes, and snippets.

@jelmervdl
Created September 23, 2021 09:57
Show Gist options
  • Save jelmervdl/2c3a86456118cfba47ae19c6be20b7e5 to your computer and use it in GitHub Desktop.
Save jelmervdl/2c3a86456118cfba47ae19c6be20b7e5 to your computer and use it in GitHub Desktop.
Print read progress of pids with open files
#!/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