In linux I can use the key combinations Alt-Ctrl-F1
,Alt-Ctrl-F2
... to switch to different tty1
as I could use man chvt
.
using the command tty
I also get displayed the teletype/linux virtual console I am on.
However if I am in xterm
or in gnome-terminal
tty will display the relevant pseude-terminal.
Given all that:
- How can I tell which is the currently "active"
tty
(meaning it being displayed on the screen)?
This would be somewhat the solution (however it seems contorted and relies on loginctl logind, there must be a non-systemd to find out):
for sessionid in $(loginctl list-sessions --no-legend | awk '{ print $1 }'); do loginctl show-session -p State -p TTY $sessionid; done | grep "State=active" -B1 | head -n 1 | sed 's/.*=//g'
tty1
throughtty12
) is the one being shown to the console user? If so, what would you expect to be reported when a GUI is running on (say)tty8
? What if the GUI is running remotely as an X Windows session over XDMCP and the user isn't local? – Chris Davies Nov 28 '19 at 11:28loginctl show-session -p State {SESSION_ID}
would yieldState=active
. Hence thetty
on which eitherwayland compositor
orXorg server
are running on if they are displayed. No remote GUIs. – fraleone Nov 28 '19 at 11:32cat /sys/devices/virtual/tty/tty*/active
yieldstty2
which is the tty wayland-compositor is running on currently – fraleone Nov 28 '19 at 12:16