3 ms·
#!/bin/sh for pid in $@; do cd /proc/"$pid"/fd || continue for fd in *; do file=$(readlink "$fd"); if [ ! -z "$file" ]; then size=$(
by progress-code 9y ago
#!/bin/sh
for pid in $@; do
cd /proc/"$pid"/fd || continue
for fd in *; do
file=$(readlink "$fd");
if [ ! -z "$file" ]; then
size=$( (du -b "$file" 2>/dev/null || echo 0) | awk '{print $1}')
if [ "$size" = "0" ]; then
continue
fi
pos=$(< ../fdinfo/"$fd" grep -F 'pos:' | grep -oP '\d+')
percent=$(echo "100*${pos}/${size}" | bc -l | xargs printf "%2.2f")
echo "${file}: ${percent}% (${pos}/${size})"
fi
done
done
- PowerfulWizard 9y agoI ended up writing very similar code to do the same thing: https://gist.github.com/jhlb/83999422a8d7e8a6e28e https://gist.github.com/jhlb/83999422a8d7e8a6e28e EDIT: as mentioned elsewhere in the thread, the pv program has a way to watch a PID as well that makes this program unnecessary.