Skip to content

Instantly share code, notes, and snippets.

View gumblex's full-sized avatar

Dingyuan Wang gumblex

View GitHub Profile
@gumblex
gumblex / progress-all.sh
Created May 3, 2017 03:28
Find out each file position opened by a process
#!/bin/bash
for fd in /proc/$1/fd/*; do
if [ ! -f "$fd" ]; then continue; fi
fdnum=$(basename "$fd")
fdinfo=/proc/$1/fdinfo/$fdnum
name=$(readlink "$fd")
size=$(stat -c "%s" "$name" 2>/dev/null || stat -c "%s" "$fd")
progress=$(grep ^pos "$fdinfo" | awk '{print $2}')
if [ $size -eq "0" ]; then
echo '['$fdnum']' "$name"':' $progress'/'$size