vmrss 889 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. has_gum() {
  4. command -v gum >/dev/null 2>&1
  5. }
  6. die() {
  7. if has_gum; then
  8. gum style --foreground 196 --bold "error:" "$1"
  9. else
  10. echo "error: $1" >&2
  11. fi
  12. exit 1
  13. }
  14. if [ -z "${1:-}" ]; then
  15. die "usage: $0 <PID>"
  16. fi
  17. PID=$1
  18. if ! ps -p "$PID" >/dev/null 2>&1; then
  19. die "process with PID $PID does not exist"
  20. fi
  21. VMRSS_KB=$(awk '/^VmRSS:/ { print $2 }' /proc/"$PID"/status)
  22. [ -z "$VMRSS_KB" ] && die "could not read VmRSS for PID $PID"
  23. VMRSS_MB=$(awk -v kb="$VMRSS_KB" 'BEGIN { printf "%.2f", kb / 1024 }')
  24. if has_gum; then
  25. echo "$(gum style --bold "PID:") $(gum style --faint "$PID")"
  26. echo "$(gum style --foreground 240 "VmRSS:") $(gum style --foreground 33 "${VMRSS_KB} kB") ($(gum style --foreground 244 "${VMRSS_MB} MB"))"
  27. else
  28. echo "PID: $PID"
  29. echo "VmRSS: $VMRSS_KB kB ($VMRSS_MB MB)"
  30. fi