www.LinuxHowtos.org

edit this article

Killing Processes

This tip shows you some interesting ways to kill stubborn processes. Never let it be said that you can't kill a process again! The first way is the old boring way that most people probably use. Use the command ps aux, look through the process list until you find the PID you want and issue the kill command. How tedious!

Alternatively, try using the killall command which will automatically kill a program based on its name.

Code Listing 1

# killall mozilla-bin

But what if you only know part of the name? Well, you could combine ps with grep, kill and awk to produce something like this.

Code Listing 2

# ps aux | grep mozilla | awk '{print $2}' | xargs kill

But, there's a far simpler way. Enter pkill and the closely related pgrep. These commands are part of the sys-apps/procps package and are designed to search for (or kill) running processes. So the previous command could be replaced with the following:

Code Listing 3

# pkill mozilla

Note: To list the PIDs instead of killing them, use pgrep.

Finally, what if you have a runaway process hogging /dev/dsp, or some other file/socket? You can use fuser, which displays the PIDs of process using a specified file or filesystem. Or give it the -k option, like this, and you can easily kill those processes:

Code Listing 4

# fuser -k /dev/dsp

From http://www.gentoo.org/news/en/gwn/20030707-newsletter.xml


rate this article:
current rating: average rating: 1.3 (178 votes) (1=very good 6=terrible)
Your rating:
Very good (1) Good (2) ok (3) average (4) bad (5) terrible (6)

back