Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I recently posted a question about terminals and this seemed like it deserved its own question. If the tty which would be synonymous with terminal, is just the device driver/device file itself, what provides the actual interface to the terminal, and what is it called? I don't mean the gui in any way, I mean the actual area (either in a virtual terminal or a possibly a psuedo-terminal) where text is being printed and read. Is this considered a part of the terminal? Are these in some way controlled by the kernel? Basically if someone wanted to write a console program, like gnome-terminal (or even with virtual terminals), is there some sort of kernel based widget/interface that takes input and output? Basically is the tty (itself i.e. /dev/tty) just a file or does it include the code needed to display output (in various colors and weights), and read from the keyboard.

Is this correct: I found here What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'? that is says tty is synonymous with terminal. This is what is confusing me. I would think that to emulate a terminal or to provide a terminal, would require the terminal driver (tty) and the terminal display and interactive part (something like xterm). So by itself the tty is simply a driver for input and output, and what displays and reads the text from and to the tty is something like xterm? Would be calling the "/dev/tty a terminal driver" also be correct? Also when I say xterm I mean the value of the $TERM var.

Another thought (let me know about this one): The tty file is synonymous with the connection between the terminal or these day terminal emulator, and the shell. Now they are all in the same box, but the original terminals would be the terminal emulators of today (clearly), but the tty or tty files would sort of act like the serial connection between the terminal and the shell/operating system. These days it seems like to me the terminal emulator is an environment/window for interacting with the /dev/tty... files and the shell sits at the other side? So writing to the /dev/tty file would be like writing to or reading form the serial port? I'm assuming this is not exactly how it works, any help would be greatly appreciated :-(.

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

Originally, "tty" had two definitions: the hardware (now the emulator) and the driver (interfaced through /dev/pty* or /dev/tty*).

The hardware/emulator was/is responsible for:

  • Taking a stream of data and presenting it; this included interpreting control sequences like "move cursor left", "blinking cursor", "clear-screen" although these control sequences were often different among manufacturers.
  • Sending keycodes for keys typed by the user; most of these were standard ASCII characters, but some terminals sent propriety keycodes for even standard keys.

The 'tty' driver was responsible for:

  • Managing the buffering, in raw or canonical mode; for example, buffering a line of characters until Enter is pressed.
  • Managing the control flow; e.g. being able to stop/continue with Cntl-s/Cntl-q.
  • Translating propriety keycodes to standard ASCII, where applicable.
  • Intercepting certain control characters (like Cntl-c and Backspace) and processing them appropriately (send SIGINT on a Cntl-c or signal an EOF on Cntl-d.
  • Canonical display of characters, for example, if echo is turned off, then do not send feedback (character typed) back to the terminal.

The terminfo and termcap databases managed what terminal control characters should be sent for an operation (like 'clear-screen'). These control sequences were/are not interpreted by the driver, but by the hardware/emulator.

share|improve this answer
add comment

In the case of console ttys ( /dev/ttyX ), the kernel driver handles displaying the output. In the case of gnome-terminal, it is in charge of displaying the output. The kernel just provides gnome-terminal with the master side of the master/slave psuedo terminal pair so that output to the psuedo terminal gets sent to gnome-terminal to display, and gnome-terminal can send input to the terminal for processes attached to it to read.

share|improve this answer
add comment

I think this link about covers it. Read the whole thing, it's awesome :-)

http://www.linusakesson.net/programming/tty/index.php -- It explains how the terminal (TTY) consists of the terminal driver, which helps controls the sessions, and the line discipline, which can control if set, specific line editing. If it is set in raw mode (line discipline) it can be over-ridden by something like read-line library. The terminal emulator in a way controls the processing of keyboard input and display. The terminal device file under /dev can be used to manipulate the line discipline and the driver. This is how I see it.

share|improve this answer
    
Please do not answer with just a link. Summarize the information directly in your answer. Keep the link for reference, but your answer should make sense even if the reader cannot or chooses not to follow the link. –  Gilles Dec 27 '11 at 23:41
    
I apologize for that, I didn't think I could write it as well as the author did, but I accepted Arcege's anyway. –  rubixibuc Dec 28 '11 at 1:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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