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.

A pseudoterminal (also spelled “pseudotty” or “PTY”) is a pair of character pseudo-devices.

One of which, the slave, provides access to (emulated) text terminal for programs (console applications) and can have attached processes. Respective special files lie in /dev/pts/ (in modern Unix98-compliant OSes) or have /dev/tty[p-za-e][0-9a-f] names for compatibility with older software.

Second, the master, is an endpoint for the terminal emulator that runs in userspace. Respective special files is either one /dev/ptmx multiplexer (in modern Unix98-compliant OSes) or have /dev/pty[p-za-e][0-9a-f] names for compatibility with older software.

113 questions
159
votes
3 answers

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 outdated? Do we not need them anymore? Is there…
hari
  • 2,400
  • 4
  • 21
  • 22
106
votes
3 answers

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.
user2720323
  • 3,549
  • 7
  • 24
  • 26
90
votes
4 answers

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 workflow and responsibilities of each element). I have read several interesting articles about it, but there are still some blurry areas. This is what I understand so far: The emulated terminal makes…
Pierre-Jean
  • 2,229
  • 1
  • 15
  • 18
76
votes
7 answers

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? There must be a utility for that, which I am…
Amir
  • 1,531
  • 1
  • 14
  • 18
37
votes
2 answers

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)? Does the terminal do something like pexpect? (poll…
mike
  • 473
  • 1
  • 5
  • 6
29
votes
3 answers

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 words, how could I find out which…
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
21
votes
1 answer

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 use script /dev/null to fix it, and it works, but…
CJL
  • 313
  • 2
  • 6
19
votes
2 answers

How to run builds in Docker containers from Jenkins

I am trying to use Jenkins to build a C++ project in a Docker container. I have no problem building in Jenkins, or building in a container outside of Jenkins. Below is what I tried. I am omitting the volumes mapping for clarity. Case 1 The following…
marcv81
  • 620
  • 2
  • 7
  • 15
12
votes
1 answer

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

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 case and only one ^D in second case?
Igor Liferenko
  • 703
  • 4
  • 16
11
votes
3 answers

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 debian8 ctrlaltf2 and login with regular user debian8…
showkey
  • 79
  • 23
  • 67
  • 128
10
votes
3 answers

Why doesn't sshd use a pseudo terminal when the ssh client's argument is followed by an interactive program?

The normal way to connect to an SSH server is ssh username@ip_address. But a user may only want to run a program on the remote machine. So the program name follows after the normal argument which is ssh username@ip_address . For…
Ron Vince
  • 1,422
  • 4
  • 17
  • 26
9
votes
1 answer

BSD-style pseudoterminals vs. UNIX 98 pseudoterminals

Based on what I have read about pseudoterminals in Linux, there are two types of pseudoterminals: BSD-style pseudoterminals (which is deprecated) and UNIX 98 pseudoterminals. I have created two images that shows my understanding of these two types…
user7681202
  • 1,273
  • 2
  • 14
  • 25
8
votes
1 answer

Why blocking read() on a pty returns when process on the other end dies?

When slave side of pty is not opened, strace on the process, which does read(master_fd, &byte, 1);, shows this: read(3, So, when nobody is connected to the slave side of pty, read() waits for data - it does not return with a error. But when slave…
Igor Liferenko
  • 703
  • 4
  • 16
8
votes
2 answers

Which process is occupying a certain pseudo terminal pts/X?

On Linux: Normally pseudo terminals are allocated one after the other. Today I realized that even after a reboot of my laptop the first opened terminal window (which was always pts/0 earlier) suddenly became pts/5. This was weird and made me…
pefu
  • 220
  • 2
  • 8
7
votes
1 answer

Is there a way to reptyr a make process or any process with subprocesses?

Consider the following Makefile. all: yes If I run make and suspend using Ctrl-Z, and then start screen or tmux, followed by an attempt to reptyr, I get the following error. $ reptyr 5328 [-] Process 5329 (yes) shares 5328's process group.…
merlin2011
  • 3,855
  • 5
  • 27
  • 36
1
2 3 4 5 6 7 8