A beginner’s introduction to the GNU/Linux command line, Part II—Managing processes

A beginner’s introduction to the GNU/Linux command line, Part II—Managing processes


Your GNU/Linux computer is an amazing machine. It can display images. It can run programs. It can perform dozens of functions all at the same time. How can you keep track of all this activity? By monitoring the processes that your computer runs, and one of the best ways to monitor and control processes is by using the command line.

Long ago computers were like calculators—they did one thing at a time—but today’s computers can multi-task doing hundreds of things at the same time. The different tasks share processor time. This is why you can search the web while writing a paper and listening to music all on the same computer at the same time.

What do you do when you can’t make your process stop no matter how many times you click that little `x` in the corner?

Each of these different things happening on the computer is called a “process”, and your computer takes turns letting all of the processes run a little bit at a time. The computer works so fast that you usually don’t even notice.

But occasionally, a process stops responding to you. What do you do when you can’t make your process stop no matter how many times you click that little x in the corner? You try using the keyboard commands Esc and Ctrl + C. You even try Ctrl + Q, Ctrl + X, and Ctrl + Z; but they don’t work. What do you do next?

If you can get into a terminal, you can kill any process

Well, if you can get into a terminal, you can kill any process. The command is called kill. The command name is easy enough to remember, but your problem is knowing what to kill. Each process has a different process identification number (PID) and you must use that number to kill it.

To see a list the processes currently running on your system, you can use the command ps. If I open a terminal program and type ps now, I will see this:

rosalyn@onizuka:~$ ps
  PID TTY          TIME CMD
14036 pts/2    00:00:00 bash
14040 pts/2    00:00:00 ps

(The prompt on my system says rosalyn@onizuka:~$. Needless to say, your computer will say something different. When I show an example like this, only type the words after the dollar sign. The computer’s response will be shown on the following lines.)

The computer responds telling me what processes I am currently running in this terminal window. First, I am running the terminal window itself using the BASH shell. Then I am running the command ps. That’s not very informative. Is it?

I would really like the computer to show me all of the processes running on my system. To find that, I must use options (letters typed after the command that modify its function). In order to see all of the processes running on my system, I use the ps aux command:

rosalyn@onizuka:~$ ps aux
  • ps reports a snapshot of the current processes running on your system.
  • a tells the computer to show all processes
  • u tells the user name of who owns the process, and
  • x lists processes that were not started in a terminal.

This command will return a long list of processes that scrolls off my terminal screen. Somewhere in that list is the process ID that I am looking for. If I am using a terminal with a scroll bar, I can just scroll back up and read it all to find the process. Personally, however, I prefer to use a different command to get the process ID. The command called top.

Tasks and processes

What’s the difference between a task and a process? Nobody knows. For the most part people use the word task when they are talking about sending things to the processor to avoid saying things like, “the processor processes the process”.

Well, actually, there is a difference between tasks and processes. The process that starts your computer is called init. It is listed by the process ID 1. This process is also called Task [0]. For the most part, however, just consider tasks and processes to be the same thing.

Top lists the processes using the most time on the computer’s processor. It prints only what will fit in your terminal window, and it refreshes every few seconds to give you an up to date picture of your system. If your program has stalled, then it is probably taking up lots of processor time, and it will be right near the top of the list. Typing top on my system shows me this:

top - 00:15:36 up 10:53,  1 user,  load average: 0.79, 0.69, 0.58
Tasks:  86 total,   3 running,  83 sleeping,   0 stopped,   0 zombie
Cpu(s): 29.9% us,  6.6% sy,  0.0% ni, 62.8% id,  0.0% wa,  0.3% hi,  0.3% si
Mem:    484292k total,   361820k used,   122472k free,    25596k buffers
Swap:  1421712k total,        0k used,  1421712k free,   169384k cached

  PID   USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
  13247 rosalyn   16   0  155m  67m  46m R 26.3 14.2  11:58.69 seamonkey-bin
   3363 root      15   0 93448  50m  44m S  9.0 10.6   6:05.50 XFree86
  14032 rosalyn   15   0 27320  14m  25m S  1.0  3.0   0:02.04 konsole
  13227 rosalyn   15   0 14168 9928  11m S  0.7  2.1   0:09.65 gvim
   3094 gkrellmd  15   0 18824 1340 2240 S  0.3  0.3   2:24.32 gkrellmd
  13207 rosalyn   15   0 26532  14m  23m S  0.3  3.1   0:01.69 kdeinit
  14196 rosalyn   16   0  2104 1084 1888 R  0.3  0.2   0:00.11 top
      1 root      16   0  1516  520 1364 S  0.0  0.1   0:00.58 init

