How to Kill a Process On Any Linux Distribution

If you are a new Linux user of any distribution, you probably don’t know how to use one of the essential commands, which is the one that helps us to terminate running processes.

The operating systems based on Unix incorporate the Kill command, useful to kill those processes that have been stuck or that we don’t want to run anymore without having to restart our computer or server.

The Kill command sends different types of signals that allow terminating processes or groups of processes. If no signal type is specified, the TERM signal will be sent, which is the default option.

Note for intermediate users: The command can be external (located in /bin/kill) or internal (more recent shells) depending on the type of Linux shell. In any case, its use is very similar.

KILL Command Signal Types

The most common signal types are the following

  • SIGHUP: It will be used if the console doesn’t respond or if control over the process has been lost. This signal is used to reload the configuration files of the process, as well as the possible log files of the same.
  • SIGKILL: Signal to stop a process. It is the last hope to terminate a process when it doesn’t respond. It’s not a clean way to end a process, and this is why no data will be backed.
  • SIGTERM: It is the fastest way to close a process. It is the default signal.

Permissions Required To Terminate a Process

The permissions are the following:

  • You can only terminate your own processes.
  • The root user will be able to kill all processes, system process and from any other users.

KILL Command Syntax

The syntax is the following:

kill [options] [signal] PID

If you want to terminate several processes at the same time:

kill [options] [signal] PID1, PID2 ...

As you can see, first you need to type the command name, then its parameters, then the type of signal and finally the PID or the PID of the process that you want to terminate.

How-To Kill Command Examples

Let’s see an example when you want to kill the Apache httpd process:

Step # 1: Find the PID of the process

The first thing you have to do when you want to terminate any process is to find their PID. For this, you can use the ps or pidof commands.

pidof httpd

That command will give you the PID, on this case is 22298, which is the Process Identifier, although you could also have as a result of a list of identifiers since the process could have several instances.

You can also run the following command to find the PID:

ps aux | grep httpd

Step # 2:  Kill Process using PID

The PID 22298 is the one assigned to the httpd process. To terminate the process and close the Apache server, you need to pass your PID:

kill 22298

This will end the process with the PID 22298, something you can check if you use the pidof command or the ps command again :

pidof httpd

If we don’t specify any signal. The signal SIGTERM (-15) will be used by default, so the following commands are equal:

kill -15 22298
kill -SIGTERM 22298

If the SIGTERM signal (-15) isn’t enough, as for example when the Apache sockets are open, we can use the signal SIGKILL (-9):

kill -9 22298
kill -SIGKILL 22298

This signal guarantees that the process will be terminated, interrupting any task in execution. If Apache has several running processes we can eliminate them all at once:

kill -9 22298 222300 222302
kill -15 22298 222300 222302

Killall Command

In Linux, we also have the killall command to kill processes by name, although this Unix command has another function. For example:

killall -15 httpd

This will close all instances of Apache’s httpd process on Linux. However, in Unix, this command will terminate all processes, so it will be better not to get confused when using it.

Do you know any other way to kill processes on Linux or get into troubles using any of the commands above? Let me know in the comments.

It might be interesting

Nokia 5610 XpressMusic: A real music powerhouse

With its nice slide opening casing, the stylish Nokia 5610XpressMusic phone belongs to the 3rd Gen of music phones. Its easy to use and high quality music features will definitely win the hearts of music lovers.

Xiaomi will unveil the Civi 1S smartphone on April 21

Earlier it became known that the company Xiaomi in the near future will present a new smartphone called Civi 1S. Today in the social network Weibo appeared the official teaser of the novelty, revealing the date of its presentation.

UK: The 10th most developed country in info tech

The annual ICT Development Index, which was compiled by the International Telecommunication Union, has ranked UK as the 10th most developed country in the world of communication and information technology, but this position is not quite remarkable as it lags behind other European neighbors as the prices of fast speed internet are quite higher in the UK.

How Can You Go about Higher Holiday Savings?

This holiday season you have the greater option to make and save even more money than any other time. You can shop in a fast pace and even get security regarding your different stores across the web.