Working out which VT an X process is on

Nicholas Wilson nicholas at nicholaswilson.me.uk
Sat Mar 31 18:17:45 UTC 2012


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.

Many thanks,
Nicholas


More information about the freebsd-x11 mailing list