If you lengthen the terminal window, it will show more data. Now, suppose the program “seamonkey” was frozen. I could kill it by typing the command kill followed by seamonkey’s process ID 13247.

Of course, to do this I need to get a prompt again. Top will keep refreshing in the terminal window until you tell it to stop. Both the letter q for quit and typing the control button and c at the same time (Ctrl + C) will stop the program and give you back your prompt.

To kill seamonkey, I can type:

rosalyn@onizuka:~$ kill 13247 

This should stop the process causing the seamonkey window to close, but sometimes it doesn’t. What do I do if seamonkey still won’t close?

Well, kill also has options. The basic command tries to be nice. It says, “Could you please stop now?” But if the process just won’t die when you ask it nicely, then use the option -9. The command kill -9 says “take no prisoners!”

So if kill alone doesn’t work, I can type:

rosalyn@onizuka:~$ kill -9 13247

That almost always will terminate the process.

Oh, by the way, you can only kill your own processes as a user. This protects you from accidentally shutting off someone else’s programs. If you are logged in as a superuser, however, you can stop another person’s programs.

Make sure to kill the right process though. In the listing above, you may notice that right below seamonkey is a listing for a process called XFree86. XFree86 is my window manager. Killing that would close all of my windows including the terminal that I am writing in now, so be cautious with kill.

The user Root is no normal user!The user Root is no normal user!

Users and superusers

GNU/Linux is designed to keep you from doing things that would damage your system. Each person is given their own account. All of a user’s files are labeled as their own and other people usually can’t change them. It is the same way for processes. Processes are labeled as belonging to someone, and you can only start and stop processes that belong to you.

But some processes belong to no one, and sometimes processes belonging to someone else get out of control. To affect those processes you have to become a superuser. A superuser, like a superhero, has amazing powers that mere mortals do not. They can start or stop any process; restrict access to files, or free them; add and remove users; and any of a number of incredible things. A superuser can also completely trash your system, so remember “with great power comes great responsibility”.

A superuser, like a superhero, has amazing powers that mere mortals do not

Since being a superuser is so dangerous, most people only become one when they must. This is one of the major reasons that people use the command line. They login to a terminal as a superuser, and they logout when they have finished the task that they came to do.

On a GNU/Linux system, the superuser is called “root”. When you run top you will often find processes that are owned by root, and only root can kill those processes. To become root you must switch user using the command su. When you type su root it will prompt you for a password.

rosalyn@onizuka:~$ su root
Password:   

You had to set a root password when you installed the Linux kernel, so the person who installed your system should have the root password. When you have the root password, you have ABSOLUTE CONTROL over the system (diabolical laughter), so it should not be given out casually.

If the person guarding the password refuses to give you this power, and you are tired of asking them to do something for you such as install new packages in a Debian system using apt-get install, they can give you partial power by using the command sudo. It means “switch user and do”.

Slay

There is a program called slay that will kill all of the processes used by another person. You can install it on your computer and access it from the command line. I use it when my son leaves several process-hogging games running in the background.

As a superuser, just type slay and a user name. The user’s processes will be terminated. Needless to say, doing this while someone is working on the computer is a way to lose a few friends. So, like all of these commands, caution is required as well as tact.

If you’d like to see what it feels like to get slayed, save any unsaved documents and then type slay and your user name. The effect is quite catastrophic and upsetting. Don’t say I didn’t warn you.

Using grep

Do you remember how I said that ps will give you a list of processes? And, lazy person that I am, I didn’t want to take the time to read them all. If you want to find a particular process in a long list, you can search the list using the command grep.

Grep is one of those tools that “oldetyme” programmers couldn’t survive without

When I type whatis grep on the command line it returns the following:

