Kill Command in Linux - MS TV Life.COM

Kill Command in Linux

Kill Command in Linux

We hope this post helped you to find out  Kill Command in Linux

Linux is a good and superior working system, however it isn’t good. On occasion, some purposes could begin behaving erratically and turn into unresponsive or begin consuming a number of system assets. Unresponsive purposes can’t be restarted as a result of the unique utility course of by no means shuts down utterly. The one answer is to both restart the system or kill the appliance course of.

There are a number of utilities that will let you terminate errant processes with kill the being essentially the most generally used.

kill Command #

kill is a shell builtin in most Bourne-derived shells akin to Bash and Zsh. The command conduct is barely totally different between the shells and the standalone /bin/kill executable.

Use the type command to show all areas in your system containing kill:

type -a kill
kill is a shell builtin
kill is /bin/kill

The output above tells that the shell builtin has precedence over the standalone executable, and it’s used everytime you sort kill. If you wish to use the binary, sort the complete path to the file /bin/kill. On this article, we are going to use the Bash builtin.

The syntax of the kill command takes the next type:

The kill command sends a sign to specified processes or course of teams, inflicting them to behave in line with the sign. When the sign will not be specified, it defaults to -15 (-TERM).

Essentially the most generally used alerts are:

  • 1 (HUP) – Reload a course of.
  • 9 (KILL) – Kill a course of.
  • 15 (TERM) – Gracefully cease a course of.

To get an inventory of all accessible alerts, invoke the command with the -l choice:

kill -l
Kill Command in Linux

Alerts could be laid out in three other ways:

  1. Utilizing quantity (e.g., -1 or -s 1).
  2. Utilizing the “SIG” prefix (e.g., -SIGHUP or -s SIGHUP).
  3. With out the “SIG” prefix (e.g., -HUP or -s HUP).

The next instructions are equal to 1 one other:


The PIDs supplied to the kill command could be one of many following:

  • If PID is larger than zero, the sign is shipped to the method with ID equal to the PID.
  • If PID is the same as zero, the sign is shipped to all processes within the present course of group. In different phrases, the sign is shipped to all processes belonging to the GID of the shell that invoked the kill command. Use ps -efj command to view the method group IDs (GIDs).
  • If PID is the same as -1, the sign is shipped to all processes with the identical UID because the consumer invoking the command. If the invoking consumer is root, the sign is shipped to all processes besides init and the kill course of itself.
  • If PID is lower than -1, the sign is shipped to all processes within the course of group eq with GID equal to absolutely the worth of the PID.

Common customers can ship alerts to their very own processes, however not people who belong to different customers, whereas the foundation consumer can ship alerts to different consumer’s processes.

Terminating Processes Utilizing the kill Command #

To terminate or kill a course of with the kill command, first you should discover the method ID quantity (PID). You are able to do this utilizing totally different instructions akin to prime, ps, pidof and pgrep.

Let’s say the Firefox browser has turn into unresponsive, and you should kill the Firefox course of. To seek out the browser PIDs use the pidof command:

pidof firefox

The command will print the IDs of all Firefox processes:

6263 6199 6142 6076

As soon as the processes numbers, you’ll be able to terminate all of them by sending the TERM sign:

kill -9 2551 2514 1963 1856 1771

As a substitute of looking for PIDs after which terminating the processes, you’ll be able to mix the above instructions into one:

kill -9 $(pidof firefox)

Reloading Processes Utilizing the kill Command #

One other frequent use case for kill is to ship the HUP sign, which tells the processes to reload its settings.

For instance, to reload Nginx, you should ship a sign to the grasp course of. The method ID of the Nginx grasp course of could be discovered within the file, which is often is situated within the /var/run listing.

Use the cat command to seek out the grasp PID:

cat /var/run/

When you discovered the grasp PID reload the Nginx settings by typing:

sudo kill -1 30251

The command above have to be run as root or consumer with sudo privileges.

Conclusion #

The kill command is used to ship a sign to processes. Essentially the most frequently-used sign is SIGKILL or -9, which terminates the given processes.

We hope the Kill Command in Linux help you. If you have any query regarding Kill Command in Linuxdrop a comment below and we will get back to you at the earliest.

We hope this post helped you to find out  Kill Command in Linux  . You may also want to see – Pgrep Command in Linux |

Copy link
Powered by Social Snap