Expert C Programming

(Jeff_L) #1

Type the command three or four times over the space of a minute or two, to see if available swap
space keeps getting smaller. You can also use others of the /usr/bin/*stat tools, netstat,
vmstat, and so on. If you see an increasing amount of memory being used and never released, one
possible explanation is that a process has a memory leak.


Handy Heuristic


Listening to the Network's Heartbeat: Click to Tune


Of all the network investigative tools, the absolute tops is snoop.


The SVr4 replacement for etherfind, snoop captures packets from the network and
displays them on your workstation. You can tell snoop just to concentrate on one or two
machines, say your own workstation and your server. This can be useful for troubleshooting
connectivity problems—snoop can tell you if the bytes are even leaving your machine.


The absolute best feature of snoop, though, is the -a option. This causes snoop to output a
click on the workstation loudspeaker for each packet. You can listen to your network ether
traffic. Different packet lengths have different modulation. If you use snoop -a a lot, you
get good at recognizing the characteristic sounds, and can troubleshoot and literally tune a
net "by ear"!


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. If a process appears to
be constantly growing and never leveling off, then suspect a memory leak. It's a sad fact of life that
managing dynamic memory is a very difficult programming task. Some public domain X-Window
applications are notorious for leaking like the Apple Computer board of directors.


Systems often have different malloc libraries available, including ones tuned for optimal speed or
optimal space usage, and to help with debugging. Enter the command


man -s 3c malloc

Free download pdf