The Kill function is used to send a signal to a process or a process group, and the function raise allows a process to send a signal to itself.
The Raise function was first defined with ISO C, and posix.1 in order to be compatible with the ISO C standard, thus containing the function raise, but posix.1 extended the feature raise to threading (we'll discuss how threads interact with the signal in 12.8), Because ISO c does not handle multiple processes, it does not define a function such as kill, because the kill function needs to use a process ID parameter.
#include<signal.h>
int kill(pid_t pid,int signo);
intraise(int signo);
Bothreturn:0if OK,-1 on error.
The call
raise(signo);
is equilent to the call:
kill(getpid(), signo);
For the parameter PID of Kill, there are four different conditions:
pid condition |
meaning |
pid>0 |
signal is Send to process with process ID PID |
pid = = 0 |
The signal is sent to processes with all process group IDs consistent with the process group ID of the sending process, note that the "All Processes" contains the implementation-defined system process collection, for many Unix system, this system process collection contains kernel processes as well as init (PID 1). | The
pid < 0 |
signal is sent to all process group IDs equal to the PID absolute value and the process that invokes the function has permission to send a signal to the process, similarly, the collection of all processes contains some system processes, as described earlier | The
pid = = 1 |
signal is sent to all processes on the system that have permission to invoke the function, and as mentioned earlier, the collection contains some system processes. |
Superuser can send signals to any process, and for other users The basic rule is that the real or effective user ID of the sending process must be equal to the real or effective user ID of the receiving process if the implementation supports _POSIX_SAVED_ IDS (posix.1 requires support), the saved Set-user-id of the receiving process is checked instead of its effective user ID, and a special case for the above permission check is: If the signal sent is Sigcont, Then any process that is in the same session can receive it.
POSIX.1 defines a signal number 0 is a null signal, if the Signo parameter is passed 0, then the normal error check will be executed by the KILL function, but does not send any signal, the technology is usually used to check whether a particular process is still present, if we send a process null signal, and the acceptance process does not exist, then The Kill function will return 1, and errno will be set to Esrch, and it should be noted that the UNIX system will recycle the process ID, so the presence of a process with the same process ID does not necessarily mean the original process.
If a call to the KILL function causes a signal to be generated and the target process being sent is the calling process itself, and the signal is not blocked, then the unblocked signal is sent to the process before the KILL function returns.
From for notes (Wiz)
10.9 Kill and raise functions