Working out which VT an X process is on

Konstantin Belousov kostikbel at gmail.com
Sat Mar 31 18:36:20 UTC 2012


On Sat, Mar 31, 2012 at 07:17:38PM +0100, Nicholas Wilson wrote:
> On Mar 31, 2012 10:39 AM, "Andriy Gapon" <avg at freebsd.org> wrote:
> >
> > on 31/03/2012 04:10 Nicholas Wilson said the following:
> > > Hello,
> > >
> > > I'm working at the moment on porting a VNC product to FreeBSD, and have
> run
> > > into a little problem which I hope I can get some help on. In brief: I
> > > can't find a way of determining which virtual terminal is in use by a
> given
> > > X process.
> > >
> > > On linux, when X opens a handle to the tty it's going to run on, it
> > > acquires it as a controlling terminal. So, if there are two X processes,
> > > and we see that tty7 and tty8 are in use, it's obvious from ps which
> > > process is which, and hence by inspecting the processes' environments we
> > > can quickly establish which display number goes with which VT. (On the
> > > other UNIX platforms we support, like AIX, we don't need to worry about
> VTs
> > > at all.)
> >
> > Not sure if there is a better way, but
> > fstat -p ${X_SERVER_PID} | fgrep tty
> > should give what you want.
> > You need to have enough privileges to get information about the X process.
> >
> > --
> > Andriy Gapon
> 
> Oh! That makes it look so obvious. I'd been fixated on the fact that we
> can't rely on proc on BSD, so fuser wouldn't work like does on linux. Of
> couse there must be a sysctl-based equivalent for getting the X process's
> fds! I'm sure I can work it out now.

The sysctl you are looking for is kern.proc.filedesc. See
lib/libutil/kinfo_getfile.c for sample use, or just use
kinfo_getfile() as is.

On the other hand, there may be more ttys opened then just VT which is
used for framebuffer, and even more then VT + ctty.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-x11/attachments/20120331/4f5f43ce/attachment.pgp


More information about the freebsd-x11 mailing list