kill

Send a signal to the process.

Table of contents

Built-in commands

Summary

kill [-s sigspec | -n signum | -sigspec] pid | jobspec ...
kill -l [sigspec]

The main purpose

Options

-s sig signal name.
-n sig The number corresponding to the signal name.
-l lists signal names. If a number is provided after this option it is assumed to be the number corresponding to the signal name.
-L is equivalent to the -l option.

Parameters

pid: process ID

jobspec: job identifier

return value

The return status is success unless an illegal option is given or an execution error occurs.

example

[user2@pc] kill -l 9
KILL

# List all signal names:
[user2@pc] kill -l
  1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
  5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE
  9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT
17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU
25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH
29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN
35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4
39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12
47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14
51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10
55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6
59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX

#The following are commonly used signals.
# Only the ninth signal (SIGKILL) can terminate the process unconditionally, and other signal processes have the right to ignore it.

HUP 1 terminal hangs up
INT 2 interrupt (same as Ctrl + C)
QUIT 3 Exit (same as Ctrl + \)
KILL 9 Forced termination
TERM 15 Termination
CONT 18 Continue (opposite of STOP, fg/bg command)
STOP 19 Pause (same as Ctrl + Z)
# The following forms of sending KILL signals are equivalent. Of course, there are more equivalent forms, which are not listed here.
[user2@pc] kill -s SIGKILL PID
[user2@pc] kill -s KILL PID
[user2@pc] kill -n 9 PID
[user2@pc] kill -9 PID

[user2@pc] sleep 90 &
[1] 178420

# Terminate the job with job identifier 1.
[user2@pc] kill -9 %1

[user2@pc] jobs -l
[1]+178420 KILLED ssh 192.168.1.4

[user2@pc] sleep 90 &
[1] 181357

# Send stop signal.
[user2@pc] kill -s STOP 181357

[user2@pc] jobs -l
[1]+ 181537 Stopped (signal) sleep 90

# Send continue signal.
[user2@pc] kill -s CONT 181357

[user2@pc] jobs -l
[1]+ 181537 Running sleep 90 &

Notice

External commands

Summary

kill [-signal|-s signal|-p] [-q value] [-a] [--] pid|name...
kill -l [number] | -L

The main purpose

Options

-s, --signal signal The signal to be sent may be the signal name or the number corresponding to the signal.
-l, --list [number] Print signal names or convert the given number to a signal name. The signal name can be found in the file (/usr/include/linux/signal.h).
-L, --table Similar to the '-l' option, but outputs the signal name and the number corresponding to the signal.
-a, --all Do not restrict "command name to pid" conversion to processes with the same UID as the current process.
-p, --pid Print the PID of the target process without sending a signal.
--verbose prints the signal and the PID of the received signal.
-q, --queue value Use sigqueue(3) instead of kill(2). The parameter value is the number corresponding to the signal.
                            Can be obtained if the receiving process has installed a handler for this signal marking SA_SIGINFO as sigaction(2)
                            This data is passed through the si_sigval field of the siginfo_t structure.
--help Display help information and exit.
--version Display version information and exit.

Parameters

The list of processes receiving the signal can be a mixture of PID and name.

PID: Each PID can be one of the following four situations:

StatusDescription
nWhen n is greater than 0, the process with PID n receives the signal.
0All processes in the current process group receive the signal.
-1All processes with PID greater than 1 receive the signal.
-nWhen n is greater than 1, all processes in process group n receive the signal. When a parameter is given in the form of "-n" and you want it to represent a process group, you must first specify a signal, or there must be a "--" option before the parameter, otherwise it will be considered sent. Signal.

name: All processes called with this name will receive the signal.

example

>sleep 20 &

# List the corresponding PIDs.
> kill -p sleep
23021

return value

Notice

Reference link

Sending signals to processes