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+<Fn> 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
4 comments:
This is a nice tip.
Thanks.
I'd like to inform that the command 'fgconsole' throws out error 'Couldnt get a file descriptor referring to the console' when in debian sid using upstart(init replacement) instead of sysVinit.please do explain this.and we really love your articles reg linux.
prakash,
A file descriptor is a handle created by a process when a file is opened. AFAIK, fgconsole has nothing to do with your problem. Do check by running the command:
$ ulimit -Hn
to know the hard limit of your file descriptors in your machine. My machine shows a value of 1024. And fgconsole works fine on it.
thx Ravi,
Actually i was wrong.fgconsole works fine when invoked as root user(su -).and yes,mine too ulimit is @ 1024.
thx again.
Prakash
Post a Comment