[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to find out the current display manager?



On Mon, Jan 16, 2017 at 11:42:17AM -0500, kamaraju kusumanchi wrote:
> Background on why I need this:
> I am developing a script[1] that gathers relevant system information
> depending on what issue a debian-user is facing.

That's pretty ambitious.  Good luck.

> Thanks. It looks like all I need is to find the parent process of
> Xorg. In my case, that would be lightdm.

There may not even be an "Xorg" process, if the user is doing something
unusual, like running a really old version of Debian (XFree86), or a
proprietary X server, or a really new version of Debian with Wayland(??),
or if the user is not currently able to get X to run at all.

Obviously, if X can't start up at all, you're going to have a very hard
time detecting a running display manager process.  So we'll get back
to that....

For the absolutely normal course, where the user is logged into X through
a display manager and is running your script inside that X session,
what you should probably do is recurse up through the process tree
(following ps -o ppid,cmd "$pid" step by step) until you run into a
process that you recognize as being a display manager, or until you
hit PID 1.

If you don't find a display manager that way, then your second try can
be "look for a running X server, and then look for its parent, and see
if it looks like a display manager".  That will catch the cases where
a display manager is running, but the user isn't logged in through it
for whatever reason.  Or where the user isn't running your script inside
an X session.

Third try can be looking for *any* running process that appears to be a
display manager.  Maybe that'll catch something like "display manager
is running a Wayland session, but user is not logged into it" more often
than it generates false positives.  Who knows.

Fourth try can be parsing dpkg -l (or similar) output to look for any
installed package that looks like a display manager.  Of course in
that case you'll also have to parse the status flags ("hi" or "rc"
or whatever).  This may catch the cases where X can't run due to drivers
being wrong, or no mouse plugged in, or whatever.


Reply to: