JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

5 Examples of kill Command in UNIX and Linux

Author:JIYIK Last Updated:2025/04/06 Views:

The kill command in UNIX and Linux killis 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 killAllkill 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 killsome examples of kill command in UNIX and how to killkill a locked process using kill command.


kill command examples in UNIX and Linux

As I said before, killit 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 -9Used 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 killcommand, 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 killcommand

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

kill command -l option

4) Print all signals supported by kill in UNIX

We can use kill -lto list all the signals supported by the kill command in UNIX, as shown in the following example:

$ kill -l

kill command -l lists all signals

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.

  1. 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.
  2. 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
  3. Bash has a built-in kill routine. So you can /bin/kill –versioncheck 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.

Article URL:

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 –

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial