The nature of the linux-signal

Source: Internet
Author: User

The concept of a signal

A soft interrupt signal (signal, also referred to as a signal) is used to notify the process that an asynchronous event has occurred. At the software level is a simulation of the interrupt mechanism, in principle, a process receives a signal that the processor receives an interrupt request can be said to be the same ("Interrupt Essence"). The signal is the only asynchronous communication mechanism in the interprocess communication mechanism, and a process does not have to wait for the signal to arrive through any operation, in fact, the process does not know when the signal arrives exactly. Processes can send soft interrupt signals to each other through system call kill. The kernel can also send a signal to the process because of an internal event, notifying the process that an event has occurred. In addition to the basic notification function, the signaling mechanism can also pass additional information.

Signal Processing Flow

For a complete signal life cycle (from signal to corresponding processing function completion), can be divided into three stages: the emergence of signals, signal in the process of registration, signal execution and logoff .

Signal Occurrence

There are two sources of signal events: hardware sources (e.g. we press keyboards or other hardware failures), software sources, the most common system functions for sending signals are kill, raise, alarm and setitimer, and Sigqueue functions, and software sources include operations such as illegal operations.

Signal is registered in the process

There is a soft interrupt signal field in the table entry in the process table, where each bit of the field corresponds to a signal, and the kernel generates a signal when the event that caused the signal to occur. The method by which the kernel sends a soft interrupt signal to a process is that the kernel sets the signal field in the process table entry of the process corresponding to the bit of that signal, and when the kernel sets this flag, we say that the kernel has delivered a signal to the process . If the signal is sent to a process that is sleeping, the process is awakened if the process sleeps at a priority that can be interrupted, otherwise only the corresponding bit of the signal field in the process table is set, not the process is awakened. If you send to a process that is in a running state, only the appropriate domain is placed.

The process of receiving signals has different processing methods for various signals. The processing methods can be divided into three categories:

The first is an interrupt-like handler, and for signals that need to be processed, a process can specify a handler function that is handled by the function.

The second method is to ignore a signal and do nothing about it, as if it had not happened.

The third method is that the processing of the signal retains the default value of the system, and the default operation for most signals is to cause the process to terminate. The process calls signal through the system to specify the processing behavior of a process for a signal.

Transferred from: http://www.cnblogs.com/hoys/archive/2012/08/19/2646377.html

The nature of the linux-signal

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.