Permanent Top

Trying to find out which program on your server keeps on memory leaking is hard sometimes. If it uses up all of your memory, including swap then executing commands is extremely difficult. What I’ve always wanted for emergency sake, is a terminal that sits on my server running top and nothing else. Since my server had a memory problem last night I decided I would have a go at setting it up. I wasn’t all too hard.

In Gentoo, I found the file “/etc/inittab” which takes care of spawning all the login shells on the system. All that I had to do was change one of the lines to look like this. (Note that this is for Gentoo and may not work for any other system).

c6:2345:respawn:/sbin/agetty -n -l /usr/bin/top 38400 tty6 linux

Basically, -n is for no login and -l is to make agetty use /usr/bin/top instead of /bin/login for the program. A quick reboot and on Terminal 6 I had top running.

I don’t know how well top will run if there is no memory left, but it might come in handy in the future.