I'm trying to understand how the programs like screen and script control I/O.

My knowledge of terminal, tty etc. comes from reading the 'tty demystified' article, and all the SE answers I could find. So from what I understand, roughly the interactions between components work as follows:

Console(Keyboard+Screen) ---- xterm(pty master) ----- tty line discipline ---- bash/other programs(pty slave)

where the line discipline is in the kernel, and xterm and bash run in the userspace.

  1. Is this correct?

Now, when we consider programs like screen, script, they are userspace programs that run in a terminal(the existing xterm), yet are able to control I/O to/from other programs. The article mentions that this is becuase they run another pseudoterminal inside xterm(the existing pseudoterminal).

  1. Does that mean that they open up a new pty master - slave pair, control the master end of this new pair, and all the processes launched from them run on the new pty slave? For example each time I start a new 'screen', and run the tty command, it shows me a diffrent /dev/pts/x. Does script also run in a similar way?

  2. Finally can somebody point me to any article/book where I can get a little more detail on this stuff(Haven't been able to find anything)?

I'd also like to reference this answer, though it is very brief.

1 Answer 1


① Yes, xterm and bash run in userspace. As do screen and script.

② Yep, that's correct. Screen basically is a terminal emulator, just like XTerm. Except of course XTerm outputs commands to the X11 server to display the terminal, whereas screen outputs control sequences & text to a another terminal (which can be a terminal emulator or an actual terminal).

③ The best detail on how those programs work is probably the source code. Questions about them are welcome here, of course, or code questions are welcome on Stack Overflow.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .