4

I am trying to clarify my understanding of terminal here.

Terminal is actually a device (keyboard+monitor). When in CLI mode, the input from your keyboard goes directly to shell and also displayed on monitor.

Meanwhile, when using GUI mode, you have to open terminal emulator program to interact with shell. The input from your keyboard goes to terminal emulator program and also displayed on terminal emulator window on monitor. The input does not directly goes to shell. The terminal emulator program will relay the input from your keyboard to shell. The terminal emulator program communicates with the shell using pseudo-terminal.

There is no terminal emulator program involved when you go straight to CLI from boot.

Please comment and correct me if anything wrong with my understanding.

Update: I read back TTY demystified. I think what I should ask is the difference between text terminal (boot straight to text mode) and GUI terminal because I thought terminal=text terminal, terminal emulator=GUI terminal e.g. Gnome Terminal, which are wrong. From the answers in regards to before this update, a user is actually using terminal emulator program (user space) too like in GUI mode. May I know is it TTY program because I found TTY process when running command 'ps aux'. I never knew there is terminal emulator program involved too (not referring to terminal emulator in kernel space) in text mode.

Update2: I read Linux console. According to it, text mode is console, meanwhile terminal software in GUI mode is terminal emulator. Well, it makes sense and it is same with my understanding before. However, according diagram from TTY demystified, terminal emulator is in the kernel space instead of user space. Interestingly, the diagram refers to text mode.

marked as duplicate by Michael Homer, muru, Archemar, Anthon, Thomas Dickey Jan 10 '16 at 11:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @MichaelHomer, also see terminal emulator vs terminal from our sister site, AU. – user1717828 Jan 10 '16 at 7:05
  • Please ask a new question explaining exactly what you want to know and how the duplicate didn't answer it. – terdon Jan 10 '16 at 12:17
6

There are a few separate terms here that need to be independently defined:

Terminal: A real keyboard/monitor interface, like the VT100: https://en.wikipedia.org/wiki/VT100

Terminal emulator(TTY): Emulates a terminal, providing input and output. Press ctrl+alt+F2 in most Linux distros, and you'll be in one. Type "w" in the terminal, and you'll see your w command run by a "tty".

Pseudo-Terminal(PTY): A master/slave pair (ptmx) in which some other piece of software like ssh or a GUI terminal provide a terminal-like interface through a slave (pts). http://linux.die.net/man/4/ptmx Type "w" in a GUI terminal, and you'll see the w command listed as coming from a pts.

Shell: A command line interpreter which is run on login, and interprets your input. Examples of this are bash/zsh.

However, please keep in mind that these terms have all become interchangeable in conversation. When someone refers to the "terminal", "terminal emulator", "console", "command line", or "shell", unless context specifies otherwise, they are probably referring more generally to:

"That text-based thing with which I control some computer."

Edit for question update

See below for all processes matching pts or pty:

root@localhost tests]# ps fauxww | grep -P [pt]t[ys] 
root      2604  2.3  0.8  50728 34576 tty1     Ss+  07:09   1:15      \_ /usr/bin/Xorg :0 -br -verbose -audit 4 -auth /var/run/gdm/auth-for-gdm-VRHaoJ/database -nolisten tcp vt1
root      2569  0.0  0.0   2008   500 tty2     Ss+  07:09   0:00 /sbin/mingetty /dev/tty2
root      2571  0.0  0.0   2008   500 tty3     Ss+  07:09   0:00 /sbin/mingetty /dev/tty3
root      2573  0.0  0.0   2008   504 tty4     Ss+  07:09   0:00 /sbin/mingetty /dev/tty4
root      2575  0.0  0.0   2008   500 tty5     Ss+  07:09   0:00 /sbin/mingetty /dev/tty5
root      2577  0.0  0.0   2008   504 tty6     Ss+  07:09   0:00 /sbin/mingetty /dev/tty6
sin       3374  0.2  0.7  90668 28564 ?        Sl   07:13   0:09 /usr/bin/python /usr/bin/terminator   <<< Added this parent of 3377 manually to see the pts source
sin       3377  0.0  0.0   2076   620 ?        S    07:13   0:00  \_ gnome-pty-helper
sin       3378  0.0  0.0   5236  1712 pts/0    Ss   07:13   0:00  \_ /bin/bash
root      4054  0.0  0.0   5124  1676 pts/0    S    07:23   0:00  |       \_ bash
root      5034  0.0  0.0   5056  1092 pts/0    R+   08:03   0:00  |           \_ ps fauxww
root      5035  0.0  0.0   4416   740 pts/0    S+   08:03   0:00  |           \_ grep -P [pt]t[ys]
sin       4154  0.0  0.0   5236  1708 pts/1    Ss   07:23   0:00  \_ /bin/bash
sin       4485  0.0  0.0   7252  3500 pts/1    S+   07:41   0:00      \_ python