rosalyn@onizuka:~$ whatis grep
grep (1)             - print lines matching a pattern

Of course there are other ways for me to find a specific process. There are options to ps (type ps --help for the options.) The command ps -C, for example, lets you search by command name. There is even a different command called pstree that makes a layered diagram of all of the currently running processes. But let us imagine for now that we are option-challenged.

grep is one of those tools that “oldetyme” programmers couldn’t survive without. It searches a file for a string and prints it on the screen. You can write the data from the ps command into a file, and then search it with grep. Do this by using the greater-than arrow “>” to send the data to a file. Type the following:

rosalyn@onizuka:~$ ps aux > pslog.txt

This writes the output of the command ps aux to a file called pslog.txt.

Reading files on the command line

You can read a file on the command line by using the command cat. Typing cat pslog.txt will write the contents of the file to the screen, but it scrolls the entire file across the screen without stopping. If you want to read a file one page at a time, you can use the command more which will write only what fits on your screen. Press the space bar to scroll to the next page. Older versions of more only scroll text in one direction, down. Because of this, another program was written that can use the arrow keys to scroll up and down within a file. That program is called less. (Programmers have a weird sense of humor.)

Now that you have the file, you can search in it. Let’s say you’re looking for a program called abiword. You should type:

rosalyn@onizuka:~$ grep 'abiword' pslog.txt

Doing that returns the string:

rosalyn  13386  0.1  2.6 23264 12632 pts/3   S    08:16   0:00 /usr/bin/abiword

Now you’ve found Abiword’s process ID. In my example it is 13386.

But in my mind’s eye I can hear some veteran command line user out there scoffing. “Ha!” he says, “I could do all of that in one line.” It is true that there are usually many ways to do the same thing when you are using the command line. I could simply type:

rosalyn@onizuka:~$ ps aux | grep "abiword"

The vertical line between the two commands is called a pipe. It is found above the backslash on the keyboard, and it is used to send the output of a process to another process just as the greater than arrow > is used to send the output of a process to a file. This command pipes the output of ps directly to grep and then prints it on the screen.

rosalyn@onizuka:~$ ps aux | grep "abiword"
rosalyn  13386  4.2  2.6 23264 12632 pts/3   S    08:16   0:00 /usr/bin/abiword
rosalyn  13396  0.0  0.1  1848  608 pts/2    R+   08:17   0:00 grep abiword
rosalyn@onizuka:~$ 

The first line shows the command you searched for and its PID 13386. The second line shows the ID for the command grep that you just ran to get this data. Pipes and arrows are really useful shorthands, and you can make quite complex commands that all fit on one line, if that makes you happy.

grep is a very useful tool. To see the options, try typing grep --help on the command line. Some of the more useful options are grep -r which will search recursively, meaning that it will search not only the files in a directory, but the files in all of the directories below it. grep -C which stands for context prints a number of lines that you specify above and below a line searched. So, for example, when I type:

rosalyn@onizuka:~$ grep -C3 'not to be' Hamlet.txt

the computer returns:

Enter Hamlet.

  Ham. To be, or not to be, that is the Question:
Whether 'tis Nobler in the minde to suffer
The Slings and Arrowes of outragious Fortune,
Or to take Armes against a Sea of troubles,

In the example above, two of the three lines above the searched for line are blank. Cool isn’t it?

Virtual terminals and jobs

In many versions of GNU/Linux, they have things called “virtual terminals”. A virtual terminal allows you to simulate the experience of being on an old fashioned monochrome terminal. The kind they had before all this new-fangled window stuff was around. This is a necessary safety blanket for old programmers who miss the simplicity of it all. The great thing about having these virtual terminals is that if your graphical user interface hangs, you can switch to a virtual terminal and kill the hung window system. It is just another process after all.

How do you run a program from a terminal?

To get to a virtual terminal, you need to type at the same time the control key, the Alt key, and the F1 key. On my system I have six virtual terminals that I get to by typing Ctrl + Alt + F1 to Ctrl + Alt + F6. Pressing Ctrl + Alt + F7 returns me to the window system. This won’t always work though. My other computer has no virtual terminals at all, so you will just have to try it and see.

