Tuesday, June 3, 2008

Determine the virtual terminal you are using in GNU/Linux

Have you ever had to determine the virtual terminal that an X session is running on? Perhaps you may want this information for a program you have created. It is possible using the fgconsole command.
# fgconsole
7
Just running fgconsole will print the number of the active virtual terminal. For the uninitiated, by default, you have 7 virtual terminals on your Linux machine. You can switch between them using the Ctrl+Alt+ key sequence.

Usually, your Linux machine will be using any virtual terminal which is available for displaying X. But if the following two parameters are enabled in your /etc/gdm/gdm.conf file, then it will always use the same terminal.
#FILE /etc/gdm/gdm.conf
FirstVT=7
VTAllocation=true
You may also do the following to see which virtual terminal your X session is using :
$ grep VT /var/log/Xorg.0.log
(++) Using VT number 7

No comments: