Howto kill a process in linux

If you have a program that using a lot of your computers resources or not responding it can be necessary to kill it the hard way, here are some ways to do that.

  • With the kill command.
    If you know the PID (every process in your system has a uniq number, that's the PID, shortcut for Process IDentifier ) of the process, you can send it a signal with the kill command. There are several signals you can send and depending on the process it will be terminated. Some of the most common signals to end a process are SIGHUP, SIGINT, SIGTERM and SIGKILL. SIGTERM is the signal you should try first and if that don't work use SIGKILL. To send a signal to the process with the kill command type this in a console: "kill -SIGNAL PID" where you replacing SIGNAL with a signal and PID with the processes process identifier number. To find out the PID of a process you can use one of the "pidof", "pgrep", "top", or "ps" command in a console.

  • With the pkill command.
    pkill is a command similar to kill in that it will send signals to a process to terminate it, the difference to kill is that you don't need know it's PID, instead you terminate a process based on its name. If you type "pkill firefox" in a console pkill will terminate all processes with firefox in it's name. pkill will by default send a SIGTERM signal but that can be changed. WARNING! be careful as pkill will terminate ALL your processes that have what you specified in its name.

  • With the xkill command.
    In X-Windows you can kill processes that have a window with the xkill command. Running xkill will get you a mouse cursor of a death skull and if you click with it on a window it will be terminated. In KDE pressing the Ctrl+Alt+Esc keyboard shortcut will run the xkill command.

  • With KDE.
    In a default KDE setup you can press Ctrl+Esc keyboard shortcut to open a window with all processes listed and from where you can right click on one and choose a signal to send to it.
  • With SysRq.
    With the SysRq keyboard key you can make the kernel do some really powerful stuff with you system. Type "cat /proc/sys/kernel/sysrq" in a console to see if SysRq it is enabled, if the result is "1" it's enabled or else you can activate it by running one of this command as root "echo 1 > /proc/sys/kernel/sysrq" or with the sysctl command like this "sysctl -w kernel.sysrq=1". By pressing any of the keyboard shortcuts below you will tell the kernel to do what's described in the parentheses.

    Alt+SysRq+r (The r stands for put keyboard in raw mode)
    Alt+SysRq+s (The s for sync the disk)
    Alt+SysRq+e (The e for terminate all processes)
    Alt+SysRq+i (The i for kill all processes)
    Alt+SysRq+u (The u for remount all file systems read only)
    Alt+SysRq+b (The b for reboot the system)
Beware that using some of these SysRq commands it is very dangerous as it will kill all processes in your system and you will loose all data that are not saved. Use it at your own risk and only as a last option.

Good luck killing your system.

Inga kommentarer: