public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Peter Gordon <admin@ramshacklestudios.com>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Can a script tell if it's running under X?
Date: Sat, 04 Dec 2004 14:54:47 -0800	[thread overview]
Message-ID: <41B24037.1050901@ramshacklestudios.com> (raw)
In-Reply-To: <9acccfe5041204133432d7a3e@mail.gmail.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kevin O'Gorman wrote:
| Is there a way for a script (bash, for instance) to know
| if it's running under X, such as in an xterm or konsole?
|
| I want to have scripts that run graphical tools if the
| infrastructure is present, and text tools otherwise.
| For me this is particularly useful for tools I don't use
| all that often, and can forget that a graphical version
| exists.

One way to do it (though I don't know how to do this in Bash) is to check X's
Process ID (PID). If `pidof X` returns an integer, than that's the PID of the
currently running X server. If X is not running it will return an empty string.

/home/peter $ pidof X
12521

/home/peter $ pidof non-running-app


/home/peter $

Hope this helps!

- --
()  The ASCII Ribbon Campaign - against HTML Email,
/\  vCards, and proprietary formats.
- ---------------------------------------------------
Peter A. Gordon (codergeek42)
E-Mail: admin@ramshacklestudios.com
GPG Public Key ID: 0x109DBECE
GPG Key Fingerprint (SHA1):
~  E485 E2F7 11CE F9B2 E3D9 C95D 208F B732 109D BECE
Encrypted and/or Signed correspondence preffered.
- ---------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBskA1II+3MhCdvs4RAjCOAKCzApn5hQ6w0yor2JMp2xASs8BzeQCgkUyp
5Yi1b6GIKNHVR2QYEwIFfEE=
=9Wp6
-----END PGP SIGNATURE-----

--
gentoo-user@gentoo.org mailing list


  parent reply	other threads:[~2004-12-04 22:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-04 21:34 [gentoo-user] Can a script tell if it's running under X? Kevin O'Gorman
2004-12-04 21:43 ` Nick Rout
2004-12-06  2:07   ` cdemarco
2004-12-06  4:19     ` Iain Buchanan
2004-12-04 21:45 ` Matan Peled
2004-12-05  0:55   ` Bastian Balthazar Bux
2004-12-04 22:54 ` Peter Gordon [this message]
2004-12-05  0:22   ` Collins Richey
2004-12-05  7:31     ` Peter Gordon
2004-12-05 15:08       ` Collins Richey
2004-12-05  8:25   ` Uwe Thiem
2004-12-05  8:27   ` Marko Vallius

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41B24037.1050901@ramshacklestudios.com \
    --to=admin@ramshacklestudios.com \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox