5 Ways to Kill a Linux Program

Tame non-resopnsive apps with a variety of distribution-agnostic technqiues

Girl using laptop

Caiaimage / Robert Daly / Getty Images 

Terminate non-responsive applications in Linux—a process called force quitting—through one of five common methods.

Use the 'kill' Command

grep and kill in linux

The first method is to use the ps and kill commands. The advantage of using this method is that it works 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 7317

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'

xkill window

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, enter xkill into the run-command window.

A crosshair appears on the screen. Click the window you want to kill.

Kill Linux Applications Using the 'top' Command

top with sigkill

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 k and enter the process id next to the application you wish to close. Top solicits a specific signal to send; in most cases, enter 15 (to request the process to gracefully terminate) or 9 (to immediately kill the process).

Linux Signals

Linux supports signals that instruct a process to do something. Some of the most common signals used in a shell session include:

  • SIGINT 2: Interrupts the process, equivalent to Ctrl+C.
  • SIGQUIT 3: Quits the process gracefully if possible, leaving a core dump to aid in debugging. Invoked with Ctrl+\.
  • SIGKILL 9: Kills the process immediately without allowing the process to gracefully perform shutdown or cleanup operations.
  • SIGTERM 15: Terminates a process. The process force quits, but if it can cleanup gracefully, the system permits it.
  • SIGCONT 16: Continue executing after stopped by SIGSTOP.
  • SIGSTOP 19: Stop the process, with the intent that it'll later be resumed with SIGCONT.
  • SIGTSTP 20: Pauses a process. Usually initiatied by Ctrl+Z.

The process name or process number works with the kill command to send a specific signal to a process. For example, kill -9 1234 sends SIGKILL to process 1234.

Use 'pgrep' and 'pkill' to Kill Applications

The ps-and-kill method used earlier works on all Linux based systems. However, many Linux systems offer a shortcut method for performing the same task using pgrep and pkill.

Pgrep evaluates the name of a process and it returns the process ID.

For example:

pgrep firefox

Enter the returned process ID into pkill as follows:

pkill 1234

The pkill command 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 open several Firefox windows and you just want to kill one. Xkill is much more useful in this situation.

Kill Applications Using System Monitor

gnome system monitor

The GNOME desktop environment offers a System Monitor tool to kill unresponsive programs.

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. These options send the respective signal to the process.