DESCRIPTION The command kill sends the specified signal to the specified process or process group. If no signal is specified, the TERM signal is sent. The TERM signal will kill processes which do not catch this signal. For other processes, it may be necessary to use the KILL (9) signal, since this signal cannot be caught.
Most modern shells have a builtin kill function, with a usage rather similar to that of the command described here. The '-a' and '-p' options, and the possi‐ bility to specify processes by command name are a local extension.
If sig is 0, then no signal is sent, but error checking is still performed. ...... # [root@localhost ~]# man 2 kill KILL(2) Linux Programmer's Manual KILL(2)
DESCRIPTION The kill() system call can be used to send any signal to any process group or process.
If pid is positive, then signal sig is sent to the process with the ID specified by pid.
If pid equals 0, then sig is sent to every process in the process group of the calling process.
If pid equals -1, then sig is sent to every process for which the calling process has permission to send signals, except for process 1 (init), but see below.
If pid is less than -1, then sig is sent to every process in the process group whose ID is -pid.
If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a process ID or process group ID.
For a process to have permission to send a signal it must either be privileged (under Linux: have the CAP_KILL capability), or the real or effective user ID of the sending process must equal the real or saved set-user-ID of the target process. In the case of SIGCONT it suffices when the sending and receiving processes belong to the same session.
man 1 文档中有一句 If sig is 0, then no signal is sent, but error checking is still performed, 意思是:如果sig为0,则不发送信号,但仍然进行错误检查。
man 2 文档中有一句 If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a process ID or process group ID,意思是:如果sig为0,则不发送信号,但仍然进行错误检查; 这可以用来检查是否存在进程ID或进程组ID。
if [ -f $PIDFILE ]; then PID="$(cat $PIDFILE)" if kill -0 "$PID" &> /dev/null; then echo "process is exists" exit 0 else echo "process is not exists" exit 5 fi fi