Keyboards, Consoles, and VT Cruising
Now that we're on a bit of a roll, let's look at another method for moving from one VT to another. The utility of being able to quickly switch from one VT to another should be obvious: you can be compiling a program on VT 1, editing a file on VT 2, reading program documentation on VT 3 and having a manual page displayed on VT 4. Now that you've re-mapped the keypad, switching from one VT to the next is as simple as pressing the keypad keys. But there are other handy means of getting around as well and these include:
Using the keysym functions Last_Console, Incr_Console and Decr_Console
Using the chvt program (which is part of the kbd package)
The Incr_Console and Decr_Console keysym functionsdo as their names imply: they switch to (VT + 1) or (VT - 1) respectively. So, if you were currently working at VT 3, the Incr_Console keysym would switch you to VT 4 while the Decr_Console keysym would switch you to VT 2. The Last_Console keysym also does as its name implies: it switches to the last VT used. If you were working at VT 3 and switched to VT 6, the Last_Console keysym would switch you back to VT 3. You can map a key or modifier+key combination to invoke any of these keysym functions. I've mapped these functions as follows:
Ctrl+left arrow = Decr_Console Ctrl+right arrow = Incr_Console keypad 0 = Last_Console
Obviously, you can map these functions in any manner you wish, but the relevant entries to map the above actions would be:
#keycode 82 = KP_0 keycode 82 = Last_Console shift keycode 82 = Console_10 alt keycode 82 = KP_0 [...] keycode 105 = Left alt keycode 105 = Decr_Console keycode 106 = Right alt keycode 106 = Incr_Console
These entries map the keypad 0 key to the Last_Console keysym and the alt- [left arrow] or [right arrow] to Decr_Console or Incr_Console keysyms. The good news is that these last two are already the default so that you have to edit only the stanza for the keypad 0 key. Now, you can quickly cycle through all the VTs by holding down the alt key and repeatedly pressing the left or right arrow. To alternate between two VTs you have only to repeatedly press the keypad 0 key. I've found these particular mappings to be quite useful but, as I mentioned before, they can be customized to anything you wish. The last bit of VT cruising magic is the chvt program included with the kbd package. Its use is quite simple:
$ chvt 3
would change to VT 3. Substituting another number for 3 allows you to change to that VT. A foreshortened version of this can be set up using a shell alias:
$ alias vt='chvt'
so that entering:
$ vt 3
would switch you to VT 3.
So, now that we've defined several methods of getting from VT to VT it is important to note that this works only at the console and not under the X Window System. Under X, the X server takes control of the keyboard, mouse, and display: setting up customized keyboard mappings is performed using the ~/.Xmodmap file or the program xkeycaps and is a subject for a later article.
Having the capacity to open multiple VTs and to have programs running on them in the foreground or background is one of the things that makes running Linux such a huge amount of fun. As the old Surgery Prof used to harangue his interns, “Help me, help me! If I had another set of hands I'd help myself!” Linux gives you that extra “set of hands”. Generally, most VTs, to be useful, must have a getty process running on them in order to log in. A getty is a program associated with a terminal that:
Opens the tty line and sets its mode.
Prints the login prompt and gets the user's name.
Initiates the login process for the user.
Without going into all the details (again, a subject for a later article), suffice it to say that this program is set up in the /etc/inittab file. An entry for a getty might look like Listing 3.
The important thing to note in this listing is that the agetty program is run on each of the tty devices from tty1 to tty6. Thus, at system startup there are a total of six gettys running, allowing you to log into VT 1 through 6. So what about VT 7 and beyond? Are they still usable in any way? If you've re-mapped your keyboard—try pressing keypad_7—alternatively, press alt-f7—and see what happens. In general, the screen is blank with the cursor positioned at the upper left corner. You can type at the keyboard, and the output is displayed on the screen. Despite this, there is no way to execute programs at this terminal. A terminal you can't log in on isn't much use. There are, however, two important exceptions to this statement.
Practical books for the most technical people on the planet. Newly available books include:
- Agile Product Development by Ted Schmidt
- Improve Business Processes with an Enterprise Job Scheduler by Mike Diehl
- Finding Your Way: Mapping Your Network to Improve Manageability by Bill Childers
- DIY Commerce Site by Reven Lerner
Plus many more.
- diff -u: What's New in Kernel Development
- Server Hardening
- Giving Silos Their Due
- What's New in 3D Printing, Part III: the Software
- 22 Years of Linux Journal on One DVD - Now Available
- Controversy at the Linux Foundation
- Don't Burn Your Android Yet
- February 2016 Issue of Linux Journal
- Firefox OS