Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Mar 2012 21:36:13 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Nicholas Wilson <nicholas@nicholaswilson.me.uk>
Cc:        "freebsd-x11@freebsd.org" <freebsd-x11@freebsd.org>, Andriy Gapon <avg@freebsd.org>
Subject:   Re: Working out which VT an X process is on
Message-ID:  <20120331183613.GO2358@deviant.kiev.zoral.com.ua>
In-Reply-To: <CAN%2BZGEmuUSt-mn_FfHjCUAqaUiorrzhfOfNzVW9f9LsPTBwCLQ@mail.gmail.com>
References:  <CAN%2BZGEnicY-UOB-5LO%2BxiUZKFpf7bFyUe3fv5reGh24ntNTofA@mail.gmail.com> <4F76D0E9.7060006@FreeBSD.org> <CAN%2BZGEmuUSt-mn_FfHjCUAqaUiorrzhfOfNzVW9f9LsPTBwCLQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--PMKcwNXkopx7sVjc
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Mar 31, 2012 at 07:17:38PM +0100, Nicholas Wilson wrote:
> On Mar 31, 2012 10:39 AM, "Andriy Gapon" <avg@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 ha=
ve
> 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 process=
es,
> > > 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 abo=
ut
> 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 proce=
ss.
> >
> > --
> > Andriy Gapon
>=20
> 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.

--PMKcwNXkopx7sVjc
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (FreeBSD)

iEYEARECAAYFAk93Tp0ACgkQC3+MBN1Mb4iHbQCg9OAVSfyjHR1RGy+1RMEbE099
O+MAn21BFglD4VQffPHn6zx67bIfckML
=7T2V
-----END PGP SIGNATURE-----

--PMKcwNXkopx7sVjc--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120331183613.GO2358>