Linux signal (1) -- kill function, linuxkill
There is no good or bad thing in the world. It depends on how we think about it. -- Scene 2 of the second act of Hamlet
Ilocker: Follow Android Security (New entry, 0 basics) QQ: 2597294287
1 # include <signal. h> 2 int kill (pid_t pid, int signo );
Sends signals to a specified process or process group. 0 is returned for success, and-1 is returned for error.
- Pid> 0: send the signal to the process whose ID is pid.
- Pid = 0: send the signal to all processes in the same process group of the sending process.
- Pid <0: sends a signal to all processes whose process group ID is equal to the absolute value of the pid.
- Pid =-1: sends signals to all processes in the system.
All processes in the preceding section do not include system processes.
In addition, the process that calls the kill function must have the permission to send signals to the target process. A non-root user can only send signals to a process that has the same user ID as the process that calls the kill function.
If the value of signo is 0, it indicates an empty signal. kill does not send the actual signal, but can be used to determine whether the specified process still exists. If an empty signal is sent to a non-existent process, kill returns-1, and errno is set to ESRCH (indicating that the process specified by the pid or the process group does not exist ).
Other errno: "EINVAL: the specified singo is invalid; EPERM: the permission is insufficient ".
It is not an atomic operation to check whether a process exists. When a kill is returned, the existing process may be terminated. In addition, the system will reuse the pid, so the process we specify the pid is not necessarily the process to be tested. Therefore, this test is not reliable.
Learning Materials: Advanced Programming in unix environment