Gentoo Archives: gentoo-user

From: Peter Gordon <admin@×××××××××××××××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Can a script tell if it's running under X?
Date: Sat, 04 Dec 2004 22:55:10
Message-Id: 41B24037.1050901@ramshacklestudios.com
In Reply to: [gentoo-user] Can a script tell if it's running under X? by Kevin O'Gorman
1 -----BEGIN PGP SIGNED MESSAGE-----
2 Hash: SHA1
3
4 Kevin O'Gorman wrote:
5 | Is there a way for a script (bash, for instance) to know
6 | if it's running under X, such as in an xterm or konsole?
7 |
8 | I want to have scripts that run graphical tools if the
9 | infrastructure is present, and text tools otherwise.
10 | For me this is particularly useful for tools I don't use
11 | all that often, and can forget that a graphical version
12 | exists.
13
14 One way to do it (though I don't know how to do this in Bash) is to check X's
15 Process ID (PID). If `pidof X` returns an integer, than that's the PID of the
16 currently running X server. If X is not running it will return an empty string.
17
18 /home/peter $ pidof X
19 12521
20
21 /home/peter $ pidof non-running-app
22
23
24 /home/peter $
25
26 Hope this helps!
27
28 - --
29 () The ASCII Ribbon Campaign - against HTML Email,
30 /\ vCards, and proprietary formats.
31 - ---------------------------------------------------
32 Peter A. Gordon (codergeek42)
33 E-Mail: admin@×××××××××××××××××.com
34 GPG Public Key ID: 0x109DBECE
35 GPG Key Fingerprint (SHA1):
36 ~ E485 E2F7 11CE F9B2 E3D9 C95D 208F B732 109D BECE
37 Encrypted and/or Signed correspondence preffered.
38 - ---------------------------------------------------
39 -----BEGIN PGP SIGNATURE-----
40 Version: GnuPG v1.2.6 (GNU/Linux)
41 Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
42
43 iD8DBQFBskA1II+3MhCdvs4RAjCOAKCzApn5hQ6w0yor2JMp2xASs8BzeQCgkUyp
44 5Yi1b6GIKNHVR2QYEwIFfEE=
45 =9Wp6
46 -----END PGP SIGNATURE-----
47
48 --
49 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Can a script tell if it's running under X? Collins Richey <crichey@×××××.com>
Re: [gentoo-user] Can a script tell if it's running under X? Marko Vallius <markvall@×××.fi>
Re: [gentoo-user] Can a script tell if it's running under X? Uwe Thiem <uwix@××××.na>