A summary of common signals under Linux

Source: Internet
Author: User

There are a lot of signals under Linux, which can be classified as reliable and unreliable signals, divided into real-time signals and non-real-time signals, and the Linux process has three ways to handle incoming signals:

(1) Ignore the signal, that is, the signal does not do any processing, wherein, there are two signals can not be ignored: Sigkill and sigstop;

(2) Capture the signal. The signal processing function is defined and the corresponding processing function is executed when the signal occurs;

(3) Perform the default operation, and Linux specifies the default action for each type of signal.

The default response of a Linux process to a real-time signal is a process termination. However, for high-performance server programming, this is a fatal flaw, for such a server needs to ensure that after receiving a variety of signals can still be reliable operation, so we need to understand the reasons for the various signals and the correct processing method. In this paper, I often encounter some of the signals to collate, combined with their own experience in the use of a brief analysis.

SIGHUP is related to console operation, when the console is turned off, the system sends HUP signals to all processes that own the console SessionID, and the default HUP signal action is exit, If a remote login starts a service process and closes the connection while the program is running, the service process exits, so the General Service process is started with the Nohup tool (which is to let the signal be ignored) or written as a daemon (using SETSID).

The following five groups can be placed in an analogy

SIGINT Terminates the process, usually our CTRL + C sends this message.

Sigquit and SIGINT are similar, but are controlled by the Quit character (usually CTRL/). The core file is generated when the process receives the message and exits.

SIGKILL message number is 9, we often use kill-9 to kill process sent is this message, the program received this message immediately terminate, this message can not be captured, blocked or this ignore, so is the ultimate weapon to kill process.

SIGTERM is a signal that is sent by default when no parameter is taken, and the default is the kill process.

SIGSTOP Stop the execution of the process, as the sigkill can not be handled by the application, notice it and terminate and interrupt difference: The process is not finished, just paused execution.

Sigcont When Sigstop is sent to a process, the usual behavior is to pause the current state of the process. If a sigcont signal is sent, the process resumes execution only. In addition to other purposes, sigstop and Sigcont are used for job control in Unix shells and cannot capture or ignore sigcont signals.

sigpipe This is an error in writing data to a pipeline that does not have a read process, an explanation that is too official. In network programming, this signal occurs if the client has closed the socket and the server calls write once, the server receives an RST segment, and if the server calls write again, this time the sigpipe signal is generated. The default way to do this is to turn off the process, but for a highly available server program, you need to handle this signal manually, so you will see that many server program code explicitly adds signal (sigpipe, sig_ign) to ignore this signal.

Sigchild This is also a high-performance server need to pay attention to the signal, if the server with fork generated after the child process to call wait for resource recycling, to prevent the production of zombie processes, However, you can call signal (sigchld,sig_ign) If the program is not interested in the state after the child process exits. To the system init to recycle. The child process does not spawn a zombie process.

SIGSEGV is the fact that Segmentfault tries to access memory that is not allocated to itself, or attempts to write data to a memory address that does not have write permission, the official three examples are:

    1. Buffer overflow---usually caused by a pointer reference out of range. Wild Hands
    2. Stack Overflow---, keep in mind, the default stack size is 8192K. Stack Overflow
    3. Illegal file access---file operations is forbidden on our Judge system. Illegal file access

The address that corresponds to the sigbus Pointer is a valid address, but the bus does not use the pointer properly. This is usually caused by unaligned data access. An attempt was made to access an area of memory that has no file content, such as an area of memory that exceeds the end of the file, or a memory area that has previously been truncated for another process. Apache burst a bug is the MMAP call when the file changes will be burst this error, specific reference this wonderful blog is: http://blog.csdn.net/ctthuangcheng/article/details/8916015

Sigurg I/O emergency signals are used when TCP transmits out-of-band data, but the emergency pointers are not recommended in the TCP manual RFC6093, so this signal is useless.

SIGIO This signal is generated when the descriptor can be I/O, the signal-driven IO model in the five large IO models is realized.

The sigalrm Clock Timing signal calculates the actual time or clock time. The alarm function uses this signal.

The above is the programming common to the signal, but also the most interesting signal, as for other signals, remember to write it later.

A summary of common signals under Linux

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.