Gentoo Archives: gentoo-user

From: Marko Vallius <markvall@×××.fi>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Can a script tell if it's running under X?
Date: Sun, 05 Dec 2004 08:28:05
Message-Id: 20041205082744.GA18718@iki.fi
In Reply to: Re: [gentoo-user] Can a script tell if it's running under X? by Peter Gordon
1 On Sat, Dec 04, 2004 at 02:54:47PM -0800, Peter Gordon wrote:
2 > Kevin O'Gorman wrote:
3 > | Is there a way for a script (bash, for instance) to know
4 > | if it's running under X, such as in an xterm or konsole?
5 >
6 > One way to do it (though I don't know how to do this in Bash) is to
7 > check X's Process ID (PID). If `pidof X` returns an integer, than
8 > that's the PID of the currently running X server. If X is not running
9 > it will return an empty string.
10
11 That doesn't really work. `pidof X` does often return the PID of the
12 currently running X server, yes, but it does not tell you if you are
13 running under it (it can be some other user's X, for example). On the
14 other hand, the X server's process name probably is X only if you're
15 running XFree or X.org. What if you're running Xvnc? :)
16
17 You can also log in remotely and run X applications. Running `pidof X`
18 will then make absolutely no sense, as *your* X server is running on
19 the machine you logged in from...
20
21 Checking if $DISPLAY is set is the way to go. If it's not set, you
22 cannot start any X apps anyway. (Well, sometimes you can if you know
23 what your display is, but if we knew that we wouldn't be having this
24 conversation.)
25
26 --
27 Marko Vallius # PGP public key A4B84F58
28
29 --
30 gentoo-user@g.o mailing list