| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #!/usr/bin/env bash
- set -euo pipefail
- has_gum() {
- command -v gum >/dev/null 2>&1
- }
- die() {
- if has_gum; then
- gum style --foreground 196 --bold "error:" "$1"
- else
- echo "error: $1" >&2
- fi
- exit 1
- }
- if [ -z "${1:-}" ]; then
- die "usage: $0 <PID>"
- fi
- PID=$1
- if ! ps -p "$PID" >/dev/null 2>&1; then
- die "process with PID $PID does not exist"
- fi
- VMRSS_KB=$(awk '/^VmRSS:/ { print $2 }' /proc/"$PID"/status)
- [ -z "$VMRSS_KB" ] && die "could not read VmRSS for PID $PID"
- VMRSS_MB=$(awk -v kb="$VMRSS_KB" 'BEGIN { printf "%.2f", kb / 1024 }')
- if has_gum; then
- echo "$(gum style --bold "PID:") $(gum style --faint "$PID")"
- echo "$(gum style --foreground 240 "VmRSS:") $(gum style --foreground 33 "${VMRSS_KB} kB") ($(gum style --foreground 244 "${VMRSS_MB} MB"))"
- else
- echo "PID: $PID"
- echo "VmRSS: $VMRSS_KB kB ($VMRSS_MB MB)"
- fi
|