Skip to content
Louis Charette edited this page Apr 19, 2014 · 1 revision

Example script to check the memory usage.

#!/bin/bash

if test -n "$1"
then
  echo "RSS Column is the memory used in kilobytes (divide by 1024 to get megas)"
else
  echo "Usage mem_stats apache2 or mem_stats all or mem_stats mysqld"
  exit 1
fi

free -m

if [ "$1" = "all" ]; then
  ps -ylA --sort:rss
else
  ps -ylC "$1" --sort:rss
fi

exit 0

Example output

RSS Column is the memory used in kilobytes (divide by 1024 to get megas)
             total       used       free     shared    buffers     cached
Mem:          2002       1769        232          0         89        609
-/+ buffers/cache:       1070        932
Swap:         3074        367       2707
S   UID   PID  PPID  C PRI  NI   RSS    SZ WCHAN  TTY          TIME CMD
S    33 19531 19529  0  80   0  3352  2507 ep_pol pts/4    00:00:00 aped-1.1.2-dev-

In this case aped uses 3352 kb (around 3 mb)

Clone this wiki locally