[Linux] What SIGNAL is associated to a CTRL+ combination ??? (SOLVED)


PowerGod

Forum Addict!
Joined
Jun 20, 2011
Messages
4,462
I just want to know, if I press for example CTRL+Z (or any other combination), what SIGNAL is sent, either the code or the name.

I searched for days about this argument and I still can't find a solution... I just found explanations about what a combination does, but I want to know the SIGNAL, because I need to trap it.

I collected all these info:
  • kill -l, shows all the SIGNAL codes
  • trap "" <number>, will disable a SIGNAL
  • man bash, lists some SIGNALS here and there but them are scattered and is not explained what combination sends them
  • stty -a, shows many hotkeys assigned, but doesn't show the SIGNAL associated to them
  • terminfo, shows many hotkeys assigned, but doesn't show the SIGNAL associated to them

So, do you know how can I find this information ?
I mean, I want to obtain it from the system itself, because I'll need to find the associations on different distributions.

(In the title there's Linux, but I'm actually using Cygwin, if it makes some difference...)

EDIT:
Adding an example (for CTRL+Z) of what I'm doing:

using stty -a i see this relevant information
Code:
 swtch = ^Z
so I know that the CTRL+z combination triggers a "swtch" o_O

then searching this "swtch" in man stty I find
Code:
 * swtch CHAR
    CHAR will switch to a different shell layer

and then I'm lost...
 
Last edited:
Sorry, I don't quite grok your meaning of 'signal', but xev reports one event for ctrl (keycode 0xffe3, Control_L) and one for 'z' (keycode 0x7a, z). According to 'xmodmap -pf' keycode 52 is z on my system and the way I read it suggests ctrl-Z is the same as plain Z from its point of view, so I'm not sure where the shell, for example, identifies ctrl plus Z as ctrl-Z (but clearly it does, as ctrl-A and ctrl-E have their defined shell effects just fine).

Edit: I don't think he means signal as in SIGTERM and that lot. Those are interprocess signals and not anything to do with the keyboard, at least directly.

Edit2: In my 'stty -a' output ^Z is defined as 'susp' as in suspend the current foreground process to return foreground control to the shell, which is what it does on my system (from there you can reforeground it using fg, or run it in the background using bg). Not sure what 'swtch' is, but it's undef on my system.
 
Last edited:
@ible : thanks, I'll have a look, but I'll use python as the last hope, I'll try to use just bash and it's tools if I can find the way

@levi: SIGNALS are these
Code:
$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP  
6) SIGABRT 7) SIGEMT 8) SIGFPE 9) SIGKILL 10) SIGBUS
11) SIGSEGV 12) SIGSYS 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGURG 17) SIGSTOP 18) SIGTSTP 19) SIGCONT 20) SIGCHLD
21) SIGTTIN 22) SIGTTOU 23) SIGIO 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGPWR 30) SIGUSR1
31) SIGUSR2 32) SIGRTMIN 33) SIGRTMIN+1 34) SIGRTMIN+2 35) SIGRTMIN+3
36) SIGRTMIN+4 37) SIGRTMIN+5 38) SIGRTMIN+6 39) SIGRTMIN+7 40) SIGRTMIN+8
41) SIGRTMIN+9 42) SIGRTMIN+10 43) SIGRTMIN+11 44) SIGRTMIN+12 45) SIGRTMIN+13
46) SIGRTMIN+14 47) SIGRTMIN+15 48) SIGRTMIN+16 49) SIGRTMAX-15 50) SIGRTMAX-14
51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9
56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4
61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
 
Hmm, okay. I don't think any of my keyboard buttons are bound to send those signals, apart from perhaps the power button which runs 'shutdown -h now' which will potentially emit SIGKILL signals to all processes as part of shutting down. But nothing generates one of those signals directly - which process would it target? You need to know which process you're sending those signals to, otherwise you wouldn't be able to control what happens.
 
Hmm, okay. I don't think any of my keyboard buttons are bound to send those signals, apart from perhaps the power button which runs 'shutdown -h now' which will potentially emit SIGKILL signals to all processes as part of shutting down. But nothing generates one of those signals directly - which process would it target? You need to know which process you're sending those signals to, otherwise you wouldn't be able to control what happens.

o_O so, if you launch a program and do a CTRL+C or CTRL+Z nothing happens ?

I just want to disable them, I need to free those combinations before running a specific program, to be able to use them inside it for other functions, and at the exit letting them resume their usual functions...
 
Good point, I forgot about ctrl-C - that's defined as 'intr' in stty -a. Not sure what signal is invoked there, but probably one is.

