10.9 Kill and raise functions

Source: Internet
Author: User
Tags posix

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.

  1. #include<signal.h>
  2. int kill(pid_t pid,int signo);
  3. intraise(int signo);
  4. Bothreturn:0if OK,-1 on error.
  5. The call
  6. raise(signo);
  7. is equilent to the call:
  8. kill(getpid(), signo);

For the parameter PID of Kill, there are four different conditions:

The The
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).
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
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.