Computer help - file server

[ Blog ] - [ File Server ] - [ Удаленная компьютерная помощь ]

We have previously written about how to kill a non-responsive program in Windows (see our post, How to Kill a Program using the Command Line). If you are an Ubuntu user, there is a similar method of terminating non-responsive programs.

Instead of logging out or rebooting to end the program, there are a couple of commands you can use in a Terminal window to kill programs that are not responding. There is also a graphical way to kill programs using the System Monitor.

NOTE: The first two methods work in other Linux distributions as well. The commands used in these methods are general Linux commands. The System Monitor, discussed in the third method, is specific to the Gnome desktop environment, but not to Ubuntu. If you are running Gnome in a different Linux distribution, you should have access to the System Monitor. There are equivalent tools in other desktop environments, such as KSysGuard in KDE. Use the killall Command in the Terminal Window

To use the killall command to kill a program, open a Terminal window by selecting Accessories | Terminal from the Applications menu.

NOTE: You can also open a Terminal window by pressing Alt + F2 to access the Run Application dialog box. Enter “gnome-terminal” (without the quotes) in the edit box and click Run.

To view a list of running processes, enter the following text at the prompt and press Enter. $ ps -A

A list of processes displays with their associated PIDs (process IDs). Look through the list to find the name of the process that matches the program you want to kill. The program is most likely listed towards the end of the list, where the programs run most recently are displayed. For our example, we used Firefox as the process to kill. The firefox-bin process is the one to kill, with a PID of 5039.

To kill a process using its PID, enter the “killall” command (without the quotes) at the prompt, followed by a space, and then the corresponding PID from the generated list. Press Enter.

Killing a process using its PID does not always work. If it doesn`t work for you, you can use the process name to kill the process. To do this, enter the “killall” command (without the quotes) at the prompt, followed by a space, and then the corresponding process name from the generated list. For Firefox, the process name is firefox-bin.

NOTE: Killing a program using its process name, only works for executable files (i.e., runnable programs) that are kept open during execution. Programs that run in the background cannot be killed using the process name.

Using killall without specifying a signal as a parameter, as in the examples above, allows the program to clean up before terminating, using the SIGTERM signal by default. If this does not work, you can specify the –9 (SIGKILL) signal. This forces the program to terminate and does not allow it to clean up before doing so. It is recommended that you try killing a program without the –9 signal first to give it a chance to exit cleanly.

If you need to use the -9 signal, enter it between the “killall” command and the name of the process (or the PID) with a space after killall and after the -9 signal, as shown below. $ killall -9 firefox-bin

NOTE: There is one dash before the 9.

To close the Terminal window, type exit at the prompt and press Enter.

Use the xkill Command on a Program’s Window

You can also run the xkill command in a Terminal window. This command allows you to kill any program just by clicking on its window.

To use the xkill command, open a Terminal window as discussed earlier in this post. Enter “xkill” (without the quotes) at the prompt and press Enter. The cursor turns into an X. To kill a program, simply click anywhere in the program’s window, or on the title bar of the window.

Use the Gnome System Monitor

If you are using the Gnome desktop environment, you can use a graphical tool, called System Monitor, to kill a program. Select Administration | System Monitor from the System menu. In newer versions of Ubuntu, you will need to click on Activities and type in system monitor.

NOTE: You can also open the System Monitor by pressing Alt + F2 to open the Run Application dialog box. Enter “gnome-system-monitor” (without the quotes) in the edit box and click Run.

On the System Monitor dialog box, click the Processes tab. A list of all running processes displays. To kill a program, find the program`s process in the list (firefox-bin for Firefox) and select it. Right-click on the process and select Kill Process from the popup menu.

A confirmation dialog box displays. If you are sure you want to kill the selected process, click Kill Process.

To close the System Monitor, select Quit from the Monitor menu.

NOTE: If you need to kill a program that is running with root privileges, use one of the first two methods of killing a program and type “sudo” (without the quotes) before the killall command or the xkill command. Enjoy!