5 Ways To Kill A Linux Program

Kill Linux Programs
Kill Linux Programs.

This article will show you various ways to kill an application within Linux.

Imagine you have Firefox running and for whatever reason a dodgy Flash script has left your browser not responding. What would you do to close the program?

Within Linux there are a multitude of ways to kill any application. This guide will show you 5 of them.

Kill Linux Applications Using The Kill Command

The first method is to use the ps and kill commands.

The advantage of using this method is that it will work on all Linux systems.

The kill command needs to know the process ID of the application you need to kill and that is where ps comes in.

ps -ef | grep firefox

The ps command lists all the running processes on your computer. The -ef switches provide a full format listing. Another way to get the list of processes is to run the top command.

Now that you have the process id you can simply run the kill command:

kill pid

For example:

kill 1234

If after running the kill command the application still doesn't die you can force it by using the -9 switch as follows:

kill -9 1234

Kill Linux Applications Using XKill

A simpler way of killing graphical applications is to use the XKill command.

All you have to do is either type xkill into a terminal window or if your desktop environment includes a run command feature enter xkill into the run command window.

A cross hair will appear on the screen.

Now click on the window you want to kill.

Kill Linux Applications Using The Top Command

The Linux top command provides a terminal task manager which lists all of the running processes on the computer.

To kill a process within the top interface simply press the 'k' key and enter the process id next to the application you wish to close.

Use PGrep and PKill To Kill Applications

The ps and kill method used earlier is fine and is guaranteed to work on all Linux based systems.

Many Linux systems have a shortcut method for performing the same task using PGrep and PKill.

PGrep lets you enter the name of a process and it returns the process ID.

For example:

pgrep firefox

You can now plug the returned process ID into pkill as follows:

pkill 1234

Wait though. It is actually simpler than that. The PKill command can actually accept the name of the process as well so you can simply type:

pkill firefox

This is fine if you only have one instance of the application but is a little bit less useful if you have multiple Firefox windows open and you just want to kill one. XKill is much more useful in this situation.

Kill Applications Using System Monitor

If you are using the GNOME desktop environment you can use the System Monitor tool to kill unresponsive programs.

Simply bring up the activities window and type "System Monitor" into the search box.

Click on the icon and a graphical task manager will appear.

Scroll down the list of running processes and find the application you wish to close. Right-click on the item and choose either "end process" or "kill process".

"End Process" tries a nice little nudge along the lines of "please would you mind shutting down" whereas the "Kill Process" option goes for the unceremonious "get off my screen, now".

Was this page helpful?