What if you want to start a process and it isn’t in your menu? How do you run a program from a terminal?

If you’ve just downloaded a program, and you are in the same directory as it, you can type ./filenameoftheprogram and it will run. If you don’t know where the program is that you want to run, you can find its location by typing whereis. So if Abiword wasn’t on my menu, but I knew that it was on my system and I wanted to run it, I could type:

rosalyn@onizuka:~$ whereis abiword
abiword: /usr/bin/abiword /usr/share/man/man1/abiword.1.gz

The computer gives me two locations for Abiword. The first listing is the actual program. The second listing is for the program’s manual pages.Simply typing /usr/bin/abiword at the command line will start the program, but here is a case where a terminal is like a calculator. The prompt will vanish from the terminal, and won’t return until you have closed the program.

To run a process from a terminal and still get the prompt back, you have to run it in the background. to do that put an ampersand at the end of the command.

rosalyn@onizuka:~$ /usr/bin/abiword&
[1] 12620
rosalyn@onizuka:~$   

It gives me a job number and then returns the prompt so I can do something else. The second number on the line tells me the process ID, so I could kill the program if I so desired by typing:

rosalyn@onizuka:~$ kill 12620
[1]+  Terminated              /usr/bin/abiword
rosalyn@onizuka:~$  

If I close the terminal that I started it in, Abiword will close, and I will really wish that I had saved my data

When you run a program from a terminal it is called a job and that terminal will number the jobs it is running sequentially. If I restart Abiword, and then type the command jobs, it returns the following:

rosalyn@onizuka:~$ jobs
[1]+  Running                 /usr/bin/abiword &
rosalyn@onizuka:~$

So I don’t have to remember the long process ID. If I want to end this job, I just call it into the foreground with the command fg and the job number.

rosalyn@onizuka:~$ fg 1
/usr/bin/abiword

Then I can close it using the keyboard command Ctrl + C. The command fg brings a background program to the foreground, and the command bg runs a stopped job in the background. fg and bg are the terminal equivalent of tabbed browsing. This kind of thing was really hot stuff before multiple windows, but they are rarely used today. Heck, even multiple virtual terminals means that you can run processes in different terminals at the same time, so why bother?

If you have lots of small jobs that you want to oversee. For example, if you were running ten or twelve mathematical calculation programs, you could start each of them and then leave them in an open terminal while you go off to do something else. You could check their status by typing jobs from time to time, or even run top in the window for constant updates on their status.

One thing that you must remember about jobs is that they are tied to the terminal. Closing the terminal closes all of the jobs that you start in it. Therefore if I am typing a document in Abiword and I close the terminal that I started it in, Abiword will close, and I will really wish that I had saved my data.

Fuser and devices

Now, sometimes a process is halted because it is waiting for a device to finish. Devices are hardware attached to a computer such as a CDROM or a printer. Even the hard drive is a device. You can use the command fuser to see what process is using a device.

If I am playing music using the Kaffeine media player, then the device cdrom should be busy. If I type fuser /dev/cdrom it will give me the process ID being used by CDROM.

rosalyn@onizuka:~$ fuser /dev/cdrom
/dev/cdrom:          15562
rosalyn@onizuka:~$           

I can ask ps what program owns this PID by typing ps and the PID:

rosalyn@onizuka:~$ ps 15562
  PID TTY      STAT   TIME COMMAND
15562 ?        S      0:02 kaffeine
rosalyn@onizuka:~$                

Then I can kill this program using this program ID.

rosalyn@onizuka:~$ kill 15562

And yes, by looking at the list of options, I could learn how to find who has control of the device and kill it all on one line.

rosalyn@onizuka:~$ fuser -k /dev/cdrom
/dev/cdrom:          15741

What is all this business about /dev/cdrom? In Unix-like operating systems, a device is referred to as if it were in a directory. Your cdrom may not be called /dev/cdrom like mine is. It may be /dev/cdrom0 or /dev/dvd. Since every system has different hardware, each /dev has a unique collection of files. But devices are a complete topic on their own.

Take control of your processes with the command line, and never be afraid of your software again

