Signal programming problems

Source: Internet
Author: User
Signal programming problems-General Linux technology-Linux programming and kernel information. The following is a detailed description. # Include
# Include
# Include
Void fun_ctrl_c ();
Int main ()
{
(Void) signal (SIGINT, fun_ctrl_c );
Printf ("main program: the program enters an infinite loop! \ N ");
While (1)
{
Printf ("This is an infinite loop (to exit, press Ctrl + C )! \ N ");
Sleep (3 );
}
Exit (0 );

}

Void fun_ctrl_c ()
{
Printf ("\ t you press Ctrl + C Oh :) \ n ");
Printf ("\ t signal processing function: What to process, programming in the processing function! \ N ");
Printf ("\ t this example is not processed, and the default processing of the SIGINT signal is restored. \ N ");
(Void) signal (SIGINT, SIG_DFL );
}

This is to print every three seconds. this is an infinite loop (to exit, press Ctrl + C )!
What I want to ask is how to implement Ctrl + C recognition in this program. The custom function fun_ctrl_c () does not seem to see Ctrl + c recognition, in addition, this still recognizes Ctrl + c twice. The first press is to implement the function fun_ctrl_c, and the second press is to exit the program. How is this implemented?

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.