Questions tagged [pty]

Pseudoterminals (also spelled “pseudotty” or “PTY”) are pseudo-devices used with ttys whose emulators run in userspace. Use the [tty] tag for broad (text terminal)-related questions, and the [console] tag for terminal devices pertaining to the system console.

Filter by
Sorted by
Tagged with
51
votes
7answers
11k views

How to trick a command into thinking its output is going to a terminal

Given a command that changes its behaviour when its output is going to a terminal (e.g. produce coloured output), how can that output be redirected in a pipeline while preserving the changed behaviour?...
74
votes
4answers
18k views

What are the responsibilities of each Pseudo-Terminal (PTY) component (software, master side, slave side)?

I am trying to figure out how a tty works1 (the work-flow and responsibilities of each elements). I have read several interesting articles about it, but there are still some blurry areas. This is ...
85
votes
3answers
101k views

What is stored in /dev/pts files and can we open them?

According to my knowledge, /dev/pts files are created for ssh or telnet sessions.
6
votes
1answer
3k views

How do I come by this pty and what can I do with it?

It seems that a simple shell redirect from /dev/ptmx gets me a new pseudo-terminal. $ ls /dev/pts; ls /dev/pts </dev/ptmx 0 1 2 ptmx 0 1 2 3 ptmx It disappears as soon as the process that ...
28
votes
3answers
6k views

How can we know who's at the other end of a pseudo-terminal device?

If I do a: echo foo > /dev/pts/12 Some process will read that foo\n from its file descriptor to the master side. Is there a way to find out what that(those) process(es) is(are)? Or in other ...
4
votes
3answers
1k views

How can we find out the pseudoterminal master and slave from each other?

A pseudoterminal has a pair of master and slave. How can we find out the master device file from a slave device file (e.g. /etc/pts/3)? I only find /dev/ptmx and /dev/pts/ptmx, but they can't be ...
0
votes
2answers
1k views

How are long command lines ( > $COLUMNS ) automatically wrapped to a new line?

There are several points where I/O is passed through, some of which (to my knowledge) are the shell, pty, tty, termios, terminal emulator application. In most terminal emulators, long command lines (...
21
votes
1answer
3k views

What does 'script /dev/null' do?

Every time I log into a VM with root, su into a user account, and try to use screen it throws an error: Cannot open your terminal '/dev/pts/0' - please check. A Stack Overflow post said I needed to ...
1
vote
2answers
895 views

Do the output of command `tty` and the file `/dev/tty` both refer to the controlling terminal of the current bash process?

From man tty tty - print the file name of the terminal connected to standard input $ tty /dev/pts/2 From APUE: Historically, the name of the controlling terminal in most versions of the UNIX ...
114
votes
3answers
76k views

What are pseudo terminals (pty/tty)?

This might be really basic question but I want to understand it thoroughly. What is a pseudo terminal? (tty/pty) Why do we need them? How they got introduced and what was the need for it? Are they ...
33
votes
2answers
17k views

How does a Linux terminal work?

If you fire up a terminal and call an executable (assuming one that's line oriented for simplicity) you get a reply to the command from the executable. How does this get printed to you (the user)? ...
4
votes
1answer
2k views

Mocking a pseudo tty (pts)

We would like to run some curses based apps in background. These apps use curses and get the current tty port name to be used internally to map log files and others context-terminal associations. ...
4
votes
1answer
4k views

How can I fix /dev/pts after mounting it?

I made the same mistake as in this question: Debian chroot blocking PTTYs on host I mounted a "devpts" filesystem inside a chroot, and now urxvt can't create ptys. Oddly enough xterm still can. ...
3
votes
0answers
84 views

Can terminal parameter changes on the slave side be detected on master?

A process (creator) creates a pseudo-terminal master/slave[/dev/pts/1] pair. Another process (consumer) opens /dev/pts/1 and changes the serial terminal parameters with tcsetattr. Is there a way for ...
10
votes
3answers
13k views

What is the difference between **pts** and **tty** and **:0**?

Please help me to distinguish pts from gui mode generated from tty. booting to multi-user.target I did this: sudo systemctl set-default multi-user.target reboot login with regular user ...
4
votes
1answer
1k views

Where does `/dev/pts/ptmx` come from? [duplicate]

On my Archlinux, /dev/pts is mounted by the devpts, so who created the /dev/pts/ptmx device node? What's the purpose of this node? it's the same (Major=5 Minor=2) device node same as /dev/ptmx/, but ...
6
votes
1answer
530 views

Does the process on the slave side of a pty talks to the line discipline or to the slave tty driver?

I have found two contradictory images of how a pseudo terminal (pty) works. The first image shows that the process on the slave side of a pty talks to the line discipline: The second image shows ...
13
votes
1answer
779 views

Why are two ^D presses necessary to exit `cat`? [duplicate]

Let's run cat and then type a then ^D - you will see that cat did not exit. Compare it with cat + a + Enter + ^D - now cat did exit. So, why two ^D presses are necessary to exit cat in the first ...
5
votes
1answer
2k views

What is the maximum allowed number of TTY, is it defined anywhere in kernel headers?

What's the maximum allowed number of TTYs? I found pty.max, but is there anything similar for TTYs? Or is it defined as a fixed value in kernel headers, I couldn't find that
2
votes
1answer
549 views

read(2) blocking behaviour changes when pts is closed resulting in read() returning error: -1 (EIO)

I'm trying to figure out how I can reliably loop a read on a pt master I have. I open the ptmx, grant and unlock it as per usual: * ptmx stuff */ /* get the master (ptmx) */ int32_t masterfd = open("/...
2
votes
1answer
434 views

Why are some pts in AIX never reused?

In an AIX system (AIX p740 1 7) that is running for about several months, some pts aren't reused anymore. This was noticed using the "who" command, with the following "awk" expression, running it ...
2
votes
1answer
201 views

PTY master missing read function

How can terminal emulator read from ptm device while it missing read function? There is a PTY driver: https://github.com/torvalds/linux/blob/master/drivers/tty/pty.c. I see pty_write function, but can'...
1
vote
1answer
2k views

Using cron to start a process on a terminal without using screen?

I want to start a process in a terminal using cron. I want the process to start in a terminal, so that I can continuously see the output of the process on the terminal, and kill it / restart it etc. I ...
1
vote
2answers
342 views

Why does Fedora have two `ptmx` files?

I know that the file /dev/ptmx is used to generate a master file for a pseudo-terminal. But I have found out that Fedora has another ptmx file (/dev/pts/ptmx): What is the purpose of this second file?...
1
vote
2answers
118 views

Does the master device appear just like a standard terminal to the driver program?

From the Linux Programming Interface The key point about a pseudoterminal is that the slave device appears just like a standard terminal. All of the operations that can be applied to a terminal ...
0
votes
1answer
345 views

When tmux exits (closes pty master), background processes from startup scripts die — why?

I'm having difficulty understanding an answer I received to a question I posed about tmux — specifically, re: what the pseudoterminal does with child processes when it exits. Original Question I ...
0
votes
2answers
246 views

How to get the opened pty for a given background process (without login) in AIX

Using this answer https://unix.stackexchange.com/a/283521/114939 which allow us to find processes that keep an given pty opened without login (who command cannot show them), caused me to ask the ...