Processes are how your computer runs. Understanding processes helps you understand your computer, so open a terminal and type top. Leave it running and see what your system is doing from moment to moment. If you are curious about what a command does, type whatis and the command name. Remember, you run the computer it doesn’t run you. Take control of your processes with the command line, and never be afraid of your software again.

Category: 
License: 

Comments

clievers's picture
Submitted by clievers on

Very nice article.
In the part about killing processes, what if "Ctrl+C", "Ctrl+X", "kill 13247" and "kill -9 13247" don't work? I've had this come up a few times where I cannot seem to get rid of a process this way. Then you just have to really wait on it to finish or respond. (And this is attempted as root). Is there even another type of command to run?
Thanks.
------
let's all play nice!

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

Did you try CTRL-Z? I've had a few rare cases where it didn't work to kill the process, but it worked to suspend it (with CTRL-Z). Now you usually can kill it, but there may be cases where even this won't work.

Cases where the "kill -KILL" (equivalent to "kill -9") won't work usually occurs because the program is accessing a network drive that has gone offline, such as an NFS share. In those cases, the only way to kill the program might be to reboot the computer, or at least bring it into single-user mode and back, so that all network shares are forcibly unmounted.

Rosalyn Hunter's picture

Other than Slay, I can't think of a more powerful way to kill processes right now.
If it is that persistent, I usually reboot. Sometimes that is the best way to solve hardware dependent problems.

-Rosalyn

clievers's picture
Submitted by clievers on

Ok, thanks. Rebooting isn't usually an option as it's a server (usually). But yeah, it's not so often though, just once in a while.

------
let's all play nice!

Conserned Admin's picture
Submitted by Conserned Admin (not verified) on

For what it is worth, one should NEVER skip directly from kill (-15) to kill -9.

The process is:

kill $PID
wait a few seconds
kill $PID
wait a few seconds
kill -2 $PID
wait a few seconds
kill -1 $PID
wait a few seconds
try to figure out why the process is not dying correctly
kill -9 $PID

One should never ``kill -9'' a process unless you have found that it is trying to close a file descriptor on a non-responsive filesystem or other type of issue that is actually causing it to not clean up properly.

If the same process is frequently requiring a ``kill -9'' then one should figure out why it is not dying correctly and switch to a different program if it can not be corrected as the process is experiencing some serious issues.

At one time there was a ``Useless use of kill -9'' award given out on Usenet for those System Admins that do not know what they are doing. As *NIX is gaining more and more popularity we are seeing many more people just using kill -9 like it should be default. There is a reason that a process should be given a SIGTERM, SIGINT then SIGHUP. The reason being that programs are written to where they catch these signals and perform cleanup processes. A SIGTERM will typically tell the program that the user wishes for it to go ahead and close all file descriptors after telling it's children(if child processes have been forked) to close up shop. A SIGINT is then used to Interrupt the program from whatever it is doing and close up shop. A SIGHUP, commonly rebound to re-read the configuration file, is a Terminal Line Hangup which should, by default, tell the program to not wait for children to respond via their pipes and just close the file descriptors and die. The evil SIGKILL tells the process to just die and not worry about what it might have been doing. SIGKILL can leave ZOMBIE child processes and ghost logins.

eg: If you were to ``sleep 9999& kill -9 $$'' then you may notice that you will often have a ghost login AND the sleep process will still be alive after your shell is dead. If, instead, you were to issue that as ``sleep 9999& kill -1 $$'' then you will find that there is no ghost login and the sleep process should have been reaped by your shell as it exited cleanly.

On a side note: one does not have to quit from ``top'' in order to kill a process. Simply pressing 'k' while viewing top will prompt you for the PID(and signal depending on the OS and distro.) One can perform many actions from within ``top'', just press 'h' to see the different shortcuts.

Rosalyn Hunter's picture

Thanks for your more detailed insight into Killing processes.
I wonder what Xkill does?

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

If I want to tell my computer to show me a process, could I actually enter the command SHOW PROCESS. Or how about the whole system, like SHOW SYSTEM? In a cluster, can I just enter SHOW CLUSTER? How about a plain HELP? Can this be done or are computers today as primitive as they were in the late 60s, when people had to deal with 2-letter commands like "ps"?
Hey, I asked my system manager these questions, and she said on Linux the HELP command is called woman. When I replied that his is weird, she said progress was made when an operating system called MSDOS was introduced which had at least the HELP command. Now, how about the rest?

