The sigpipe__ function in the signal function

Source: Internet
Author: User
When you write the socket program under Linux, if you try to send it to a disconnected socket, it throws a sigpipe signal to the bottom. The default approach to this signal is to exit the process, which is not what we expected most of the time. The connection is established, if one end of the connection, and the other end still write data to it, the first write data will receive the RST response, then write the data, the kernel will send a sigpipe signal to the process, notify the process that the connection has been disconnected. and the default processing of SIGPIPE signals is to terminate the program

Therefore, we need to overload this signal processing method. You can safely shield Sigpipe by invoking the following code:

Signal (Sigpipe, sig_ign);


For generating signals, we can use method signal (int signum, sighandler_t handler) to set signal processing before generating a signal. If this method is not called, the system calls the default processing method: Aborts the program and displays the prompt (which is the problem we often encounter). We can call the system's processing method, or we can customize the processing method.

Three methods are defined inside the system:
(1) SIG_DFL signal-specific default actions:
(a) If the default action is to suspend a thread, execution of that thread is temporarily suspended. When a thread is paused, any additional signals sent to the thread are not delivered until the thread starts executing, except Sigkill.
(b) The signal action of the suspended signal is set to SIG_DFL and the default action is to ignore the signal (SIGCHLD).
(2) Sig_ign ignore the signal.
(a) The delivery of the signal has no effect on the thread
(b) The system does not allow the action of the Sigkill or sigtop signal to be set to SIG_DFL
(3) Sig_err



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.