0

I am trying to change the default behavior of the control signals with stty. Signals like Ctrl+C, Ctrl+D, Ctrl+Z, Ctrl+\. Can any one give me idea about how to disable and enable these signals on console with stty.

  • 1
    More correctly they are special characters that trigger the line discipline to send signals. – JdeBP Sep 29 '16 at 10:59
1

You can "trap" commands (and key combinations) with trap:

trap "echo CTRL+C not allowed" 2

Now when I use CTRL+C in the terminal I get this message:

CTRL+C not allowed

Or, just trap "" 2 if you simply want to trap CTRL+C without printing anything.

To clear a trap, simply do:

trap - 2


Read the man page for trap here. More information about signals and traps can be found here.

| improve this answer | |
  • no i dont want to show any type of messages nor allow these signals to interrupt my program for some time. After some time again i need to enable these signals. – Kumar2080 Sep 29 '16 at 11:23
  • @Kumar2080 See my edit. And please read the information in the links I posted. – maulinglawns Sep 29 '16 at 11:33
0

trap will not work on CTRL+Z ,when you provide CTRL+Z the handler will not execute and your console gets non-interactive

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.