What is pts in linux

Difference between pts and tty

I always see pts and tty when I use the who command but I never understand how they are different? Can somebody please explain me this?

2 Answers 2

A tty is a native terminal device, the backend is either hardware or kernel emulated.

A pty (pseudo terminal device) is a terminal device which is emulated by an other program (example: xterm , screen , or ssh are such programs). A pts is the slave part of a pty.

(More info can be found in man pty .)

Short summary:

A pty is created by a process through posix_openpt() (which usually opens the special device /dev/ptmx ), and is constituted by a pair of bidirectional character devices:

  1. The master part, which is the file descriptor obtained by this process through this call, is used to emulate a terminal. After some initialization, the second part can be unlocked with unlockpt() , and the master is used to receive or send characters to this second part (slave).
  2. The slave part, which is anchored in the filesystem as /dev/pts/x (the real name can be obtained by the master through ptsname() ) behaves like a native terminal device ( /dev/ttyx ). In most cases, a shell is started that uses it as a controlling terminal.

Thanks. I take it that’s a historical reference as opposed to contemporary use i.e. it used to be backed by hardware.

Oldish thread but here’s my 2 cents. When hardware was much more expensive, companies would have a central, multi-user system (Unix, Mainframe, etc) with a bunch of connected «dumb» terminals. These just had a screen and keyboard and very simple logic that only knew how to send keystrokes down the wire to the server and to receive screen updates. All actual processing was done on the server. This is what is meant by «backed by hardware». Once personal computers came around, «terminal emulators were created to emulate these dumb terminals and allow someone with a PC to interact with the server.

Источник

what is pts/0 and (:0.0) in linux when typing who am i

The pts/0 is telling you which «pseudo terminal» the user is logged in on. In this case it’s terminal #0. The «(:0.0)» tells you which hostname and display you’re using.

Читайте также:  Linux как посмотреть ram

who am i is an alias of command who -m . See the man page for who. You can also read about the who command here.

The output can definitely be confusing to a Unix novice.

examples

shows -m is same as am i

[root@grinch]$ who am i root pts/4 2013-04-12 07:10 (greeneggs.mydom.net) [root@grinch]$ who -m root pts/4 2013-04-12 07:10 (greeneggs.mydom.net) 

connected to some remote system

[sam@munger ~]$ who am i sam pts/0 2013-04-12 07:19 (192.168.1.7) 

locally on my laptop

[saml@greeneggs ~]$ who am i saml pts/1 2013-04-11 16:41 (:0.0) 

The last bit that still might be confusing you is the :0.0 . This is how X Windows represents the «display» a user is on. The first «0» says which monitor/device you’re on, the second «0» says which virtual display you’re on.

This harks back to the days when computers were expensive and so multiple people might be working on the same computer all at the same time. I wouldn’t worry about it, just remember that it’s either going to be «:0.0» or possibly «:0». The environment variable «DISPLAY» and the command xhost make use of the «:0.0» value.

You can read more about remote displaying in Unix here.

whoami vs. who am i

Aren’t they the same command? No they’re different:

[saml@grinchy ~]$ ls -l /usr/bin/who /usr/bin/whoami -rwxr-xr-x 1 root root 49432 Nov 3 2010 /usr/bin/who -rwxr-xr-x 1 root root 26280 Nov 3 2010 /usr/bin/whoami 

Also their output is completely different; whoami just shows you your effective userid while who am i shows you connection info about your terminal:

[saml@grinchy ~]$ who am i saml pts/0 2013-04-11 16:41 (:0.0) [saml@grinchy ~]$ whoami saml 

Источник

What Is Dev/Pts in Linux

Dev/pts is a pseudoterminal stimulated by programs like Telnet and SSH. Since the advent of Microsoft Windows, Linux is only used as an additional operating system instead of a sole or primary OS. That’s why there is a need for pseudoterminals to use the UNIX and Linux programs. Dev/pts files store information related to the connected devices through Linux in special directories.

