Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
0
answers
47
views
How does `/dev/tty` work as a "synonym"?
### Context To restore the standard input, standard output and/or standard error (file descriptors 0, 1 and/or 2 respectively) of a process to the keyboard and/or display of an interactive shell (bash) session, I have seen [here][1] that one can execute either of the following: $ exec &>/dev/tty or...
### Context
To restore the standard input, standard output and/or standard error (file descriptors 0, 1 and/or 2 respectively) of a process to the keyboard and/or display of an interactive shell (bash) session, I have seen here that one can execute either of the following:
$ exec &>/dev/tty
or
$ exec &>$(tty)
Whereas
$(tty)
(a command substitution) returns /dev/pts/X
where X
is the number associated to the currently active terminal window (pseudo-tty), thereby explicitly pointing the redirection to the "real" filename associated with the terminal in which the command is entered, in contrast /dev/tty
is a character file which *seems* to appear identical to different processes (i.e. to different concurrent terminal windows).
In man 4 tty
it says:
> The file /dev/tty [...] is a synonym for the controlling terminal of a process...
In The Open Group Base Specifications Issue 8, Chapter 10 it says:
> **/dev/tty**
>
> In each process, a synonym for the controlling terminal associated with the process group of that process, if any. It is useful for programs or shell procedures that wish to be sure of writing messages to or reading data from the terminal no matter how output has been redirected. It can also be used for applications that demand the name of a file for output, when typed output is desired and it is tiresome to find out what terminal is currently in use.
### Question
Since /dev/tty
is a file and not a symbolic link like /dev/fd
or /proc/self
, how can it "point" to different terminal processes when interpreted in different terminal windows? What does it mean in Unix/Linux parlance to be "a synonym" when not a symbolic link or a hard link — I mean: what is interpreting such a "synonym" when invoked on a command line and how?
The Quark
(402 rep)
Jul 24, 2025, 01:16 PM
• Last activity: Jul 25, 2025, 05:58 AM
1
votes
0
answers
31
views
How to set which tty to run GUI in?
I have set up a runit service to autologin in `/dev/tty16` and the shell profile executes `dbus-run-session Hyprland`, however, I noticed that Hyprland, or GUIs start on the 'active' or the currently shown tty. How can I specify what tty to use a GUI application in?
I have set up a runit service to autologin in
/dev/tty16
and the shell profile executes dbus-run-session Hyprland
, however, I noticed that Hyprland, or GUIs start on the 'active' or the currently shown tty. How can I specify what tty to use a GUI application in?
Caesar
(25 rep)
Jun 29, 2025, 08:10 PM
1
votes
1
answers
2357
views
How can I get write/wall commands working as intended?
OS: xUbuntu 22.04 I want to use the write / wall commands for sending msgs to other users sharing the same computer. But when I try to use the write command, I get the following error: ``` √ ~ $ who user1 tty7 2024-05-12 06:40 (:0) user2 tty8 2024-05-13 06:56 (:1) user3 tty9 2024-05-16 06:09 (:2) us...
OS: xUbuntu 22.04
I want to use the write / wall commands for sending msgs to other users sharing the same computer.
But when I try to use the write command, I get the following error:
√ ~ $ who
user1 tty7 2024-05-12 06:40 (:0)
user2 tty8 2024-05-13 06:56 (:1)
user3 tty9 2024-05-16 06:09 (:2)
user4 tty10 2024-05-16 11:54 (:3)
√ ~ $ write user2 tty8
write: effective gid does not match group of /dev/pts/13
The error is the same no matter what variation of the command I try: write user2
, write user2 /dev/pts/13
or write user2 pts/13
I have been searching online and found just a few blurbs about the error. One such blurb seemed to suggest this behaviour was intentional, at least for Debian/buntu.
https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/2064685
I did try the advice in the link above to:
>If you wish to restore the previous behavior, it should be sufficient to change /usr/bin/write.ul to root:tty 02755.
So that now my /etc/bin/write.ul
has the setgid bit set:
√ ~ $ sudo chmod 02755 /usr/bin/write.ul
√ ~ $ ls /usr/bin/write.ul
-rwxr-sr-x 1 root root 23K Apr 9 10:32 /usr/bin/write.ul*
but doing so has made no change in the error received.
Any ideas what more I likely need to do to get these commands working as intended?
naphelge
(43 rep)
May 20, 2024, 11:35 PM
• Last activity: Apr 26, 2025, 12:10 AM
2
votes
2
answers
2943
views
w command doesn't show all pseudo-terminal sessions
If I open terminal and execute `w` command then it will show: user tty7 :0 12:04 39:56 36.87s 0.06s /sbin/upstart - Now if open `terminator` or `xterm` and execute `w` command then it will show it's entry in the output of `w` command like user tty7 :0 12:04 39:56 36.87s 0.06s /sbin/upstart - user pt...
If I open terminal and execute
w
command then it will show:
user tty7 :0 12:04 39:56 36.87s 0.06s /sbin/upstart -
Now if open terminator
or xterm
and execute w
command then it will show it's entry in the output of w
command like
user tty7 :0 12:04 39:56 36.87s 0.06s
/sbin/upstart -
user pts/2 :0.0 12:50 1.00s 0.02s 0.00s w
but it will not show a new entry when I open gnome-terminal
or xfce4-terminal
.
Why it is showing new session for terminator and not for xfce4-terminal?
Prvt_Yadav
(6032 rep)
May 4, 2018, 07:25 AM
• Last activity: Mar 25, 2025, 03:02 PM
3
votes
1
answers
361
views
sudo results in a new session with a new controlling PTY
On Linux Ubuntu when at terminal I run `sudo su` or `sudo su -` the system creates a new session with a new controlling `pts`, namely ubuntu@ubuntu:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.5 LTS Release: 22.04 Codename: jammy ubuntu@ubuntu:~$ u...
On Linux Ubuntu when at terminal I run
sudo su
or sudo su -
the system creates a new session with a new controlling pts
, namely
ubuntu@ubuntu:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
ubuntu@ubuntu:~$
ubuntu@ubuntu:~$ uname -a
Linux ubuntu 5.15.0-124-generic #134-Ubuntu SMP Fri Sep 27 20:20:17 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
ubuntu@ubuntu:~$
ubuntu@ubuntu:~$ ps
PID TTY TIME CMD
143254 pts/0 00:00:00 bash
143302 pts/0 00:00:00 ps
ubuntu@ubuntu:~$
ubuntu@ubuntu:~$ sudo su -
root@ubuntu:~#
root@ubuntu:~# ps
PID TTY TIME CMD
143304 pts/1 00:00:00 sudo
143305 pts/1 00:00:00 su
143306 pts/1 00:00:00 bash
143316 pts/1 00:00:00 ps
root@ubuntu:~#
Is it an expected behavior?
As requested in the comments:
$ ps
PID TTY TIME CMD
146202 pts/0 00:00:00 bash
146231 pts/0 00:00:00 ps
$ sudo -s
root@ubuntu:/home/ubuntu# ps
PID TTY TIME CMD
146233 pts/1 00:00:00 sudo
146234 pts/1 00:00:00 bash
146240 pts/1 00:00:00 ps
CarloC
(385 rep)
Oct 25, 2024, 04:41 PM
• Last activity: Oct 25, 2024, 06:17 PM
4
votes
1
answers
270
views
Will writing to /dev/pts allow me to source ~/.bashrc?
I have several terminal windows already open; I just made a change to `~/.bashrc`, and I'd like to run `source ~/.bashrc` in each of the open terminals. It seems to me that if I just ```bash source ~/.bashrc | tee /dev/pts/{0..12} ``` , then `~/.bashrc` should be run in each terminal. It looks like...
I have several terminal windows already open; I just made a change to
~/.bashrc
, and I'd like to run source ~/.bashrc
in each of the open terminals.
It seems to me that if I just
source ~/.bashrc | tee /dev/pts/{0..12}
, then ~/.bashrc
should be run in each terminal. It looks like it was, since I include a clear
at the end of ~/.bashrc
.
However, what I'm specifically testing is whether
PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}"
actually creates a single source of truth for all my terminals, and was modified in each open terminal.
Now I'm not sure if this has something to do with writing to /dev/pts/{0..12}
or is related to the way that history
functions. If I look at one of my open terminals which is running git log
, and echo $PROMPT_COMMAND
, I do **NOT** see the modifications I would expect had ~/.bashrc
been sourced. As a consequence of the history
commands missing, I do not see git log
output in a separate terminal, running tail -f ~/.bash_history
, which I would expect to see if PROMPT_COMMAND
was indeed modified after source ~/.bashrc
.
However, if I ask each terminal echo $PROMPT_COMMAND | tee /dev/pts/{0..12}
, what the value of PROMPT_COMMAND
is, I get:
history -a; history -c; history -r; pre_prompt_command; echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"
which includes history -a; history -c; history -r;
, the changes that I added in ~/.bashrc
.
Now I'm confused. What am I doing wrong? Or what do I not understand correctly? Was PROMPT_COMMAND
modified or was it not? Or is this a consequence of how bash / linux works? I'm pretty sure it's user error, and not a bug.
Radoslav Ivanov
(41 rep)
Apr 14, 2024, 02:46 PM
• Last activity: Apr 28, 2024, 12:50 PM
3
votes
1
answers
2951
views
documentation on ptmx and pts
I am want to stream a linux terminal to my own program, and as far as I understand this is done by opening /dev/ptmx to start a new pts, I have tested this and this does indeed work (it creates a new file in /dev/pts). But I am not sure how I am supposed to actually read and write to this terminal....
I am want to stream a linux terminal to my own program, and as far as I understand this is done by opening /dev/ptmx to start a new pts, I have tested this and this does indeed work (it creates a new file in /dev/pts). But I am not sure how I am supposed to actually read and write to this terminal. Writing directly to /dev/pts/(pts number) I just get an input/output error. Also, am I supposed to open /dev/ptmx and /dev/pts/(pts number) at the same time with the same program. Am I supposed to somehow open a shell first?
I find this stuff kinda confusing and I have not been able to find much information except for this man page http://man7.org/linux/man-pages/man4/pts.4.html
TT-392
(247 rep)
Sep 22, 2018, 02:03 PM
• Last activity: Nov 1, 2023, 04:29 PM
2
votes
1
answers
533
views
umount /chrootedpath /dev/pts after several chroot(s): target is busy
I've been doing several chrooted environments in parallel, each in separate folder (when the script with `chroot` exited I sometimes run another in same folder), and for a while it seemed fine. But now I have almost empty `/dev` of "main" system (cannot start apps/open new windows, etc.). I've been...
I've been doing several chrooted environments in parallel, each in separate folder (when the script with
chroot
exited I sometimes run another in same folder), and for a while it seemed fine. But now I have almost empty /dev
of "main" system (cannot start apps/open new windows, etc.).
I've been mounting like this:
sudo mount -t proc proc $work_path/fin_sq/proc
sudo mount -t sysfs sys $work_path/fin_sq/sys
sudo mount -t devtmpfs devtmpfs $work_path/fin_sq/dev
sudo mount -t devpts devpts $work_path/fin_sq/dev/pts
and unmounting after exiting chroot
:
umount "${work_path}"/fin_sq/dev/pts
umount "${work_path}"/fin_sq/dev
umount "${work_path}"/fin_sq/proc
umount "${work_path}"/fin_sq/sys
Occasionally I've interrupted script running in chrooted environment via ctrl-c
. For cases when the script run in a folder where there were remnants of previous run, the script is coded to umount and delete previous work.
Today I saw target is busy
at least in one terminal window where I run script with chroot
. After umount
failed the script deleted all folders of chrooted system. For the future, I think I better cancel further unmounts/deletions if one of umounts fails.
However, what do you think might cause such result? How to investigate? How to get system to working condition? I'm not rebooting the system for a while hoping to learn Linux deeper. TIA
P.S. full script(s) for those interested: script running other script via chroot , searching for /dev/pts
finds two lines (mount/umount) in the code.
"Naturally" lsof
shows empty output and adding --force
seems to make no difference. Trying mount -t devpts devpts /dev
resulted in "devtmpfs already mounted on one_of_chrooted_paths/dev".
I've read https://unix.stackexchange.com/questions/464585/umount-target-is-busy , but the question is for -o rbind
, I mount w/out it. Again, it was working with two chrooted, I increased to 3-4 and something broke...
Alex Martian
(1287 rep)
Oct 20, 2023, 01:32 PM
• Last activity: Oct 21, 2023, 04:24 AM
2
votes
1
answers
2821
views
Why dmesg output displayed on /dev/tty1
This is still related to my [yesterday thread](https://unix.stackexchange.com/questions/703218/annoying-clocksource-alert-warning-in-bash-prompt-periodically), 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 m...
This is still related to my [yesterday thread](https://unix.stackexchange.com/questions/703218/annoying-clocksource-alert-warning-in-bash-prompt-periodically) , 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 whenever I want input something, my input has been overwrite with that output. It came printed out periodically maybe about second
. So you can see how it's annoying
My terminal is moreless looks like this:
root@LFS:# echo "Hey get out of there"clocksource: timekeeping watchdog on CPU0: acpi_pm wd-wd readback delay of 643744ns
clocksource: wd-tsc-wd read-back delay of 182144ns, clock-skew test skipped!
clocksource: timekeeping watchdog on CPU0: acpi_pm wd-wd readback delay of 643744ns
clocksource: wd-tsc-wd read-back delay of 182144ns, clock-skew test skipped!
clocksource: timekeeping watchdog on CPU0: acpi_pm wd-wd readback delay of 643744ns
clocksource: wd-tsc-wd read-back delay of 182144ns, clock-skew test skipped!
...
I suspect this is not because of
, but
output. Because when I command
. It display same. But whenever I use /dev/pts
There's no annoying output or alert that came periodically, I tested it when I login SSH in my LFS sistem.
So how to prevent dmesg log displayed to /dev/tty1
Update:
Inside /proc/cmdline
root@LFS:~# cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-5.16.9-lfs-11.1 root=/dev/sda1 ro
Muhammad Ikhwan Perwira
(319 rep)
May 20, 2022, 02:22 PM
• Last activity: May 20, 2022, 03:01 PM
1
votes
1
answers
773
views
ssh pseudoterminal special character problems
So I have the following situation: I have a host that exhibits unexpected behavior when using `ssh -t` combined with tmux. If I call `ssh -t my-problem-host tmux` non-ascii characters (e.g. `€`) are displayed as `_`. If I connect without calling tmux, there is no problem. For example `ssh -t my-prob...
So I have the following situation: I have a host that exhibits unexpected behavior when using
ssh -t
combined with tmux.
If I call ssh -t my-problem-host tmux
non-ascii characters (e.g. €
) are displayed as _
. If I connect without calling tmux, there is no problem.
For example ssh -t my-problem-host bash
followed by manually entering tmux is OK, while ssh -t my-problem-host bash tmux
is not OK.
Other strange behavior outside of tmux: If I use ssh -t my-problem-host vim
and enter a special character, I get the special character and a space. If I use ssh -t my-problem-host mc
and type a special character, I get two questions ??
.
I also have this problem only with a single host and would like to know what causes this and how this can be fixed. Essentially ssh -t
seems to cause problems, the host seems to have a strange pseudo-terminal.
Joseph Dalton
(11 rep)
Dec 26, 2021, 07:52 PM
• Last activity: Dec 30, 2021, 11:40 AM
-3
votes
1
answers
2028
views
How can i change this Value (pts/1)
[![Image][1]][1] [1]: https://i.sstatic.net/Tq5Q3.png How can I change `pts/1` to another value? Can I add a user with `adduser` and give a own parameter to change this?