If all you want to do is disable them, can't you use stty to do that? I can redefine them by typing for example 'stty intr ^W' to make ctrl-W work as my ctrl-C normally does. It seems invoking 'stty intr undef' works to set them to <undef> in stty -a output. Is that not what you're looking for?

Edit: Setting them back to their normal settings might be more work. You'd need to parse the 'stty -a' output to find out what the preexisting settings are to be best of my current knowledge.

FWIW, man stty tells me that intr sends an interrupt signal, possibly a SIGINT.

Edit2: And it tells me susp sends a stop signal. Indeed, sending a SIGSTOP (-19) from another shell appears to do the same, and it ends of in the 'jobs' list of the originating shell. Cool stuff!
 
Last edited:
  • Like
Reactions: ___
"intr" refers to SIGINT, but i know it because someone in some forum told it... I just can't find a list of those associations... but it must be somewhere !! This thing is making me crazy :-||

I'll have a look at how complicated could become to disable/enable those combinations with stty programmatically... but still I really want to find out how to get the associated signal... really, my search started like a simple thing "then I just get the signal associated and I'm done :)" and the hell raised... I have 250 opened tabs on the browser (and also many man pages on the terminal) about the argument and nothing that can give to me this "simple" answer :(
 
Well, the documentation in 'man stty' tells me that whenever you press the keycode associated with 'intr' it sends an interrupt process, and 'susp' sends a stop process. I guessed that that probably means SIGINT and SIGSTOP, and it seems I was right - there's only a limited number of signals it could be. I still suspect that stty arguments such as kill which deletes the current line don't actually work by sending a signal, but I might be wrong. Still, you can disable them using stty if you want.

In terms of determining the current settings programmatically, it's probably relatively easy to come up with a 'sed' command which will print out the current setting of a specific stty action. You could then store those in variables, and at the end use a set of case statements to set anything that isn't <undef> back to its claimed setting.
 
"intr" refers to SIGINT, but i know it because someone in some forum told it... I just can't find a list of those associations... but it must be somewhere !!

Maybe this might be helpful?

The SIGINT (“program interrupt”) signal is sent when the user types the INTR character (normally C-c). See Special Characters, for information about terminal driver support for C-c.

http://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html

And here is a list of characters that cause signals:
http://www.gnu.org/software/libc/manual/html_node/Signal-Characters.html#Signal-Characters
 
Last edited:
"swtch" isn't a signal, it's a terminal command. It simply stands for "switch", and it switches shell layers, basically letting you have multiple shells in a single shell, if the shell supports it. I don't know why your swtch is set to ^Z; ^Z is typically used to send a suspend signal to the process and give the shell control again.
 
Not sure about swtch, but that seems more of a byproduct to me. But the signal you are searching for CRTL+Z seems to be SIGTSTP, according to the list I linked.
 
CRTL+Z seems to be SIGTSTP
Also known as SIGSUSPEND in some systems.
Incidentally, if your intention is to trap these signals, know that you can't. Most signals can be trapped, SIGKILL and SIGSTOP/SUSPEND are untrappable, handled by the OS.
 
@WizardStan : so the association showed by stty is not used ? o_O Then where is the "true" association to the signal ?

EDIT:
If I can't trap the signals, maybe I can reassign the combination
 
Last edited:
Then where is the "true" association to the signal ?
Which signal? Not all signals have associated keys, as far as I know only Ctrl-C and Ctrl-Z do, sending SIGTERM and SIGSTOP respectively. All other signals are sent via the "kill" command.
 
Which signal? Not all signals have associated keys, as far as I know only Ctrl-C and Ctrl-Z do, sending SIGTERM and SIGSTOP respectively. All other signals are sent via the "kill" command.

I was speaking about CTRL-Z, in stty it's defined as "swtch", and you told that this command doesn't send a signal, BUT the combination indeed is sending a signal to stop a running program...

so there are 2 possibilities,
1) "swtch" sends a SIGTSTP
or
2) CTRL-Z is associated to SIGTSTP somwhere else
 
Then where is the "true" association to the signal ?
EDIT:
If I can't trap the signals, maybe I can reassign the combination

This is the subscript for the SUSP character in the special control character array. termios.c_cc[VSUSP] holds the character itself.
So it seems to be hardcoded and you may have to recompile your libc6 wich would be overkill.

If really needed, It should be easier to turn off job control in bash.
 
Well, I was trying to obtain this http://www.cyberciti.biz/faq/unix-linux-shell-scripting-disable-controlc/#more-4818
but for every needed combination

EDIT:
for example, I have some CLI programs where I can set some macros, like in midnight commander, but if I try to assign CTRL-Z the program will be stopped...
so I just want to ignore the common functions of those combinations while inside those programs, so I can use them for other purposes...
 
Last edited:
Back
Top