From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19471 invoked from network); 5 Dec 2004 00:23:12 +0000 Received: from smtp.gentoo.org (156.56.111.197) by lists.gentoo.org with AES256-SHA encrypted SMTP; 5 Dec 2004 00:23:12 +0000 Received: from lists.gentoo.org ([156.56.111.196] helo=parrot.gentoo.org) by smtp.gentoo.org with esmtp (Exim 4.41) id 1CakBE-0004Pi-No for arch-gentoo-user@lists.gentoo.org; Sun, 05 Dec 2004 00:23:12 +0000 Received: (qmail 10156 invoked by uid 89); 5 Dec 2004 00:22:57 +0000 Mailing-List: contact gentoo-user-help@gentoo.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail Reply-To: gentoo-user@lists.gentoo.org X-BeenThere: gentoo-user@gentoo.org Received: (qmail 18929 invoked from network); 5 Dec 2004 00:22:56 +0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=MD80+ReWQHfkOJ8icwZbAhEylL12DCG5ToYYxRyWHcmCDjM6gUSEKKiZT+gTuiygB26LbsKJ7dZEqN4I2rmp0JyNuxx78z0KOLL07k4WBGryKTSyfkI+bt+J58kDa15UzbvMX9grovpKbCFk0sNcsT7egnqyv7weLwEgtyJLdWQ= Message-ID: Date: Sat, 4 Dec 2004 17:22:56 -0700 From: Collins Richey Reply-To: Collins Richey To: gentoo-user@lists.gentoo.org In-Reply-To: <41B24037.1050901@ramshacklestudios.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <9acccfe5041204133432d7a3e@mail.gmail.com> <41B24037.1050901@ramshacklestudios.com> Subject: Re: [gentoo-user] Can a script tell if it's running under X? X-Archives-Salt: d4f5986d-7b84-4b49-a559-d2ddcca68d02 X-Archives-Hash: 6da4e9ab1ae9960c0dd7cabf0fe6c80f On Sat, 04 Dec 2004 14:54:47 -0800, Peter Gordon wrote: > -----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! > For the normal non-root user case, this would be '/sbin/pidof X', unless you have monkeyed with the standard $PATH setup. -- Collins -- gentoo-user@gentoo.org mailing list