Linux Signal (ii)--signal function

Source: Internet
Author: User
Tags function prototype signal handler

Freud thought: To solve these problems, the parties will have to remember and understand their early childhood experience, to gain insight into the subconscious conflict. Freud's therapy, called "Psychoanalysis" (psychoanalysis), was widely adopted by mental health practitioners for a long time in 20th century. --"Change Your thinking"

Ilocker: Focus on Android Security (new entry, 0 Basics) qq:2597294287

1 #include <signal.h>2void (*signal (intvoid (*func) (int ))) (int);

Sets the signal handler for the signal specified by the Signo. Success returns a function pointer to the previous signal handler, and an error returns SIG_ERR.

If you do not understand the function declaration of signal, you should review the basic (function pointers) of C + +.

Make the declaration of the signal function a bit simpler:

1 void Sigfunc (int// Signal processing function prototype 2 sigfunc * signal (int signo, Sigfunc * func);

Simple example:

1 voidSig_handler (intSigno) {2   if(SIGUSR1 = =Signo)3 printf ("Received SIGUSR1.");4   Else5printf ("Received signal%d. ", Signo);6 }7 8 intMain () {9   if(Sig_err = =signal (SIGUSR1, Sig_handler))Tenprintf ("Can ' tCatchSIGUSR1 "); One  A    for ( ; ; ) - pause (); -}

The signal processing function can also be set to Sig_ign (indicating that this signal is ignored) or SIG_DFL (indicating the use of the system's default signal handler).

Signal SIGSTOP, SIGKILL cannot be captured or ignored.

The following two points are recorded but not verified and are not determined to be correct:

    • Assuming a handler for signal A is being executed, and another signal B comes in, the signal handler for B is transferred, and after processing is completed, a signal handler is then executed.
    • There is a soft interrupt signal field in the process, and each bit in the domain corresponds to a signal, and when a signal is received, the corresponding bit is placed. So, for the same signal, the process does not know how many have been received before processing.

In addition to signal, there are sigaction functions that can set signal processing functions, which are more complex than signal, and then write notes later.

Learning materials: Advanced Programming for the UNIX environment

Linux Signal (ii)--signal function

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.