When devices like the keyboard and mouse are directly connected to the computer through serial ports, the connection is called TTY. Read this guide if you are curious about the /dev/pts. In this guide, we will explain about /dev/pts in Linux.

Читайте также:  Creating users and groups in linux

What Is /dev/pts in Linux?

The /dev/pts signifies the master files related to the pseudoterminal slave or a master, and the system saves it as /dev/ptmx. You can open the descriptors of these master files using the grantpt and unlockpt commands.

Applications such as xterm and Telnet help fool the Linux operating system that it is running on a dummy terminal when it is used along with another OS like Windows. The program data is presented to the files like it is run on an actual terminal by using the data to the slave file as input for the master file.

This process is stored in directories listed as the dev/pts file system in Linux that aids the functioning of such pseudoterminals. If you stop with /dev, it signifies an ordinary file directory in the regular flow of files. But if you use the /dev/pts, it is associated with the special directory available only in the kernel created by Linux. Every unique terminal window is related to a Linux pts entry in the /dev/pts system.

Use the “w” command to view the pseudoterminal to which the application is connected. Here, you can get the details about the concerned applications through which the pseudoterminal is connected:

The devpts file directory has different mounts of files in such a manner that each mount has different indices according to the assigned pts and is unique from one another.

You can also use the mount command to verify whether the dev/pts files are mounted in Linux.

There are many kinds of pseudoterminals applications that you can use for Linux, such as GUI terminals inclusive of xterm and console, remote shell applications, and multiplexer applications.

A single pseudoterminal can receive multiple outputs from different programs at a time. Multiple programs routing to the same terminal for reading would confuse the multiple inputs.

It is essential to understand that the files stored virtually in the /dev/pts directories are abstract and not real files. The data related to the programs on execution are stored temporarily while the pseudoterminals are in use. If you open the /dev/pts as files, it would usually be less useful.

Sometimes, it is possible that the command system is not suitable for mounting the devpts files. You can see if the file systems are listed in the output after running the following command:

Читайте также:  Tracert linux red hat

If your Linux kernel does not support this system, you can download the latest version that supports the dev/pts files.

Conclusion

The /dev/pts is a special virtual temporary file directory unique to the Linux system while running the programs through pseudoterminals. While these files do not necessarily store permanent records of related data, they contribute by associating the reading or writing a program in each terminal and storing the crucial information for successfully running the programs through pseudoterminals.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.

Источник

What does «pts/» in the output of w mean?

The file /dev/ptmx is a character file with major number 5 and minor number 2, usually of mode 0666 and owner.group of root.root. It is used to create a pseudoterminal master and slave pair.

When a process opens /dev/ptmx, it gets a file descriptor for a pseudoterminal master (PTM), and a pseudoterminal slave (PTS) device is created in the /dev/pts directory. Each file descriptor obtained by opening /dev/ptmx is an independent PTM with its own associated PTS, whose path can be found by passing the descriptor to ptsname(3).

Before opening the pseudoterminal slave, you must pass the master’s file descriptor to grantpt(3) and unlockpt(3).

Once both the pseudoterminal master and slave are open, the slave provides processes with an interface that is identical to that of a real terminal.

Data written to the slave is presented on the master descriptor as input. Data written to the master is presented to the slave as input.

In practice, pseudoterminals are used for implementing terminal emulators such as xterm(1), in which data read from the pseudoterminal master is interpreted by the application in the same way a real terminal would interpret the data, and for implementing remote-login programs such as sshd(8), in which data read from the pseudoterminal master is sent across the network to a client program that is connected to a terminal or terminal emulator.

Pseudoterminals can also be used to send input to programs that normally refuse to read input from pipes (such as su(1), and passwd(1)).

They’re usually xterminal/gnome-terminal/terminator sessions.

Источник

Оцените статью
Adblock
detector