vmrss 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # #!/usr/bin/env bash
  2. #
  3. # # Check if PID is provided
  4. # if [ -z "$1" ]; then
  5. # echo "Usage: $0 <PID>"
  6. # exit 1
  7. # fi
  8. #
  9. # PID=$1
  10. #
  11. # # Verify if PID exists
  12. # if ! ps -p "$PID" >/dev/null; then
  13. # echo "Error: Process with PID $PID does not exist."
  14. # exit 1
  15. # fi
  16. #
  17. # # Get VmRSS from /proc/<PID>/status
  18. # VMRSS=$(grep VmRSS /proc/"$PID"/status | awk '{print $2}')
  19. #
  20. # # Check if VmRSS was found
  21. # if [ -z "$VMRSS" ]; then
  22. # echo "Error: Could not retrieve VmRSS for PID $PID."
  23. # exit 1
  24. # fi
  25. #
  26. # # Convert to human-readable format (MB)
  27. # VMRSS_MB=$(echo "scale=2; $VMRSS / 1024" | bc)
  28. #
  29. # echo "Process $PID VmRSS: $VMRSS kB ($VMRSS_MB MB)"
  30. #!/usr/bin/env bash
  31. INTERVAL="${1:-1}"
  32. printf "%-8s %-6s %-6s %-10s %s\n" \
  33. "TIME" "PID" "RT" "RSS(MB)" "CMD"
  34. while true; do
  35. TS=$(date +%H:%M:%S)
  36. ps ax -o pid=,comm=,cmd= | awk '$2 ~ /^(node|nodejs|bun)$/ { print }' | \
  37. while read -r PID COMM CMD; do
  38. STATUS="/proc/$PID/status"
  39. [ ! -r "$STATUS" ] && continue
  40. RSS_KB=$(awk '/VmRSS/ {print $2}' "$STATUS")
  41. [ -z "$RSS_KB" ] && continue
  42. RSS_MB=$(awk "BEGIN { printf \"%.1f\", $RSS_KB/1024 }")
  43. RT=$(case "$COMM" in
  44. bun*) echo "bun" ;;
  45. node*) echo "node" ;;
  46. *) echo "js" ;;
  47. esac)
  48. printf "%-8s %-6s %-6s %-10s %s\n" \
  49. "$TS" "$PID" "$RT" "$RSS_MB" "$CMD"
  50. done
  51. sleep "$INTERVAL"
  52. done