Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • What happens if I want to terminate with CTRL + AAA instead of CTRL + CCC? Commented Jun 1, 2019 at 19:22
  • 1
    Changing key binding in your code is not possible as far as i know. but like i said you can change signal key binding in stty and in your terminal emulator. Commented Jun 1, 2019 at 19:29
  • 1
    you do not use printf and exit in signal handlers, ever. just think what happens if a SIGINT is coming while the program is running another printf or flushing the stdio buffers, or within a handler registered with atexit(3). Commented Jun 1, 2019 at 19:54
  • 1
    Thanks @mosvy but this is a proof of concept code not a real one. why you don't add an answer and explain us more about what you know. because i didn't get what you said in your last comment. Commented Jun 1, 2019 at 20:05
  • 2
    @RasoolZiafaty just because it's a proof of concept it should be correct. Besides, doing it correctly will make it shorter and simpler, not the reverse. Notice that the use of signal() instead of sigaction() is also highly dubious: on some systems, signal(3) will set the handler as with SA_RESETHAND ie the handler will be disabled after the first ^C. Commented Jun 1, 2019 at 20:11