pts/1
to another value?
Can I add a user with adduser
and give a own parameter to change this?
Eren G
(7 rep)
Aug 14, 2021, 02:34 PM
• Last activity: Aug 15, 2021, 10:35 AM
0
votes
1
answers
2084
views
Restore default permissions on /dev/pts
Hey guys I tried to activate multiuser for some screens so I used screen -A -m -d -S test screen -S stest -X multiuser on screen -S test -X acladd testuser But I got chmod /dev/pts/17: Permission denied Unfortunately I thought it would be a great idea to play around with the permissions. Now I´...
Hey guys I tried to activate multiuser for some screens so I used
screen -A -m -d -S test
screen -S stest -X multiuser on
screen -S test -X acladd testuser
But I got
chmod /dev/pts/17: Permission denied
Unfortunately I thought it would be a great idea to play around with the permissions.
Now I´m with the folder it self
drwxrw-rw- 2 root sys 0 Jul 10 09:39 pts
And the files inside with the following
total 0
crw-rw-rw- 1 root sys 136, 0 Aug 4 22:30 0
crw-rw-rw- 1 markus mTeam 136, 1 Aug 1 23:20 1
crw-rw-rw- 1 markus mTeam 136, 10 Jul 24 13:47 10
crw-rw-rw- 1 markus mTeam 136, 11 Jul 27 17:43 11
crw-rw-rw- 1 markus mTeam 136, 12 Aug 4 22:33 12
crw-rw-rw- 1 markus mTeam 136, 13 Aug 4 22:32 13
crw-rw-rw- 1 markus mTeam 136, 14 Aug 4 22:33 14
crw-rw-rw- 1 markus mTeam 136, 15 Jul 27 20:12 15
crw-rw-rw- 1 markus mTeam 136, 16 Aug 4 21:46 16
crwxrwxrwx 1 markus mTeam 136, 17 Aug 4 2021 17
crw-rw-rw- 1 markus mTeam 136, 18 Aug 4 22:07 18
crw-rw-rw- 1 markus mTeam 136, 19 Aug 4 16:29 19
crw-rw-rw- 1 markus mTeam 136, 2 Jul 27 17:43 2
crw-rw-rw- 1 markus mTeam 136, 20 Jul 27 17:37 20
crw-rw-rw- 1 markus mTeam 136, 22 Jul 27 17:43 22
crw-rw-rw- 1 markus mTeam 136, 23 Aug 1 20:16 23
crw-rw-rw- 1 markus mTeam 136, 24 Aug 4 17:55 24
crw-rw-rw- 1 markus mTeam 136, 25 Jul 27 17:43 25
crw-rw-rw- 1 markus mTeam 136, 28 Jul 27 12:29 28
crw-rw-rw- 1 markus mTeam 136, 29 Jul 27 17:43 29
crw-rw-rw- 1 markus mTeam 136, 3 Aug 4 22:24 3
crw-rw-rw- 1 markus mTeam 136, 31 Jul 27 17:43 31
crw-rw-rw- 1 markus mTeam 136, 33 Jul 27 17:43 33
crw-rw-rw- 1 markus mTeam 136, 4 Aug 4 22:33 4
crw-rw-rw- 1 markus mTeam 136, 5 Jul 13 10:01 5
crw-rw-rw- 1 markus mTeam 136, 6 Aug 4 22:14 6
crw-rw-rw- 1 markus mTeam 136, 7 Aug 4 22:14 7
crw-rw-rw- 1 markus mTeam 136, 8 Aug 4 22:33 8
crw-rw-rw- 1 markus mTeam 136, 9 Jul 10 09:41 9
crw-rw-rw- 1 root sys 5, 2 Jul 10 09:39 ptmx
On some other pages I have read that the permissions can change and aren't static.
And my problem is now that since I changed the permissions I'm not able to create new screens nor operate them.
When I use for example:
screen -A -m -S test
I get
Cannot open /dev/pts/27: Permission denied
So is there a way to fix my stupid mistake?
I'm grateful for every help I get :)
I'm using Ubuntu 20.10
Markus
(3 rep)
Aug 5, 2021, 07:02 AM
• Last activity: Aug 5, 2021, 01:00 PM
-1
votes
1
answers
602
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 type `who` command. When I open other terminals, the number of pts's increase. ``` username@machine$ w...
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 type
who
command. When I open other terminals, the number of pts's increase.
username@machine$ who
username tty7 2020-12-30 11:39 (:0)
username pts/0 2020-12-30 11:39 (:0)
username pts/1 2020-12-30 11:53 (:0)
I am not getting why this is happening, shouldn't there be more tty's after opening other terminals?
Also, when I do su
I see that other pts session gets opened for root in auth.log file.
Gaurav Purswani
(1 rep)
Dec 30, 2020, 07:05 AM
• Last activity: Dec 31, 2020, 04:27 PM
0
votes
2
answers
1022
views
screen /dev/pts/<num> of a VM never has correct stty settings
A virtual machine (using linux+kvm+qemu) is setup to provided a serial port for a terminal, which is made available via a pseudo-terminal, some random `/dev/pts/ ` I use screen as a way to interact with `/dev/pts/ `, as it has proven better than `cat /dev/pts/ & cat > /dev/pts/ ` which did not corre...
A virtual machine (using linux+kvm+qemu) is setup to provided a serial port for a terminal, which is made available via a pseudo-terminal, some random
/dev/pts/
I use screen as a way to interact with /dev/pts/
, as it has proven better than
cat /dev/pts/ & cat > /dev/pts/
which did not correctly handle escapes like ctrl-c
, or echoed input multiple times.
The issue and core of this question is that the settings of the "tty/pts" as inquired via stty --all
inside the shell wihtin screen /dev/pts/
does not have the correct settings with respect to the dimensinos (cols
and rows
) which effectively causes headache by incorrect line-wrapping etc inside the shell of the VM.
Since there is more than 1 machine and terminal/tty/pts at play here I am not experienced enought to understand how to setup the correct settings.
How can the screen /dev/pts/
shell be made aware of the correct stty
settings?
** Update **
The output of stty --all
within the shell of the vm is.
root@mail:~# stty --all
speed 115200 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ;
eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon ixoff
-iuclc -ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon -iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -flusho -extproc
the output of stty --all
in the shell of the hosting system is
speed 38400 baud; rows 39; columns 147; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ; eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon -ixoff -iuclc -ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
fraleone
(897 rep)
Nov 16, 2020, 12:25 PM
• Last activity: Dec 20, 2020, 12:10 PM
3
votes
3
answers
3887
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 shared by multiple slaves. Given one of the processes working on the master and slave, how can we f...
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 shared by multiple slaves.
Given one of the processes working on the master and slave, how can we find out the other?
For example, ps
provides information about the controlling tty of each process. Can it be helpful?
Thanks.
Tim
(106420 rep)
Jan 3, 2019, 06:14 PM
• Last activity: Dec 9, 2020, 12:51 PM
1
votes
1
answers
5245
views
How to restrict a user from using tty?
i was wondering if it is possible to force log out a user (anyone other than root) when trying to login via tty ( ctrl + tab + f1 / f2 / f3 ..). The user should be able to use pts with no problems. Using CentOS 7.
i was wondering if it is possible to force log out a user (anyone other than root) when trying to login via tty (ctrl+tab+f1/f2/f3..). The user should be able to use pts with no problems.
Using CentOS 7.
Harish Agadi
(21 rep)
Aug 1, 2018, 12:52 PM
• Last activity: Sep 18, 2020, 03:04 AM
3
votes
1
answers
591
views
identify process sending a signal to a shell script
I've written a shell script that uses the `trap` feature to output its progress when it receives a SIGUSR1 signal, but I don't see how to have the script be able to output the progress to the STDOUT of the process which sent the signal. So, if the script is running in terminal emulator `/dev/pts/10`...
I've written a shell script that uses the
trap
feature to output its progress when it receives a SIGUSR1 signal, but I don't see how to have the script be able to output the progress to the STDOUT of the process which sent the signal. So, if the script is running in terminal emulator /dev/pts/10
and I send the process a signal from a terminal emulator on /dev/pts/11
, the output is going to /dev/pts/10
, but I want to send to /dev/pts/11
. I do NOT want to have to resort sending the progress message via wall
or hard-coded shell redirection to a specific STDOUT.
user1404316
(3138 rep)
Jun 24, 2020, 06:08 PM
• Last activity: Jun 24, 2020, 09:00 PM
3
votes
1
answers
1357
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("/dev/ptmx", O_RDWR | O_NOCTTY); if(masterfd ptmx = masterfd; Next I save the slave's name (yes I know...
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("/dev/ptmx", O_RDWR | O_NOCTTY);
if(masterfd ptmx = masterfd;
Next I save the slave's name (yes I know sizeof(char) is always 1)
/* get the path to the slave */
char * slavepathPtr;
char * slavePath;
size_t slavepathLen;
if((slavepathPtr = ptsname(masterfd)) == NULL){
perror("ptsname");
exit(EXIT_FAILURE);
}else{
slavepathLen = strlen(slavepathPtr);
slavePath = (char *) malloc(sizeof(char) * (slavepathLen + 1));
strcpy(slavePath, slavepathPtr);
};
I then create a predictably named symlink to the slave (
/dev/pts/number
) in /dev/custom/predictable
(which was provided as an argument to this program using getopts) and verify that its permissions are safe using calls to access
, lstat
, readlink
, symlink
and confirm that the program can continue execution, otherwise it calls unlink
on the symlink and terminates the thread.
Finally the program ends up in this loop
ssize_t read_result;
ssize_t write_result;
while(1){
if((read_result = read(comms_in->ptmx, ptmxio_read_buffer, sizeof ptmxio_read_buffer)) thread_statuses[PTMXIO_THREAD] = THREAD_FAILED;
pthread_mutex_unlock(&COMMS_MUTEX);
pthread_cond_signal(&SIG_PROGRAM_FINISHED);
pthread_exit((void *) comms_in);
}
}else if((write_result = write(STDOUT_FILENO, ptmxio_read_buffer, read_result)) != read_result){
{
/** same as above */
}
};
};
On the system, I can run this program and all is swell.
The read blocks.
When the pts symlink is opened with cu
or picocom
then bytes are successfully read up to the buffer limits either on my end or the kernel's end, depending on who's lower.
The problem comes when the slave is closed.
At this point, the read returns -1
-> EIO
with error text: Input/output error
and will continue to do so, consuming a lot of cpu time if I choose to not terminate the thread and loop.
When cu
or picocom
or even just an echo -en "some text" > /dev/pts/number
, the read blocks again, until bytes are available. In the case of the redirection into the symlink, obviously if it fills less than a buffer, read just gets that one buffer and continues to return -1
-> EIO
again.
What's going on? I need a method that doesn't consume a lot of CPU as this runs on a slow embedded application processor and allows me to re-establish reads without losing bytes.
I noticed a thread making a call to this:
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...})
and can't make much sense of what the 3 options are as they're not in my Linux headers anywhere.. Note that 3
is comms_in->ptmx
/ masterfd
.
Here is an lstat on the symlink and some extra information, note that the st_mode is unchanged before and after successful and unsuccessful reads.
‘ptmxio_thread’ failed read (-1) on /dev/pts/13 /dev/pts/13: Input/output error
‘ptmxio_thread’ ptsNum (from ioctl) 13
‘ptmxio_thread’ st_dev: 6, st_ino: 451, st_mode: 0000A1FF, st_nlink: 1
‘ptmxio_thread’ st_uid: 000003E8, st_gid: 000003E8, st_rdev: 0, st_size: 11
‘ptmxio_thread’ st_blksize: 4096, st_blocks: 0, st_atime: 1540963806, st_mtime: 1540963798
‘ptmxio_thread’ st_ctime: 1540963798
Supernovah
(143 rep)
Oct 31, 2018, 04:48 AM
• Last activity: Feb 10, 2020, 02:35 AM
0
votes
2
answers
970
views
How to write to terminal device stdin of running process from a different terminal without any prior preparation?
There seem to be plenty of similar questions, for example: https://stackoverflow.com/questions/5374255/how-to-write-data-to-existing-processs-stdin-from-external-process However the answer given is to prepare the program beforehand by making its stdin a pipe. There's also: https://serverfault.com/qu...
There seem to be plenty of similar questions, for example:
https://stackoverflow.com/questions/5374255/how-to-write-data-to-existing-processs-stdin-from-external-process
However the answer given is to prepare the program beforehand by making its stdin a pipe.
There's also:
https://serverfault.com/questions/178457/can-i-send-some-text-to-the-stdin-of-an-active-process-running-in-a-screen-sessi
Which is answered by commanding a terminal multiplexer under which the program in question is running. That means it also needs prior preparation.
This question is about how to do this *without* having done any preparation beforehand.
At first I thought it might be as simple as:
echo foo > /proc/$p/fd/0
but that just writes to the terminal. So then I tried:
echo foo > /proc/$terminal_emulator/fd/$ptmx_fd
but that also fails because it just opens up a new terminal device slave for echo.
I already have an answer using gdb
(*sigh*) which I'll be posting below, but I wonder if anyone knows of a simpler and better alternative.
JoL
(4989 rep)
Aug 6, 2019, 05:06 PM
• Last activity: Aug 6, 2019, 05:53 PM
2
votes
0
answers
283
views
Associating pts and tty to a process
I am trying to find out which tty or pts is being run by which process. My research so far is that: - tty is a kernel or backend terminal to handle lower level stuffs - pts is a pesudo terminal to allow user to communicate with the system - there are a lot of tty and pts files in `/dev` but cannot b...
I am trying to find out which tty or pts is being run by which process.
My research so far is that:
- tty is a kernel or backend terminal to handle lower level stuffs
- pts is a pesudo terminal to allow user to communicate with the system
- there are a lot of tty and pts files in
/dev
but cannot be read
Would like to ask the following questions:
- Why does /dev/pts
and /dev
contains so much numbers (eg 1-26) despite ps -aux | grep pts
only showing 4 pts entries
- Is it possible to determine what process is running a pts or tty? As I read that ssh spawns a new shell, but not sure if its a pts or tty
user357066
(65 rep)
Jul 8, 2019, 02:52 AM
Showing page 1 of 20 total questions