0

This is probably linux-specific question...

I am running multiple virtual sessions and switching between them using "Ctrl+Alt+Fn". I am trying to write a script which would trigger some actions after I switch in/out of consoles.

I understand that I can read /sys/class/tty/tty0/active device to see which is currently active virtual console:

$ cat /sys/class/tty/tty0/active
tty2

Now, how do I identify which virtual tty am I actually running in? tty command does not return that information:

$ tty
/dev/pts/0

$DISPLAY also shows :0, not tty2. How can I determine that I am indeed running in tty2?

galets
  • 1,045
  • 1
  • 9
  • 17
  • `/dev/pts/0` is a pseudo-terminal. It indicates that you are not running on a virtual console, in my opinion. If you were, your tty whould be `/dev/tty{0..n}`. ---- After re-reading, I understand. Your X session (or Wayland) runs on ttyX, but your process is in a terminal window. I don't have an answer, but I would research how to map a display number to an X session, and an X session to a tty. – berndbausch Apr 24 '21 at 00:40
  • On Ubuntu 16, I see `/usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch`. I wonder if `vt7` is the virtual terminal? Probably yes, because `cat /sys/class/tty/tty0/active` returns tty7. – berndbausch Apr 24 '21 at 00:44

0 Answers0