Please feel free to email me with any questions at with "blog" as the subject.

Search my blog:

Loading...

Friday, 3 September 2010

Kill unresponsive or misbehaving processes.

Anyone using linux should know how to do this as it comes in useful more often than you can imagine.

There are multiple ways to do it.

I will post the most common CLI methods.


Firstly the kill command.

You can use kill to terminate a process that is being run by you, or if logged in as root or using sudo you can kill a program run by anybody.

kill has many uses but I will only post the most simple one.

To kill a process using kill you must first have its PID (process ID).

To get this you can use the command pidof.

You may then kill the process.

For instance;

if

bash$ pidof [process]

gives [output]

then you can

bash$ kill [output]

which will end process [process]

For instance:

bash$ pidof rhythmbox
2531
bash$ kill 2531

would be used to kill rhythmbox

This is a rather long method however.



This is where the comand killall comes in.

You do not need to use the PID when using killall.
You can simply use:

bash$ killall [process]

and the process will be killed.

For instance:

bash$ killall rhythmbox



There is another option which lets you see if a program is misbehaving and kill it called Top.

When in a shell simply type:

bash$ top

You get a CLI task manager which shows PID's and cpu usage etc.

Example:

bash$ top

gives me this:


You can kill a process by pressing 'k' then typing in the PID listed for it.

eg:

PID to kill: 2531

it will ask you:

Kill PID 2531 with signal [15]:

and you can simply press enter to kill it or ^C (ctrl+C) to exit the program.