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.

This might be really basic question but I want to understand it thoroughly.

  1. What is a pseudo terminal? (tty/pty)
  2. Why do we need them? How they got introduced and what was the need for it?
  3. Are they outdated? Do we not need them anymore? Is there anything that replaced them?
  4. Any useful use-case?

What I did:

  1. Read man pages - got some info but not exact picture.
  2. Tried to read on them from Network programming by Richard Stevens. - Got some info but not the why? part.

Any help/pointer is greatly appreciated.

share|improve this question

migrated from stackoverflow.com Sep 21 '11 at 6:36

This question came from our site for professional and enthusiast programmers.

    
I think so, too, especially if no specialized issues like openpty/forkpty arise here. –  thiton Sep 20 '11 at 18:31
    
Tried to flag it for migration, but Linux/Unix is not a valid migration target. Trying gradient descent, Super User is already a slightly better target than this site, and maybe they can route it to an even better site. –  thiton Sep 20 '11 at 19:25
3  
This is a pretty good overview: linusakesson.net/programming/tty/index.php –  nos Sep 20 '11 at 20:00
    
@nos : wow! Thats an awesome link. The thing that I was looking for. Thanks a ton :) –  hari Sep 20 '11 at 20:06

3 Answers 3

up vote 11 down vote accepted
  1. A device that has the functions of a physical terminal without actually being one. Created by terminal emulators such as xterm. More detail is in the manpage pty(7).
  2. Traditionally, UNIX has a concept of a controlling terminal for a group of processes, and many I/O functions are built with terminals in mind. Pseudoterminals handle, for example, some control characters like ^C.
  3. They are not outdated and are used in many programs, including ssh.
  4. ssh.
share|improve this answer
    
Thanks @thiton. Can you please elaborate on your example of ssh? How does it use pty/tty? How does master/slave role play in ssh? –  hari Sep 20 '11 at 18:17
1  
ssh allocates a pty for the shell it creates. The shell is connected to the slave end and thereby can rely on all the capabilities of a normal terminal (e.g. termcap if I remember correctly), and the ssh daemon connects to the master end and sends and receives its input there. –  thiton Sep 20 '11 at 18:24

Pseudo-terminals are emulators for serial lines. They provide endpoints for telnet, ssh, and xterm shells.

share|improve this answer
    
And they're ancient relics (really, shells/text applications are still interacting over a device that emulates a tele-type writer over a serial line like they worked 40 years ago...) We still need them because there is no replacement :-( –  nos Sep 20 '11 at 17:55
    
Well, if you consider the terminal, I don't think you need much more than a stream of letters comming and going... –  Diego Sevilla Sep 20 '11 at 17:59
    
@Diego Sevilla The original unix inventor did away with tty/ptys in Plan 9 , and there a terminal pretty much does just use a stream of in/out data. But in *nix, the ttys are still around and used by consoles and terminal emulators to e.g. control terminal size, flow control, line buffering, special key events, and other stuff. –  nos Sep 20 '11 at 18:06

The answer is in the name -- "Pseudo" meaning "not genuine but having the appearance of".

With the first terminals, there was always a piece of hardware attached with associated device, be it display hardware or a serial port.

With xwindows, telnet and ssh, there came a need for software "Pseudo devices" to do the job of standing in for display hardware. They are "Pseudo Terminals" ... software that emulates Terminal hardware, handling input and output in the same way a physical device would so that the software connected is not aware there's not a real device attached.

share|improve this answer
    
Because now we have many applications which need to access same piece of hardware, every app is using the hardware via "pseudo" terminal? –  hari Sep 20 '11 at 18:15
    
I expanded the answer a bit -- hope it clarifiies. –  gview Sep 20 '11 at 18:29
    
No, we just don't actually have that kind of hardware around anymore. xterm emulates a classic terminal, that's all. –  thiton Sep 20 '11 at 18:29
    
@thiton: When you say emulates, thats the software part, isn't it? –  hari Sep 20 '11 at 18:48
    
@hari: Yes, it is. A pseudo terminal has no hardware components. –  thiton Sep 20 '11 at 19:17

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.