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.
129 questions
5
votes
1
answer
557
views
Fool a program it has a pty of specific size
I use nethack with ttyrec to archive my funny deaths.
My only issue is that nethack uses as much screen space as possible to print log massages.
I would like to limit it to only work with 80x24 ...
2
votes
1
answer
279
views
TTY line discipline echoing feature
I'm confused from the actual meaning of the echoing feature implemented in Linux TTY driver.
As far as I know, a pseudo-terminal pair (PTY pair) consists of a PTY master, a PTY slave and a line ...
2
votes
2
answers
87
views
Unable to write to self in graphical terminal session?
Essentially, I noticed I am unable to write to my user who is using gnome-terminal.
tty returns /dev/pts/1, but I am unable to write there as root. Instead, it returns as follows:
myuser@pegasus:/$ ...
0
votes
0
answers
50
views
using ptys from shell
In earlier times I was able to open a pair of pseudo terminals /dev/ttyp9 and /dev/ptyp9.
It was easy to do something like:
$ cat /dev/ptyp9
and in another shell
$ echo Hallo > /dev/ttyp9
But on my ...
0
votes
1
answer
215
views
Where is the tty line discipline exactly "logically" located?
I recently started learning about Operating Systems and the linux kernel. I was interested in terminals, so I started there, however, I quickly ran into a problem. I wrote a slightly longer question, ...
0
votes
1
answer
189
views
xterm seems to change its "home" key behaviour for emacs
In xterm, when I press the HOME key on my keyboard, it normally sends ^[[H but when I open emacs -nw, it changes to ^[OH; those are home and khome respectively. I figured out while trying to build my ...
0
votes
2
answers
208
views
How can I connect a bash process to a tty _without_ using getty
I would have two serial usb devices connected to each other, /dev/ttyUSB1 and /dev/ttyUSB2. I would like to run /bin/bash connected to one end, so that I can attach to the other end using picocom and ...
1
vote
1
answer
173
views
job control doesn't work when I create my own pty pair with socat
I am experimenting with understanding terminal emulators by looking at the different pieces of the puzzle.
I am trying to start a pty pair and shell process with socat, and then connect to it with ...
0
votes
1
answer
158
views
how to get file descriptors of PTY inside of a child?
https://man7.org/linux/man-pages/man7/pty.7.html
in the "UNIX 98 pseudoterminals" it is said that ptsname can be used (and then open), but this function accepts file descriptor. i tried to ...
1
vote
1
answer
351
views
Pseudo-terminals control each other, how to get the return display
The problem is: my pseudo-terminal is /dev/pts/0, the target pseudo-terminal is /dev/pts/4, and I'm trying to get the target pseudo-terminal to print text using the echo text > /dev/pts/4 command.
...
2
votes
0
answers
978
views
How to suppress "Failed to set controlling terminal" warning in GDB when setting program to run on another terminal?
I'm using GDB to debug a program, and I want to direct its output to a different terminal than the one where GDB is running. Here's what I've been doing:
Open a second terminal, check its device name ...
0
votes
0
answers
282
views
How to reown a process?
when i run this script with a shortcut(sxhkd):
#!/bin/sh
MUSIC_DIR="$HOME/music"
songs=$(ls "$MUSIC_DIR")
filename=$( echo -e "random\n$songs" | dmenu -l 30 -i -p &...
0
votes
1
answer
350
views
how can I make socat simulate unplugging a serial device
I have this test program
import sys
for line in sys.stdin:
print(line.strip())
print("DONE")
if I get it to print out lines from a real device (an FTDI)
python3 demo.py < /dev/...
0
votes
1
answer
186
views
Can I set up a serial terminal (RS-232) without a pty?
I have two computers that both have a RS-232 port on /dev/ttyS0 connect together with a null modem.
I am trying to understand bit by bit how an external terminal worked in the old days, and how that ...
2
votes
1
answer
3k
views
trying to make my own shell handle ctrl+c properly
I am trying to understand how shells are set up so that the programs they are running receive the SIGINT when you press ctrl C but the shell doesn't, because when you are running bash, and run another ...
0
votes
1
answer
704
views
How to determine the graphical tty in loginctl
Loginctl lists a lot of sessions, and I want programmatically to know which one is a graphical session (e.g. GNOME desktop).
In the example below, I have a GNome desktop session open, an ssh ...
0
votes
1
answer
808
views
Pseudo terminal for comms between two processes
I am writing an executable that uses a 3rd party C library (libmodbus if it matters) to communicate via serial device (in my case, /dev/ttyUSB0 or similar to talk RS-485 via an FTDI chipset based USB-...
1
vote
2
answers
934
views
/proc/self/fd/2 can not be accessed under `sudo -u other_user`
I often use tee /proc/self/fd/2 to show something both to stdout and stderr, capture stdout, while still keep all output to stderr.
E.g., I have a do.sh:
STD_OUT_STR=$(CMD ARGS ... 2>&1 | tee /...
1
vote
1
answer
277
views
How to pipe terminal interaction with running process over network?
How can I run a program that expects to be executing in a terminal in such a way that it's STDIO can be arbitrarily connected-to remotely?
Specifically, I want to be able to launch gdb on one host and ...
1
vote
1
answer
1k
views
how to remove the buffer when simulating a serial device with socat
I am creating a fake serial device like this:
socat -d -d pty,raw,echo=0 pty,raw,echo=0
This creates devices with new numbers each time. Let's call them /dev/pty/6 and /dev/pty/7
To simulate a ...
2
votes
1
answer
423
views
zsh zpty does not work on macOS, does work on Linux?
zsh module zsh/zpty seems to work perfectly well on my Linux virtual machine running on Apple M1 macOS machine. But the same does not work on macOS (even on the same host machine). I have tried this ...
4
votes
1
answer
16k
views
"sudo: unable to allocate pty: No such device" in chrooted Linux
Added:
After reading suggested as duplicate Which of proc, sys etc. should be bind-mounted (or not) when chrooting into a "replacement" distribution? :
How I know:
it is customary to invoke ...
8
votes
1
answer
6k
views
How does the use_pty sudoers option prevent a persistence attack?
As a rule in the Debian 10 hardening guide, and various other audit guides of the Center for Internet Security (CIS), setting the use_pty sudoers option is recommended for the following rationale:
...
3
votes
1
answer
269
views
SSH under pty still promts stdin from terminal
I am currently learning about the pseudo-terminal functionalities in C. I am able to create the master, slave end of the pty, after fork, I have set the stdin, stdout, stderr to fd slave , after exec ...
0
votes
1
answer
1k
views
How to get color in terminal but no color in output file [duplicate]
To show output in both terminal and to a file, tee can be used like below
ls --color=auto | tee opfile
But now, there is no color in the terminal. If I force colors, opfile also has colors which ...
2
votes
1
answer
3k
views
Why dmesg output displayed on /dev/tty1
This is still related to my yesterday thread, so there's alert or maybe it's just log that displayed on my terminal on /dev/tty1. Ofcourse it's annoying because it's displayed in my bash prompt, so ...
2
votes
1
answer
220
views
Do programs that create pseudoterminals emulate terminals?
The way I understand it, applications that create a pty (a master/slave pair) can be separated into 2 categories:
terminal emulators (xterm, urxvt, ...), which supposedly produce graphical output
the ...
0
votes
1
answer
274
views
Verbose logging: howto save disk?
Situation
I'm running a program on Linux, which produces a lot of verbose logs to stdout.
The program itself is put into background by using systemd.service facilities.
Until now, I have configured ...
1
vote
1
answer
2k
views
How do I display a bash prompt when using SSH without a pseudo-terminal?
When the connection is slow, I connect to remote computers using SSH without allocating a pseudo-terminal (e.g. ssh -T [email protected] or ssh [email protected] bash). Although I am able to use the ...
4
votes
1
answer
2k
views
Perplexity about TTY and PTY
I'm trying to understand this topic but, apparently, for my brain it is too hard.
Terminal device entries normally reside in two directories: /dev and
/dev/pts. The /dev directory contains entries ...
0
votes
0
answers
203
views
How does terminal in Linux actually work? [duplicate]
I'm using Linux console for years, but currently started thinking of how it actually works. Typing a command as a string and pressing Enter returns its output in the same terminal window.
Opening a ...
3
votes
1
answer
9k
views
What is Virtual Serial Port in QEMU?
Ubuntu 20.04 both on host and guest.
I'm new to QEMU and trying to set up guest-host communication via serial port. The QEMU documentation says that -serial dev option:
Redirect the virtual serial ...
-1
votes
2
answers
1k
views
Why does the input cursor always go from the top to the bottom in a terminal emulator?
I noticed that the terminal cursor starts at the top of the terminal and slowly moves down as more commands are executed, until ultimately settling on the bottom regardless of the number of commands. ...
1
vote
3
answers
455
views
What "bad" things may happen (and why) if a Terminal Emulator and the Shell running in it are using different TERM types?
For example, in PuTTY's configuration I set terminal type to xterm-256color but after SSH login I change it with export TERM=linux in the shell.
I know it works quite well for most time. Just want to ...
1
vote
2
answers
627
views
How can I clean up output from expect?
Background: I'm using expect to connect between AMCE.sh and a managed network switch. I can connect to the switch via SSH, log in and issue commands but because of the way the switch manages SSL ...
-1
votes
1
answer
634
views
Why is Linux giving a pts number for real terminal console? (which is not an emulated terminal like ssh or xterm)
I read that pts is a pseudo-terminal (that we get through ssh or xterm) and tty is the native terminal.
I didn't connect to my PC through ssh or xterm, but I am still getting pts/0 and pts/1 when I ...
1
vote
0
answers
217
views
Interpret bash escape sequences and other characters using ncurses
I want to design a terminal multiplexer like tmux, but not that complex, something minimal, that works remote, using ncurses.
On the server side, the workflow is as follows:
The server process ...
0
votes
1
answer
156
views
Are there tools that I can use to obtain a snapshot of terminal or pty state? [duplicate]
Please stop marking this question as a duplicate, it's not a duplicate. Thanks. Consider the sequence of a, followed by \x1b[D ("cursor back"), followed by b. This would produce an output of ...
3
votes
1
answer
3k
views
Shell Upgrade: script typescript command using bash
Can anyone explain what this means:
SHELL=/bin/bash script -q /dev/null
It is used to upgrade a shell in a CTF in HTB:
SHELL=/bin/bash script -q /dev/null
Ctrl-Z
stty raw -echo
fg
reset
xterm
...
0
votes
1
answer
271
views
script -c '...' does NOT print colors
edit: I was in EternalTerminal session, and that was the source of the difference. In a regular ssh, it works.
I need to get commands in a pipe to believe they are in a PTY and emit colorized output.
...
0
votes
0
answers
3k
views
Link character device to pty with socat
I have a "regular character device" - not sure of the proper naming - that doesn't support ioctl on an embedded device (/dev/appvcom). I need to connect to it with an application that uses some ioctl ...
0
votes
2
answers
387
views
How to replace program running in graphical terminal with another program?
Lets say I have top or some ncurses program running in a graphical terminal, and from outside this terminal I'd like to execute a command, that would replace top with another program of my choosing.
...
1
vote
1
answer
956
views
Alternative to "openvt", but for pseudo terminal (pts). Exists?
Alternative to "openvt"...but for pseudo terminal(pts)... Exists?
Openvrt operate only tty...but not pts.
(Example: lauch comand in specific pts and with user of shell pts destination)
Command <...
1
vote
1
answer
2k
views
How bash sets tty attributes before and after running a command?
Open xterm, run tty and see pseudo terminal slave file (let's say it is /dev/pts/0).
Then open another xterm and run
$ stty -F /dev/pts/0
speed 38400 baud; line = 0;
lnext = <undef>; discard = &...
4
votes
1
answer
4k
views
What is the difference between IXON and IXOFF tty attributes?
To be specific, let's speak in pseudo-terminal terms. Suppose we have file descriptors master and slave for a pseudo-terminal pair (suppose it is a controlling tty). Disabling IXON on master (or slave,...
0
votes
1
answer
721
views
Detect pty buffer capacity
I am using the tty subsystem of Linux to emulate serial ports. The emulated serial ports are used by an application that expects a physical serial port. In my case, the application is running under ...
0
votes
0
answers
615
views
Why does changing my home directory in WSL break my PATH but only in the second window in tmux?
A bit ago, I found it necessary to set my home directory to my One Drive in WSL. Thanks to this post I was even able to get my permissions working correctly within WSL (Ubuntu 16.04 LTS).
However, ...
1
vote
0
answers
1k
views
Restricted shell within docker container
Some context for my question: I am working on a pty NodeJS server running in docker where I want to provide users connecting to the shell an isolated environment where they can play around with ...
10
votes
1
answer
1k
views
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 ...
1
vote
1
answer
1k
views
How TTY differs from an ordinary file? [duplicate]
I'm trying to understand ssh's -t option:
-t Force pseudo-terminal allocation. This can be used to execute arbitrary screen-
based programs on a remote machine, which can be ...