5 Examples of kill Command in UNIX and Linux
The kill command in UNIX and Linux kill
is commonly used to kill a hung or hung process or group of processes. kill is just a signal transmitter that sends the specified signal to the specified process in UNIX or UNIX-like systems such as Linux, Solaris, or FreeBSD. Just like in Windows, when we see a particular process hanging the system, we go to the Task Manager to find the process and kill it, similarly, in UNIX and Linux, we first find the Process ID (PID) of the problematic process and then kill it.
Although we also have killAll
kill command which does not require PID but can kill a process using only the process name. Kill command is usually kill()
a wrapper around the kill system call but some Linux systems also have kill built in. In this article, we will see kill
some examples of kill command in UNIX and how to kill
kill a locked process using kill command.
kill command examples in UNIX and Linux
As I said before, kill
it sends a signal to the specified process, it can send all the signals specified in. Here we will see some examples of kill command in UNIX and Linux:
1) kill command forcibly kills a process in UNIX
kill -9
Used to forcefully terminate a process in Unix. Following is the syntax of kill command in UNIX.
$ ps -ef| grep process_identifier // 会显示PID
$ kill -9 PID
2) Unix kills command kills multiple processes
Using the UNIX kill
command, we can specify multiple PIDs at the same time and all processes will receive the signal, or if the signal is KILL, they will be killed, as shown in the following UNIX kill
command
The kill syntax in UNIX to kill multiple processes is:
$ kill -9 pid1 pid 2
Here is an example of killing multiple processes in UNIX:
迹忆客:~ jiyik.com$ ps -ef
UID PID PPID TTY STIME COMMAND
jiyik 5736 5332 1 Nov 14 /usr/bin/bash
jiyik 5604 5552 0 Nov 16 /usr/bin/bash
jiyik 3508 4872 2 Nov 17 /usr/bin/bash
jiyik 6532 5604 0 17:43:19 /usr/bin/man
jiyik 6352 3420 0 17:43:22 /usr/bin/sh
jiyik 7432 6352 0 17:43:22 /usr/bin/less
jiyik 5348 3508 2 17:52:59 /usr/bin/ps
迹忆客:~ jiyik.com$ kill -9 3420 6352
迹忆客:~ jiyik.com$ ps -ef
UID PID PPID TTY STIME COMMAND
jiyik 5736 5332 1 Nov 14 /usr/bin/bash
jiyik 5604 5552 0 Nov 16 /usr/bin/bash
jiyik 3508 4872 2 Nov 17 /usr/bin/bash
jiyik 5040 3508 2 17:53:38 /usr/bin/ps
3) Find the Signal name using the kill command in UNIX
If we run the command
with option “ -lKill
” , it can also show us the name of the Signal. For example, “ 9 ” is the KILL signal, and “ 3 ” is the QUIT signal.
$ kill -l 3
QUIT
$ kill -l 9
KILL
4) Print all signals supported by kill in UNIX
We can use kill -l
to list all the signals supported by the kill command in UNIX, as shown in the following example:
$ kill -l
5) Use the -s option of the kill command to send the signal in UNIX.
We can use kill command option -s to specify the signal name to send to other processes instead of specifying the number. Following is an example of using Kill command and signal code in UNIX.
$ ps -ef
UID PID PPID TTY STIME COMMAND
jiyik 5736 5332 1 Nov 14 /usr/bin/bash
jiyik 3508 1 2 Nov 17 /usr/bin/bash
jiyik 7528 2352 0 18:00:30 /usr/bin/bash
jiyik 4424 7528 0 18:05:11 /usr/bin/less
jiyik 168 7528 0 18:05:15 /usr/bin/ps
[1]+ Stopped less -r a
$ kill -s KILL 4424
$ ps -ef
UID PID PPID TTY STIME COMMAND
jiyik 5736 5332 1 Nov 14 /usr/bin/bash
jiyik 3508 1 2 Nov 17 /usr/bin/bash
jiyik 7528 2352 0 18:00:30 /usr/bin/bash
jiyik 5044 7528 0 18:05:32 /usr/bin/ps
Important points about the kill command in UNIX and Linux
To conclude the discussion and examples of UNIX kill command, we have outlined some of the key points and things to remember related to kill command in UNIX and Linux. You can quickly refer to this whenever you have doubts regarding kill in UNIX.
- The kill command in UNIX can send signals to any other process in UNIX or Linux. In order to use these signals, the respective process should understand these signals.
- In unix, we can get the complete list of signals supported by kill command
by simply executing "
man kill
" or simply by executing the command .kill -l
-
Bash has a built-in kill routine. So you can
/bin/kill –version
check by typing
That's all about the UNIX kill command, I will add a few more points as I think of them. You are also welcome to provide some examples of kill command in UNIX.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Restart PostgreSQL in Ubuntu 18.04
Publish Date:2025/04/09 Views:72 Category:PostgreSQL
-
This short article shows how to restart PostgreSQL in Ubuntu. Restart PostgreSQL Server in Ubuntu You can restart Postgres server in Ubuntu using the following command. Order: sudo service postgres restart Sometimes the above command does n
Issues to note when installing Apache on Linux
Publish Date:2025/04/08 Views:78 Category:OPERATING SYSTEM
-
As the most commonly used web server, Apache can be used in most computer operating systems. As a free and open source Unix-like operating system, Linux and Apache are a golden pair. This article will introduce the installation and use of A
How to decompress x.tar.xz format files under Linux
Publish Date:2025/04/08 Views:186 Category:OPERATING SYSTEM
-
A lot of software found today is in the tar.xz format, which is a lossless data compression file format that uses the LZMA compression algorithm. Like gzip and bzip2, it supports multiple file compression, but the convention is not to compr
Summary of vim common commands
Publish Date:2025/04/08 Views:115 Category:OPERATING SYSTEM
-
In Linux, the best editor should be vim. However, the complex commands behind vim's powerful functions also make us daunted. Of course, these commands do not need to be memorized by rote. As long as you practice using vim more, you can reme
Detailed explanation of command return value $? in Linux
Publish Date:2025/04/08 Views:58 Category:OPERATING SYSTEM
-
? is a special variable. This variable represents the return value of the previous command. That is to say, when we run certain commands, these commands will return a code after running. Generally, if the command is successfully run, the re
Common judgment formulas for Linux script shell
Publish Date:2025/04/08 Views:159 Category:OPERATING SYSTEM
-
In shell script programming, predicates are often used. There are two ways to use predicates, one is to use test, and the other is to use []. Let's take a look at how to use these two methods through two simple examples. Example 1 # test –
Shell script programming practice - specify a directory to delete files
Publish Date:2025/04/08 Views:98 Category:OPERATING SYSTEM
-
Usually, in Linux system we need to frequently delete some temporary files or junk files. If we delete them one by one manually, it will be quite troublesome. I have also been learning shell script programming recently, so I tried to write
Use of Linux command at - set time to execute command only once
Publish Date:2025/04/08 Views:158 Category:OPERATING SYSTEM
-
This article mainly involves a knowledge point, which is the atd service. Similar to this service is the crond service. The functions of these two services can be similar to the two functional functions of javascript. Those who have learned
Use of Linux command crontab - loop execution of set commands
Publish Date:2025/04/08 Views:170 Category:OPERATING SYSTEM
-
Compared with at , which executes a command only once, crontab, which we are going to talk about in this article, executes the set commands in a loop. Similarly, the use of crontab requires the support of the crond service. The service is s