Monday, July 02, 2007

How to check for a memory leak

Looking for a memory leak is a two-step process. First you use the swap command to see how much swap space is available:

/usr/sbin/swap -s
total: 17228k bytes allocated + 5396k reserved = 22624k used, 29548k available

Type the command three or four times over the space of a minute or two, to see if available swap space keeps getting smaller.

The second step is to identify the suspected process, and see if it is guilty of a memory leak. You may already know which process is causing the problem. If not, the command ps -lu username shows the size of all your processes, as in the example below:

F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME COMD
8 S 5303 226 224 80 1 20 ff38f000 199 ff38f1d0 pts/3 0:01 csh
8 O 5303 921 226 29 1 20 ff38c000 143 pts/3 0:00 ps

The column headed SZ is the size of the process in pages. (The pagesize command will tell you how big that is in Kbytes if you really must know.) Again, repeat the command several times; any program that dynamically allocates memory can be observed growing in size.

No comments:

Post a Comment