From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MLwBc-0005UW-MY for qemu-devel@nongnu.org; Wed, 01 Jul 2009 05:33:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MLwBX-0005P1-MX for qemu-devel@nongnu.org; Wed, 01 Jul 2009 05:33:03 -0400 Received: from [199.232.76.173] (port=48643 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MLwBX-0005Op-D0 for qemu-devel@nongnu.org; Wed, 01 Jul 2009 05:32:59 -0400 Received: from one.firstfloor.org ([213.235.205.2]:42561) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MLwBX-0007zq-18 for qemu-devel@nongnu.org; Wed, 01 Jul 2009 05:32:59 -0400 Received: from basil.firstfloor.org (p5B3CB7E5.dip0.t-ipconnect.de [91.60.183.229]) by one.firstfloor.org (Postfix) with ESMTP id 459E41A98002 for ; Wed, 1 Jul 2009 11:32:53 +0200 (CEST) Date: Wed, 1 Jul 2009 11:32:52 +0200 From: Andi Kleen Message-ID: <20090701093251.GA12447@basil.fritz.box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] Allow setting qemu process name List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org [this is a port of a old KVM userland patch I had; Avi back then suggested to submit it to qemu] Set the Linux process name to the name argument specified with "-name". I find this useful to see which guests are taking CPU time in top. This doesn't affect ps, which checks argv[0], but rewriting the environment uses much more code, so I only used this simple way. Signed-off-by: Andi Kleen diff --git a/vl.c b/vl.c index 7b7489c..584c48e 100644 --- a/vl.c +++ b/vl.c @@ -68,6 +68,7 @@ #include #include #include +#include /* For the benefit of older linux systems which don't supply it, we use a local copy of hpet.h. */ @@ -526,6 +527,19 @@ void hw_error(const char *fmt, ...) va_end(ap); abort(); } + +static void set_proc_name(const char *prefix, const char *s) +{ +#ifdef __linux__ + char name[16]; + if (!s) + return; + /* Could rewrite argv[0] too, but that's a bit more complicated. + This simple way is enough for `top'. */ + snprintf(name, sizeof name, "%s-%.10s", prefix, s); + prctl(PR_SET_NAME, name); +#endif +} /***************/ /* ballooning */ @@ -6008,11 +6022,15 @@ int main(int argc, char **argv, char **envp) if (kvm_enabled()) { int ret; + set_proc_name("kvm", qemu_name); + ret = kvm_init(smp_cpus); if (ret < 0) { fprintf(stderr, "failed to initialize KVM\n"); exit(1); } + } else { + set_proc_name("qemu", qemu_name); } if (monitor_device) { -- ak@linux.intel.com -- Speaking for myself only.