Monitoring bash Intermediate

Memory Leak Detector via RSS

Track RSS memory of a process over time and alert if it grows beyond threshold.

bash
#!/bin/bash
PID=$(pgrep -f myapp | head -1)
MAX_MB=512
while true; do
  RSS_KB=$(awk '/VmRSS/ {print $2}' /proc/$PID/status)
  RSS_MB=$((RSS_KB/1024))
  echo "$(date +%H:%M:%S) RSS: ${RSS_MB}MB"
  if [ $RSS_MB -gt $MAX_MB ]; then
    echo ALERT: ${RSS_MB}MB exceeds threshold
  fi
  sleep 60
done

Prerequisites

  • bash
  • procfs

Pro Tips

  • → Compare with Valgrind for root-cause analysis.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
bash
Level
Intermediate
Read time
3 min
Published
Apr 2025
License
Commercial License

Newsletter

New modules every week, directly to your inbox.