Wednesday, 24 October 2012

Linux for you Admin Tips: 8

Linux for you Admin Tips:1
Linux for you Admin Tips:2
Linux for you Admin Tips:3
Linux for you Admin Tips:4
Linux for you Admin Tips:5
Linux for you Admin Tips:6
Linux for you Admin Tips:7

What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?



I think these terms almost refer to the same thing, when used loosely:
  • terminal
  • shell
  • tty
  • console
What exactly do each of these terms refer to?
Ans::
In unix terminology, the short answer is that
  • terminal = tty = text input/output environment
  • console = physical terminal
  • shell = command line interpreter
tty is a particular kind of device file which implements a number of additional commands (ioctls) beyond read and write.


terminal is synonymous with tty. Some ttys are provided by the kernel on behalf of a hardware device

Other ttys, sometimes called pseudo-ttys, are provided (through a thin kernel layer) by programs called terminal emulators, such as Xterm (running in the X Window System),

The console appears to the operating system as a (kernel-implemented) tty. On some systems, such as Linux and FreeBSD, the console appears as several ttys,the name given to each particular tty can be “console”, ”virtual console”, ”virtual terminal”, and other variations.

shell is a special program that interacts with a user through a controlling ttyand offers

The division of labor between the terminal and the shell is not completely obvious. Here are their main tasks.

  • Input: the terminal converts keys into control sequences (e.g. Left → \e[D). The shell converts control sequences into commands (e.g. \e[D → backward-char).
  • Line edition, input history and completion are provided by the shell.
    • The terminal may provide its own line edition, history and completion instead, and only send a line to the shell when it's ready to be executed. The only common terminal that operates in this way is M-x shell in Emacs.
  • Output: the shell emits instructions such as “display foo”, “switch the foreground color to green”, “move the cursor to the next line”, etc. The terminal acts on these instructions.
  • The prompt is purely a shell concept.
  • The shell never sees the output of the commands it runs (unless redirected). Output history (scrollback) is purely a terminal concept.
  • Inter-application copy-paste is provided by the terminal (usually with the mouse or key sequences such as Ctrl+Shift+V or Shift+Insert). The shell may have its own internal copy-paste mechanism as well (e.g. Meta+W and Ctrl+Y).
  • Job control (launching programs in the background and managing them) is mostly performed by the shell. However, it's the terminal that handles key combinations like Ctrl+C to kill the foreground job and Ctrl+Z to suspend it.

No comments:

Post a Comment