Signal Handling in C

后端 未结 5 1867
伪装坚强ぢ
伪装坚强ぢ 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:34

    In your example it seems you don't need CTRL-C handlind at all. A "signal(SIGINT,SIG_IGN)" seems enough for you, unless your application must handle a SIGINT coming from some other source. CTRL-D doesn't usually generates signals, it simply communicates the EOF condition. You can in general control the behavior of your terminal (we are talking about console input, it isn't?) by using the termios library (also here). You can enable, redefine or disable the "interrupt" character (CTRL-C), the EOF one and many other ones (XON, XOFF, modem control...)

    Regards

提交回复
热议问题