Crashing, otherwise known as locking up or freezing, is a well-known and all-too-frequent phenomenon in the Windows world. With Linux systems, on the other hand, it is not uncommon for servers and other always-on systems to go for months without needing a single reboot. I’ve used Linux for roughly… oh around 9 years now, and Windows since the days of 3.x in the early 90’s, and can tell you from experience that Linux crashes are few and far between… especially when compared to the rate of Windows crashes. That said, it can happen from time to time, and it’s better that you know how to recover from them. Just powering off while everything’s running is not good for any operating system, Windows or otherwise, and may damage your data, so it’s best to avoid it if you can and try to get everything to shut down in an orderly manner. Here are some ways to do it.
Track it down and kill it!
If a certain program has locked up but the computer is still functional, meaning you can still move the mouse, select menu items, etc., and it’s not practical or desirable to reboot the machine, then killing the program will do the trick. (You may feel like killing it if you just typed up a long document without saving and it has locked up, potentially losing all your work, but that’s not what I’m talking about.) You can open a terminal window (also known as Console, shell, or command prompt) and type in:
ps -ef | less
(If you haven’t seen that vertical bar | before it’s called a “pipe,” often found on the backslash \ key. It looks like two little vertical lines, one stacked on top of the other, but when you type it it’s one solid line.) This will give you a long list of processes that the computer is currently running. Here’s a little snippet of my listing as an example:
lisa 5861 1 14 Dec23 ? 01:41:47 /usr/lib/firefox/firefox
lisa 9522 5861 2 Dec23 ? 00:07:03 /usr/lib/nspluginwrapper/i386/li
lisa 11147 5510 0 00:27 ? 00:00:02 gnome-terminal
lisa 11149 11147 0 00:27 ? 00:00:00 gnome-pty-helper
lisa 11150 11147 0 00:27 pts/0 00:00:00 bash
You can now use the cursor up or down keys to scroll through your list and look for the name of the misbehaving program. For the sake of argument, and because it’s what I have running at the moment, let’s say my Firefox has crashed. The first column is my username, and the second is the process ID (pid for short). The last column tells me the name of the process (program). Take note of the pid’s of any processes that bear the name of the program giving you trouble. In this case I’m looking for anything with firefox in it. I can see Firefox is running with a pid of 5861, so I hit Q to quit out of the listing and type
Some distributions may complain that you don’t have the right to do this. If so you will need to do it as the root user (aka administrator). To do that in Ubuntu and other distributions based on it such as Kubuntu and Mint, add sudo in front of all the commands, as in sudo kill 5861. It will ask for the root password the first time you do this. For most other distributions type su and hit enter. It will ask you for the root password (not your user password, remember) and after that the prompt will end with a # instead of a $, and you can just enter the commands as they appear here. If this fails to close the program, and you took note of more than one pid to kill for this program, repeat the kill command for each remaining pid. If this still doesn’t do it, use the same kill command(s) but with -9 option. In my case:
kill -9 5861
Granted, the kill -9 option is not the nicest or neatest way to kill a program, which is why it’s a last resort, but it is the silver bullet… if nothing else does it this will. If it doesn’t, you have probably missed another pid that needs to be killed or you aren’t properly running kill as the root user.
There are shortcuts to this process if you know the name of the program – that is, what you would type in at a terminal to start it up, you can just type pkill followed by the program name. In this case, I happen to know it’s firefox. So I can type
ps -ef | grep firefox
to check if it actually stopped the program and all its processes. If not, the -9 option above works with pkill too.
pkill -9 firefox
That’s great, you say, but what if my whole system seems to have locked up?