I am looking for an explanation of what happens in Linux when this key combination is pressed to change the current terminal. In particular, what software component intercepts this key combination and changes the terminal? Is it the kernel? If it is the kernel, could you provide the location of the source file which handles this?
Edit:
I want to understand how this works in both a graphical (X11) and text-based environment.
Best Answer
It is the kernel. Keep in mind the keyboard is hardware and everything that happens there passes through the kernel; in the case of VT switching, it handles the event completely itself and does not pass anything on to userspace (however, I believe there is an ioctl related means by which userspace programs can be notified of a switch occurring involving them and perhaps affect it, which X no doubt does).
The kernel has a keymap build into it; this can be modified while running with
loadkeys
, and viewed withdumpkeys
:The kernel source contains a default keymap file which looks exactly like this; for 3.12.2 it's
src/drivers/tty/vt/defkeymap.map
. You'll also notice there is a corresponding defkeymap.c file (this can be generated withloadkeys --mktable
). The handling is inkeyboard.c
(all these files are in the same directory) which callsset_console()
fromvt.c
:I edited some hits out of that list; you can see the function signature on the second last line.
So these are the things involved in the switching. If you look at the sequence of calls, eventually you come back to
kbd_event()
inkeyboard.c
. This is registered as an event handler for the module:(3.12.2
drivers/tty/vt/keyboard.c
line 1473)Hence,
kbd_event()
should be called when something bubbles up from the actual hardware driver (probably something fromdrivers/hid/
ordrivers/input/
). However, you won't see it referred to askbd_event
outside of that file, since it is registered via a function pointer.Some resources for scrutinizing the kernel
printk
lines into the source as a simple means of tracing (not all of the standard C lib can be used in kernel code, including printf from stdio). printk stuff ends up in syslog.Wolfgang Mauerer wrote a great big book on the 2.6 kernel, Professional Linux Kernel Architecture, which goes through a lot of the source. Greg Kroah-Hartman, one of the principle devs for the last decade, also has a lot of things kicking around.