Bash public

Process Memory Hogs

Share this script safely, inspect its metadata, and copy the exact command you need.

Dashboard

Ready to run

One-liner

Copy the command, then review before execution.
curl -fsSL https://runny.sh/r/F7Z19D2H7Y1B | bash

Current version: 1.1 · Updated by Godmode · 2026-09-07 02:38:59.226

At a glance

Script metadata

Slug
F7Z19D2H7Y1B
Fetches
0
Size
2121 B · 72 lines
Expires
never
Last fetch
Created
2026-09-07 00:35:59.391
Description
Top processes by resident memory

Readable before runnable

Preview

#!/usr/bin/env bash
# Process memory hogs
# Read-only: top 10 processes by RSS. Warns if the leader uses >=25% of RAM, crit at >=50%.
# Exit 0 if healthy, 1 if warning, 2 if critical or ps is missing.
# Hosted on Runny.sh. Review the script page before you run it.

set -u

status=0
note() { printf '%s\n' "$*"; }
bump() {
  case $1 in
    crit) status=2 ;;
    warn) [ "$status" -lt 1 ] && status=1 ;;
  esac
}

note "=== Top processes by RSS ==="
note "Host:     $(hostname 2>/dev/null || printf unknown)"
if ! command -v ps >/dev/null 2>&1; then
  note "ps:       not found in PATH"
  note "Result: CRITICAL"
  exit 2
fi

mem_kb=0
if [ -r /proc/meminfo ]; then
  mem_kb=$(awk '/^MemTotal:/ {print $2}' /proc/meminfo)
  note "Memory:   $((mem_kb / 1024)) MiB total"
fi
note ""
note "PID      USER            RSS_MiB  %MEM  COMMAND"
note "-------- --------------- -------- ----- ----------------"

top=$(ps -eo pid,user,rss,pcpu,comm --sort=-rss 2>/dev/null | awk 'NR > 1 {print}' | head -n 10)
if [ -z "${top}" ]; then
  note "No process table returned"
  bump warn
else
  printf '%s\n' "$top" | while IFS= read -r row; do
    pid=$(printf '%s\n' "$row" | awk '{print $1}')
    user=$(printf '%s\n' "$row" | awk '{print $2}')
    rss=$(printf '%s\n' "$row" | awk '{print $3}')
    pcpu=$(printf '%s\n' "$row" | awk '{print $4}')
    comm=$(printf '%s\n' "$row" | awk '{print $5}')
    note "$(printf '%-8s %-15s %8s %5s %s' "$pid" "$user" "$((rss / 1024))" "$pcpu" "$comm")"
  done
  lead_rss=$(printf '%s\n' "$top" | awk 'NR == 1 {print $3}')
  if [ "${mem_kb}" -gt 0 ] && [ -n "${lead_rss}" ]; then
    pct=$((lead_rss * 100 / mem_kb))
    note ""
    note "Leader:   ${pct}% of RAM"
    if [ "$pct" -ge 50 ]; then
      note "          CRITICAL: one process holds at least half of RAM"
      bump crit
    elif [ "$pct" -ge 25 ]; then
      note "          WARNING: one process holds at least a quarter of RAM"
      bump warn
    else
      note "          OK"
    fi
  fi
fi
note ""

case $status in
  0) note "Result: HEALTHY" ;;
  1) note "Result: WARNING" ;;
  *) note "Result: CRITICAL" ;;
esac
exit "$status"

Raw endpointhttps://runny.sh/r/F7Z19D2H7Y1B

See something unsafe?

Report this script

Tell us why it should come down. Anyone can also report a URL at /abuse.

Restore revision