Rosalyn Hunter's picture

I wouldn't really call something primitive just because it has a two letter command.

Anyway, if you really want specialized command names, you can always try scripting them. You can make short files called scripts that when you run them by typing their name, initiate a long command for you. In that case you could do ps with lots of options added and formatted the way you like it when you type SHOWPROCESSES. I don't think you can have a space in the command though.

About the woman command.

I see no sign of it. I think it must be a joke.

Anyway, thanks everyone for the comments. If you find any other good ones. Post.

Thanks Rosalyn

Edzilla's picture
Submitted by Edzilla (not verified) on

You don't even have to script anything, you can simply alias them.
So if you want SHOWPROCESS to do "ps aux" in bash, you type "alias SHOWPROCESS ps aux".
Now, in this terminal, every time you'll type SHOWPROCESS, it will do "ps aux".
If you want to have that possibility in every terminal you open from now on, just add "alias SHOWPROCESS ps aux" to the file .bashrc in your account.
Also, short command names are still used of efficiency. It's a LOT faster to just type "ps" or "ps aux", than to type SHOWPROCESS.
And for the "help" command in linux/unix, either you misunderstood, or your are making a bad joke. The command is "man", as in manual, followed by the command you want help with.
For example, you could type "man ps", and it would give you an explanation about the use of "ps", it's options, it's peculiarities...

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

#!/bin/bash
if [ $1 == "PROCESSES"]
then
ps aux
fi

put that in a file named SHOW in /usr/local/bin and chmod +x /usr/local/bin/SHOW
then you can run SHOW PROCESSES
but it is faster to write ps aux than writing SHOW PROCESSES

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

'help' works on my system as does 'help ls' ('help' basically does 'man help' and since 'help' is a hardlink to 'man', 'help ls' is the same as 'man ls'). Of course this is BSD *nix, not Linux where the default bloated ass shell (bash) has a built-in very unhelpful 'help' command.

And yet, Linux is the predominant open source operating system.

mattflaschen's picture

I would add one more useful command to the list: killall. killall lets you kill a program directly if you know the name of the binary. For example:

killall akregator

will kill all instances of Akregator.

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

xkill turns your mouse pointer into a skull and crossbones, whatever window you left click on gets "run through" so to speak. Right click to return to a normal mouse pointer.

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

If kill and slay dont work, there is always SysRQ. That strange little button sharing "print screen" is actually an access to several very powerful, low level kernel interrupts. The good news is that SysRQ commands cannot be denied by the system. The bad news is that it must be enabled both during compile, and in kernel.sysrq additionally, the potential for harm is much greater than that of kill -9, but IF your server has it enabled, and all else fails, its worth a try.

Rosalyn Hunter's picture

Wow!
I never heard of SysRQ. I'm gonna have to look that up.

Sounds like the tip of a long series of programmer tools or something.
Thanks for the comment.

-Rosalyn

Rosalyn Hunter's picture

I found something about sysRQ. It's really old. I felt embarrased that I didn't know it when it is printed on my own keyboard!

I found a really nice wikipedia page on this function.

http://en.wikipedia.org/wiki/SysRq

Mitch Meyran's picture

There's no shame in not knowing about ALL those PC BIOS level interrupts - I'm not sure they're even all properly referenced (except in those old 1979 Intel datasheets...)
Those keys shouldn't work with:
- PPC Macs
- Intel Macs (use EFI, not BIOS)
- Alphas
Or do they?
---
A computer is like air conditioning: it becomes useless when you open windows.

Don Crowder  AKA eldergeek's picture

I'm still using Debian but now it's Etch instead of Sarge and I'm happier than ever with it. Etch is substantially more user friendly than Sarge and still works beautifully on older hardware.

I love the way you write. I read Part II all the way through without my eyes glazing over. I doubt if any of it will stick, because that's how my strange brain works, but the first time a process hangs up and can't be shut down I'll remember this tutorial, revisit it (even if I have to change computers and google for it), read it again and apply the information. Then I'll remember it.

