0

The TTY subsystem contains the TTY driver, line discipline(s) and hardware drivers (keyboard driver, display driver). Let's say I use a virtual terminal/console. So, my current session uses ‍/dev/tty1 (TTY device 1). When I press Ctrl+Alt+F2, I open another session which now uses /dev/tty2 (TTY device 2).

So, who controls which /dev/ttyN is the active one?  Line discipline?

How about output from inactive /dev/ttyN?  Input from process attached to it cannot be output to line discipline because it is an inactive tty.  So, input from process will just be dropped?

closed as too broad by Thomas Dickey, Jakuje, Archemar, cuonglm, PersianGulf Mar 12 '16 at 13:58

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • How do keyboard input and text output work? addresses some of this, but it focuses on X Windows and ssh, and ignores lines disciplines and virtual consoles. What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'? is canonical background reading. – G-Man May 18 at 3:47
  • The tty subsystem make use of keyboard/framebuffer driver, which is not part of it. Each running ttyN has bunch of states including its output buffer, input buffer, line discipline states etc, an activated ttyN write to framebuffer and read from keyboard when some process write/read it. Non-actived ttys don't do this but still has working output/input buffers. – 炸鱼薯条德里克 May 19 at 3:28
  • Also notice that tty drivers also control pesudo-terminals slave side, which is not completely the same as tty, the another side -- master side of pesudo-terminals -- is controlled by userspace, which may not directly read from keyboard device or write directly to framebuffer – 炸鱼薯条德里克 May 19 at 8:48
3

Without OP specifying a particular system, the advice has to be generic.

For a terminal emulator, the most common configuration uses pseudo-terminals. As a rule, those do not use the /dev/ttyXX naming convention:

  • Before Unix98, the BSD pseudo-terminal naming convention was predominant, using names such as /dev/ttypXX (master) and /dev/ptypXX (slave). You can see some variants in xterm's ptyx.h header.
  • With Unix98, some of the other variants were consolidated, and library interfaces provided to reduce the need for special device names in programs. The most common form allocates slave devices under /dev/pts.

In contrast, a /dev/ttyXX name usually refers to a (more or less) real console. With Linux, those names are virtual consoles, not related to pseudoterminals. A terminal emulator would not be connecting to those. But you can have active sessions on each of those virtual consoles.

Further reading:

Line discipline is a different aspect from "active connection". A terminal emulator does have to initialize the connection to use it, but once initialized, it will stay active until one end of the connection is dropped.

Further reading:

In regard to selecting a particular /dev/ttyXX device, you should look at a terminal server.

  • OS is ubuntu server 14.04. – Ron Vince Mar 12 '16 at 12:11

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