You'll see both pts and tty related processes. You assume that because you see tty in ps, this is the thing your GUI terminal is using, but it's not. In this case, the mingetty TTY processes are all the ones I can use with ctrl+shift+F2-6, and the pty are slaves related to my GUI terminal process. To see for sure, check lsof of your GUI terminal's process:

[root@localhost tests]# ps fauxww | grep terminator
sin       3374  0.2  0.7  90668 28564 ?        Sl   07:13   0:08 /usr/bin/python /usr/bin/terminator
[root@localhost tests]# lsof -p 3374 | grep '[pt]t[ys]'
/usr/bin/ 3374  sin   17u   CHR      136,0      0t0      3 /dev/pts/0
/usr/bin/ 3374  sin   25u   CHR      136,1      0t0      4 /dev/pts/1

When you boot into text mode, you're going into a TTY just like if you press ctrl+alt+f2 from the desktop. When you use SSH/GUI terminals, you're using a pseudo-terminal.

  • I have just updated my question. – Ron Vince Jan 10 '16 at 9:49
  • This is my current understanding. Terminal emulator is a code in kernel space. So, it is used both in text and GUI modes. In text mode, the terminal emulator mostly interacts with shell. In GUI mode, the terminal emulator interacts with X11. I wonder why GUI program like Gnome terminal is called terminal emulator too. – Ron Vince Jan 11 '16 at 14:25
  • Perhaps it would clarify the question to provide the output that is leading you to these conclusions. lsof -p $pid will show you all the files a process (including your terminal) has open. – Brandon DuPree Jan 11 '16 at 23:38
  • No output, but based on my (limited?) knowledge about linux kernel and this diagram linusakesson.net/programming/tty/case3.png – Ron Vince Jan 12 '16 at 12:40
  • New update in the question. – Ron Vince Jan 12 '16 at 13:04
2

A (display) terminal is a piece of hardware which has a keyboard and display, and communicates with a host computer. The terminal is itself a small computer; an embedded system.

A terminal emulator is software running on a general-purpose machine which implements the behavior of some terminal.

Terminal emulators are not all graphical. They can be based on a text display mode. An example of this is the console in the Linux kernel.

Terminal emulators can also use terminal emulation themselves. An example of this is the GNU Screen program. It requires a terminal, but provides terminal emulation to programs running under it.

Terminal emulators can run in a host computer in order to provide a virtual terminal to access that host computer itself. The piece of software running no the host looks to that same host as an attached remote terminal. But terminal emulators can also be used to simply use the computer as a terminal to access some remote host. An example of this is, say, using an IBM 3270 emulator running under Windows on a PC to access a mainframe. It's an emulator because you're using a piece of software under Windows and not an actual 3270 on your desk. But you're not using that to access the Windows command line. Another example of this kind of terminal emulator is a serial communication package like Minicom, Hyper Terminal and so forth. Also, the popular PuTTY SSH client.

  • I have just updated my question. – Ron Vince Jan 10 '16 at 9:49
  • New update in the question. – Ron Vince Jan 12 '16 at 13:05
  • I don't have anything to change. The text mode in the linux kernel is an emulator. When you print VT100-like escape sequences to a console device, code in the kernel intercepts them and turns them into various actions. Since the Linux kernel isn't a VT100 hardware unit from Digital Equipment Corporation, it must be emulating one. QED. Moreover, you can use Linux as an emulator to access a remote host. Log into your Linux via text console, then telnet or ssh somewhere. The terminal codes from the remote host are interpreted by the console, so you're able to do "full screen stuff". – Kaz Jan 12 '16 at 18:11

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