1. Function Description:
Kill and raise are used to send signals:
Kill sends signals to processes or process groups;
Raise sends the signal to the process itself.
Their prototype is as follows:
# Include <signal. h>
Int kill (pid_t PID, int signo );
Int raise (INT signo );
If the call succeeds, 0 is returned. If the call fails,-1 is returned.
From the prototype, we can see that the raise function can be implemented through kill.
Raise (signo );
It is equivalent:
Kill (getpid (), signo );
2. PID parameters:
The PID parameter in the kill function, which has the following four situations:
- PID> 0: send the signal to the process whose ID is PID.
- PID = 0: send the signal to all processes (excluding kernel and init processes) in the same process group of the sending process ). in this case, the sender must have the permission to send signals to these processes.
- PID <0: send the signal to all processes whose process group ID is equal to the absolute value of PID (excluding kernel processes and init processes ). in this case, the sender must have the permission to send signals to these processes.
- PID =-1: send the signal to all processes on the system that have the permission to send the signal to the sending process (excluding the kernel process and INIT process ).
3. signo parameters:
Posix.1 defines a signal numbered 0 as an empty signal. if the signo parameter is 0, kill still performs a normal error check, but does not send a signal. this is used to determine whether a process exists.