[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17. Recovering from Crashed Programs

Linux is renowned for its stability, and it's true that the operating system itself seldom crashes or hangs. The programs you run on it however, might not be so sturdy, and some programs can and do crash. Unlike some other operating systems, Linux itself is rarely affected by crashing programs.Recovery is normally fairly easy, and reboots are very rarely required.

17.1 Terminating Misbehaving Programs  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.1 Terminating Misbehaving Programs


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.1.1 XKill

XKill is a handy tool for terminating hung or frozen apps that refuse to respond to the File>Quit button, or the windows close button. Simply start xkill, either from your menus or an Xterminal window, and the mouse cursor will change into something resembling a gunsight. Move the cursor over the offending window and click on it; this will usually shut down the problem program.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.1.2 The ps and kill Commands

The ps command is an extremely useful tool that is run from the command line to list all the processes currently running. It can be used in conjunction with the kill command to stop crashed or runaway programs. To use it, open an xterminal and type in: ps -aux. The -aux option just makes ps show some additional information. You'll be presented with a list of all the running processes, their owners, their resource usage and so on. On the extreme left side you'll see the identifying number (or PID) of each process. This number can be used with the kill command to stop rogue programs.

As an example, we'll assume Netscape has crashed, and can't be shutdown normally. Running ps -aux shows up Netscape in the list of running processes, along with Netscapes PID or process identifying number (let's say the PID is 2345). Typing in this:
kill 2345
should stop Netscape immediately. Run ps -aux again to see if it has indeed been killed. What if it's still there? Run the kill command again, but this time with the -9 option, eg.
kill -9 2345 should do the trick.

The kill command (without the -9) should always be tried first, as it gives the process a chance to close any files it may have open and generally tidy up after itself, whereas kill -9 is not so gentle and just kills the process instantly. Note that the 2345 PID I've used is just an example, and that each process is allocated a PID number when it is started.

There is another version of kill, and that is killall. The killall command is used with the processes name, rather than PID. For example:
killall netscape
or
killall -9 netscape
could be used when you know the processes name.

The ps -aux command is also handy for spotting resource hogs. Let's say for example you are working at your computer when you notice things are slowing to a crawl. Run ps-aux and check the columns showing the cpu and memory usage to spot the offending program. You can then use kill to terminate it if you wish.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.1.3 Stopping Command Line Programs

Occasionally you may start a program from the command line, only to find that it hangs, or runs away eating up resources. In these cases, you can usually stop it simply by hitting <ctrl-c>, ie. holding down the Ctrl and the c key at the same time.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.2 X Related Problems

In Linux, the GUI system (ie. the graphical display, mouse cursor etc) are commonly referred to simply as X. What do you do if a program hangs or crashes, and takes your mouse cursor with it? You can't use xkill, and you mightn't be able to open a terminal window either. What you can do is hit Alt-Ctrl-Backspace to restart X and regain mouse control. If you do this, you should probably run ps -aux when X restarts just to make sure the crashed program didn't leave any leftover processes. These should be killed before restarting them in the new X session.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.3 Rebooting - The Last Resort

Unlike other systems, Linux very rarely requires a reboot. However, if a program locks up so badly that neither the mouse or keyboard respond, rebooting may be the simplest solution. If you can somehow reboot normally then this is preferable to simply hitting the power button, but sometimes you just have no other option. For those using a journalling filesystem such as ext3 or reiserfs (these are often installed by default with recent distros) this shouldn't cause any problems; ext2 users will probably find the system will complain about the rude shutdown and automatically run a filesystem check at the next bootup. Usually though, everything will be OK.
[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated on March, 5 2003 using texi2html
Hosted by www.Geocities.ws

1