Signal Handling in C

后端 未结 5 1866
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 02:49

How can I implement signal Handling for Ctrl-C and Ctrl-D in C....So If Ctrl-C is pressed then the program will ignore and try to get the input from the user again...If Ctrl

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 03:27

    This is a program for handling signal when pressed Ctrl+c

    The syntax for signal function is : signal(signal name, function name);

    #include
    #include  // for handling signal 
    
    void signal_handler() 
    {
        printf("Signal Handled here\n");
    }
    
    main() 
    {
        printf("In main function..\n");
    
        // SIGINT is signal name create  when Ctrl+c will pressed 
        signal(SIGINT,signal_handler);  
    
        sleep(15);
    
        printf("In main after called from signal_handle \n");
    
    }
    

提交回复
热议问题