What are ptmx, pts

Pseudoterminals are virtual devices in UNIX-like systems that simulate the behavior of an actual physical terminal (a TTY). Search for VT220 for images or go here to read about the origin of a terminal.

My understanding is that pseudoterminals allow you to create multiple virtual terminals from a single physical terminal (or a TTY in modern days).

For example (I’ve thought of doing this), if you were to have a Unix-like machine without any GUI and you were to boot up that machine. Say you wanted to work on that machine without any GUI but you need to have multiple terminals available in a single monitor. You would use pseudoterminals.

From the man pages: The file /dev/ptmx (the pseudoterminal multiplexor device) is a character file with major number 5 and minor number 2, usually with mode 0666 and ownership root:root. A character file with major number 5 and minor number 2. From the devices list:

5 char	Alternate TTY devices
	  0 = /dev/tty		Current TTY device
	  1 = /dev/console	System console
	  2 = /dev/ptmx		PTY master multiplex
	  3 = /dev/ttyprintk	User messages via printk TTY device
	 64 = /dev/cua0		Callout device for ttyS0
		...
	255 = /dev/cua191	Callout device for ttyS191

	(5,1) is /dev/console starting with Linux 2.1.71.  See
	the section on terminal devices for more information
	on /dev/console.

When is it beneficial to use a pseudoterminals?

  • Automate terminal interactions
  • Remote access
  • Multiple terminal sessions
  • Need flexibility with testing, scripting, and remote management tasks

References

https://man7.org/linux/man-pages/man4/pts.4.html https://linux.die.net/man/7/pty https://www.lenovo.com/us/en/glossary/pseudoterminal/