5 Ways to Kill a Linux Program

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

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

Use the 'kill' Command

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.

grep and kill in linux

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

kill pid

For example:

kill 7317

If, after running the kill command, the application 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, enter xkill into the run-command window.

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

xkill window

Kill Linux Applications Using the 'top' Command

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

To kill a process within the top interface, press k and enter the process id next to the application you wish to close. The top command 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).

top with sigkill

Linux supports signals that instruct a process to do something. Some 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 clean up gracefully if 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 initiated 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 accepts the name of the process as well, so you can type:

pkill firefox

This is fine if you only have one instance of the application but is 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

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 the item and choose either end process or kill process. These options send the respective signal to the process.

gnome system monitor