Gentoo Archives: gentoo-user

From: Collins Richey <crichey@×××××.com>
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 00:23:12
Message-Id: e00942e40412041622161656c4@mail.gmail.com
In Reply to: Re: [gentoo-user] Can a script tell if it's running under X? by Peter Gordon
1 On Sat, 04 Dec 2004 14:54:47 -0800, Peter Gordon
2 <admin@×××××××××××××××××.com> wrote:
3 > -----BEGIN PGP SIGNED MESSAGE-----
4 > Hash: SHA1
5 >
6 > Kevin O'Gorman wrote:
7 > | Is there a way for a script (bash, for instance) to know
8 > | if it's running under X, such as in an xterm or konsole?
9 > |
10 > | I want to have scripts that run graphical tools if the
11 > | infrastructure is present, and text tools otherwise.
12 > | For me this is particularly useful for tools I don't use
13 > | all that often, and can forget that a graphical version
14 > | exists.
15 >
16 > One way to do it (though I don't know how to do this in Bash) is to check X's
17 > Process ID (PID). If `pidof X` returns an integer, than that's the PID of the
18 > currently running X server. If X is not running it will return an empty string.
19 >
20 > /home/peter $ pidof X
21 > 12521
22 >
23 > /home/peter $ pidof non-running-app
24 >
25 > /home/peter $
26 >
27 > Hope this helps!
28 >
29
30 For the normal non-root user case, this would be '/sbin/pidof X',
31 unless you have monkeyed with the standard $PATH setup.
32
33 --
34 Collins
35
36 --
37 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Can a script tell if it's running under X? Peter Gordon <admin@×××××××××××××××××.com>