From: Ewan Mellor Subject: Re: [RFC] Is this process running on which machine? Date: Sat, 18 Nov 2006 13:53:35 +0000 Message-ID: <20061118135335.GA20440@leeni.uk.xensource.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Akio Takebe Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org On Sat, Nov 18, 2006 at 06:10:57PM +0900, Akio Takebe wrote: > Hi, all > > I'd like to know "Is this process running on which machine?" > For example, a native machien, or dom0, or domU, or HVM.. > > So I research codes of xen, > then I make the following shell. > (I haven't confirmed HVM yet because I don't use VTx machine.) > What do you think about it? > > ========================================================================= > #!/bin/bash > > if [ -d /sys/hypervisor ] ; then > UUID=$(cat /sys/hypervisor/uuid) > if [ x"$UUID" == x"00000000-0000-0000-0000-000000000000" ]; then > echo "this is dom0." > else > echo "this is domU." > fi > else > IS_HVM=$(strings /proc/acpi/dsdt | grep -i xen) > if [ x"IS_HVM" != x ]; then > echo "this is hvm machine" > else > echo "this is native machine" > fi > fi I wouldn't rely upon the UUID of domain 0 being all-zeros -- there have been arguments about that in the past. The proper mechanism for doing this is grep -q "control_d" /proc/xen/capabilities This will be true if you are in the "initial control domain" (SIF_INITDOMAIN has been set). Ewan.