I hope you'll continue this series. I want the book when it's printed, or, if it's an eBook I'll buy it and print it myself.

I'm still a Wannabe Linux Geek (and still in training)

Don Crowder

Felipe Alvarez's picture

Instead of 'ps' use 'pgrep -l '. Example, try 'pgrep -l firefox' when running firefox. You will see the PID as well as the name of the program (ie. firefox).

Instead of wasting time remembering stupid numbers, use pkill . Example, with firefox running try typing pkill firefox. This will TERM-inate (signal 15) firefox, without having to remember stupid numbers.

(YMMV. Works on opensuse. I haven't tried this on other distros)

wow movies's picture

I did not know about pgrep (so thanks for that tip). But when I read your post I did 'man pgrep' and it comes up with a man page for pgrep _and_ pkill - so your 'most used' would be shorter as 'pkill firefox'.

vall3yman's picture
Submitted by vall3yman (not verified) on

fuser -k /path/to/program

this will kill the program that you named along with any forks that the program may have initiated.

vall3yman's picture
Submitted by vall3yman (not verified) on

fuser -k `which gcc`

kills every instance and any forks

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

This guide is good I guess but to REALLY kill some stuff, just type:
[dangerous command that could destroy your system, edited]

Tony Mobily's picture

Hi,

This comment shows that it's a good idea to moderate comments, ALL the time, no matter how many you have.
I just cannot believe some people.

Anonymous user: I hope you realise that your IP address was recorded on the server.

Merc.

mscman's picture
Submitted by mscman (not verified) on

And people wonder why the Linux community has such a bad reputation. Thanks to people like you, new users are afraid to take advice from us seasoned users. Hopefully nobody used that command and lost data.

Tony Mobily's picture

Hi,

Well, I reported the hell out of him.
He was from a .mil domain (!). So, hopefully somebody will get seriously told off about it.

Luckily, the community also "works" :-D

Bye!

Merc.

devlin's picture

This article while helpful actually made the process more difficult than it has to be.

There is a nice little command called "xkill" that works easily. You either bring up a run dialog box or open a terminal program, then just type "xkill" and hit enter. You will notice your cursor has changed to normally a skull and crossbones, click on the frozen application to be killed and left click on it. It should die very quickly. Done.

I only use the standard "kill" command if I am running apps from the command line ( I'm rarely ever there...) and one froze.

Terry Hancock's picture

1) This is an article about the command line, and xkill is an x application (albeit a small one).

2) Sometimes there is no window to xkill.

3) Sometimes there is a window, but your xserver is locked up so the mouse won't do anything or you can't get the application menu to come up (And yes, I have encountered systems where X is locked up, but virtual terminal switching works, and killing the offending process frees up the X session).

4) Sometimes the whole console is locked up, but you can remote login via SSH and kill the offending process to fix things (i.e. from another computer). I suppose it's a bit counter-intuitive that SSH often works even when the console is completely locked up, but it is often true.

John788878's picture
Submitted by John788878 (not verified) on

Hi Rosalyn,

Very nice written article! Thank You!

By the way if anyone is interested, most of these commands will also work in a terminal window on OSX, which uses BSD.

I am not sure why people are afraid of the command line. Once you get used to it, it's really great. Last night I installed a new application on my Xubuntu box. I could have used the GUI installer, but it was easier and quicker to use apt-get.

Peter (not the user on this page)'s picture
Submitted by Peter (not the ... (not verified) on

Kill -9 no more cpu time
kill -9 and your process is mine

lews99therin's picture
Submitted by lews99therin (not verified) on

Hi,
Enjoyed your article! Thanks

Ryan Cartwright's picture

But in my mind’s eye I can hear some veteran command line user out there scoffing. “Ha!” he says, “I could do all of that in one line.”...

Quite an amazing eye - perhaps that should've been "mind's ear" ;o)

Good article though. Well done.

Ryan

Author information

Rosalyn Hunter's picture

Biography

Rosalyn Hunter has been on the internet since before the web was created. Born into a family of instructors, she has made it her life's goal to teach others about the important things in life, such as how to type kill -9 when a process is dead. She lives in a little house on the prairie in the American West with her husband, her three beautiful children, a cat and a dog.