Sample Header Ad - 728x90

How to tell if I am on active virtual console?

0 votes
0 answers
389 views
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?
Asked by galets (1297 rep)
Apr 23, 2021, 11:04 PM