Signal () function description

Source: Internet
Author: User
Header file# Include <signal. h> Benefits:Set the corresponding action of a signal Function prototype: Void (* signal (int signum, void (* handler) (int); or: typedef void (* sig_t) (int ); sig_t signal (int signum, sig_t handler ); Parameter description: The first parameter signum indicates the signal type to be processed. It can take any signal Except SIGKILL and SIGSTOP. The second handler describes the action associated with the signal. It can take the following three values: (1) a function address without return values. This function must be stated before signal () is called, the name of the function in handler. When a signal of sig type is received, the function specified by handler is executed. This function should be defined in the following form: void func (int sig); sig is the unique parameter passed to it. After a signal () call is executed, the process immediately executes the func () function no matter which part of the program it is executing receives a signal of the sig type. When the execution of the func () function ends, the control returns the point where the process is interrupted and continues to be executed. (2) The SIG_IGN symbol indicates that the signal is ignored. After the corresponding signal () call is executed, the process ignores the signal of the sig type. (3) The SIG_DFL symbol indicates that the signal is processed by the restoration system by default. Function Description: Signal () sets the signal processing function based on the signal number specified by signum. When the specified signal arrives, the function execution specified by handler is redirected. When a signal processing function is executed, if the process receives the signal again, the signal will be automatically stored without interrupting the execution of the signal processing function, after the signal processing function is executed, call the corresponding processing function again. However, if the process receives other types of signals during signal processing function execution, the execution of the function will be interrupted. Return Value:Returns the previous signal processing function pointer. If an error exists, returns SIG_ERR (-1 ). The following situations can generate Signal:
  1. Press CTRL + C to generate SIGINT
  2. Hardware interruption, such as Division 0 and illegal memory access (SIGSEV)
  3. The Kill function can send Signal to a process.
  4. Kill command. It is actually a packaging of the Kill function.
  5. Software interruption. For example, when the Alarm Clock times out (SIGURG), when the Reader stops, it writes data (SIGPIPE) to the pipeline, and so on.

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.