How to kill a process in Gnu / Linux

Server farm

One of the tasks that the Windows user knows best is to terminate a process or close an application unexpectedly. These types of operations are common on Windows systems, but unfortunately, they are not exclusive to the operating system: it also exists on Gnu / Linux.

But, even in Gnu / Linux, the way to deal with these problems is more efficient than in proprietary operating systems. In Gnu / Linux there are three commands whose purpose is to kill a process or terminate an application, They are called Kill, PKill, and Killall.

But before using them, we must first know or know the PID of the process. The PID is a process identification number. It is unique and they do not have more than a single process, it works as if it were the DNI or passport number of a person, it is something unique and unrepeatable at that time.

Knowing the PID of a process is simple, we can find it by writing the command "htop" in the terminal or directly writing "ps -A" in the terminal.

In any case, it will show us all the processes, the programs they use and the PID of each process. Now, to kill a process we have to write the following:

kill -9 PID

Instead of PID we will use the process code. The variable "-9" indicates that we want to kill the process. If we change it to "-15", we indicate that we want the process to finish and if we use "-1" we suspend it.

Kill is a command that helps us kill a process but it will only work on the processes that we have created as a user, we will not be able to kill processes from other users or from the system.

The Pkill command is similar to Kill. But unlike the previous one, PKill allows us to kill the process or the program using the name, that is, we do not need to use the PID of the program. An example of use would be:

PKill mysql

The Killall command is more powerful and effective than the previous commands but it is also more dangerous. Killall not only kills the process but also the program or function, killing all the processes that depend on that program. An example of using Killall is

killall firefox

Conclusion

To kill a process, any of the above commands are used, but not all of them will adapt perfectly to our situation. Depending on our need or our problem we have to use Kill, PKill or Killall. I personally recommend use PKill, because it is simpler and faster. Although if we have a serious problem, the Killall command can be very useful Don't you think so?


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   someone said

    And if you want to kill a program that is on the screen, you can use xkill.
    Example, you open the calculator and it gets stuck (don't be scared, it's just an example, that will never happen: D)
    So in the command console we write xkill
    The mouse cursor will turn into a kind of "x" and we click with the mouse on the calculator. It's like shoot to kill: D
    Greetings.

  2.   Arrakix. said

    I am not a connoisseur but it is easier on the »Mate» desktop with «System Monitor» especially because you do not have to run as administrator.

    # killall qbittorrent

    With System Monitor you kill him and you are so hot.

    1.    someone said

      If for some strange reason the screen is blocked and you cannot interact, then it will not work to open the system monitor because it is blocked. You can open another session with ctrl + alt + F1..F12 and there you can use the console commands indicated above.
      Or connect via ssh from any other computer / device.

  3.   javimg said

    All these methods are valid and effective.
    Personally I prefer Xkill…. The quickest thing is to create a launcher for this command and place it in the panel, this is the way I use in Xunbuntu 14.04, my usual distro, when something gets caught.

    I hope this contribution is helpful and complete the info provided in this post.

    Greetings and happy holidays.