Skip to content

Instantly share code, notes, and snippets.

@norpol
Last active February 11, 2017 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norpol/ff54a3cefcba4a89882147bb76ca36f7 to your computer and use it in GitHub Desktop.
Save norpol/ff54a3cefcba4a89882147bb76ca36f7 to your computer and use it in GitHub Desktop.
tiny iotop alternative
#!/bin/sh
# 2017 © MIT https://gist.github.com/norpol/
# Usage: pidiotop.sh <PID>
# Example: pidiotop.sh $(pgrep -n dd)
# Requires: bc
set -ue
pid="${1}"
interval=10
bbytes=
bytes=
while true; do
bbytes="${bytes}"
bytes=$(awk -v rbytes='read_bytes:' '$1 == rbytes { print $2; exit}' "/proc/${1}/io")
if [ -n "${bbytes}" ]; then
mbs=$(echo "(${bytes}-${bbytes})/${interval}/1000/1000" | bc -l)
printf "\r${mbs}MB/s"
fi
sleep "${interval}"s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment