Linux interprocess communication (iv) signal transmission capture of signal communication

Source: Internet
Author: User

Signal communication signal transmission capture Kill (), raise (), alarm (), pause () and its basic experiments

Signal overview

The signal is a simulation of the interrupt mechanism at the software level. In principle, a process receives a signal and the processor receives an interrupt request that can be said to be the same.

The signal is asynchronous, a process does not have to do anything to wait for the signal to arrive, in fact the process does not know exactly when the signal arrives.

The signal can interact directly between the user space process and the kernel process, and the kernel process can also use it to inform users of what system events are happening in the space process. It can be sent to a process at any time without having to know the state of the process. If the signal is not currently in the execution state (Running), the signal is saved by the kernel until the process resumes execution and passes it to it. If a signal is set to block by a process, the signal is passed to the process until its blocking is canceled.

Signal is the only asynchronous communication mechanism in interprocess communication mechanism, which can be regarded as asynchronous notification, which notifies the process of receiving signal. The signaling mechanism can also pass additional information in addition to basic notifications.

Signal source

There are two sources of signal events:

① hardware source. If we press the button on the keyboard or if there are other hardware failures;

② software source. The most common system functions for sending signals are kill (), raise (), Alarm (), Setitimer () and Sigqueue (), and the software source includes some illegal operations.

How the process responds to the signal

① ignore the signal. Ignoring the signal is not processing the signal, of which two signals can not be ignored: Sigkill and Sigstop.

② capture signals. Defines a signal processing function that performs the processing of a response when a signal occurs.

③ performs the default action. Linux sets the default action for each signal, as shown in the following table:

The life cycle of the signal

A complete signal lifecycle can be divided into 3 important stages, which are depicted by 4 important events, signal generation, signal registration in process, signal cancellation in process, signal processing function. Here the signal generation, registration, cancellation is the internal implementation mechanism of the signal, rather than the function of the signal implementation (not under our control). Therefore, the registration of the signal is not related to the signal function (such as Kill (), etc.) and the signal installation function (such as signal (), etc.).

The interval of two adjacent events constitutes a phase of the signal lifecycle, as shown in Figure 1. Note that there are many ways to signal processing, usually by the kernel, and of course, can be completed by the user process.

Signal processing, including signal transmission, capture and processing, they have their corresponding common functions:

function to signal: Kill (), raise ().

function to capture signal: alarm (), pause ().

Functions for processing signals: signal (), sigaction ().

This section is mainly about signal transmission and capture, the next section to deal with

Signal sending function Kill () and raise ()

Function description

The Kill () function is the same as our kill system command (but cannot be mistaken for kill) to send a signal to a process or process group (actually, the kill system command is just a user interface to the Kill () function). It should be noted here that the Kill () function can not only terminate the process (actually by emitting a sigkill signal), but also send other signals to the process.

Unlike the Kill () function, the raise () function allows a process to send a signal to itself.

Related Article

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.