Working out which VT an X process is on

Andriy Gapon avg at FreeBSD.org
Sat Mar 31 09:40:06 UTC 2012


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.

> On BSD, I don't think it's possible to get this behaviour, identifying the
> X processes on a multi-user system by their controlling terminal. I develop
> a fork of Xvnc, so I've already read the relevant Xorg code, but I'm fairly
> new to BSD. If there is a way to configure or launch X apropriately I'd be
> grateful to hear it. I can easily hack X with an ioctl to do this, but I
> want to be able to follow the stock Xorg X server.
> 
> Some background: one of the programs we distribute is a "service-mode
> server" which follows the console and attaches itself to the X server on
> the currently-active VT. I would like our FreeBSD server to be able to
> follow the console, like our linux server does, and switch X server when
> the user uses Alt-Fn or 'switch user' in GNOME.
> 
> I'm not dead set on controlling terminals if there's another way of getting
> the information. My current best workaround is to grep the X logs, where
> the vt is reliably printed, but this feels dirty.
> 
> My experience of porting to BSD has been excellent otherwise; very little
> effort at all, and in a very neat environment that feels comfortable and
> modern compared to Solaris and HP-UX. Thank you for any help or pointers
> you can give, and for distributing  a great system.
> 
> Best,
> Nicholas
> 
> ---
> Nicholas Wilson
> Cambridge, UK
> _______________________________________________
> freebsd-x11 at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-x11
> To unsubscribe, send any mail to "freebsd-x11-unsubscribe at freebsd.org"
> 


-- 
Andriy Gapon


More information about the freebsd-x11 mailing list