From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MTwmp-0001mq-Q6 for qemu-devel@nongnu.org; Thu, 23 Jul 2009 07:48:35 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MTwmg-0001jP-S5 for qemu-devel@nongnu.org; Thu, 23 Jul 2009 07:48:32 -0400 Received: from [199.232.76.173] (port=42112 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTwmf-0001j9-2p for qemu-devel@nongnu.org; Thu, 23 Jul 2009 07:48:26 -0400 Received: from pf.freedaemonhosting.com ([66.210.104.252]:14270 helo=FreeDaemonHosting.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MTwme-0001m2-C6 for qemu-devel@nongnu.org; Thu, 23 Jul 2009 07:48:24 -0400 Date: Thu, 23 Jul 2009 06:47:16 -0500 From: "Todd T. Fries" Subject: Re: [Qemu-devel] [PATCH] Allow setting qemu process name Message-ID: <20090723114715.GA826@fries.net> References: <20090701093251.GA12447@basil.fritz.box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090701093251.GA12447@basil.fritz.box> Reply-To: todd@fries.net List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andi Kleen Cc: qemu-devel@nongnu.org Penned by Andi Kleen on 20090701 11:32.52, we have: | | [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); #elif defined(__OpenBSD__) if (!s) setproctitle("%s-%.10s", prefix, s); | +#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. | -- Todd Fries .. todd@fries.net _____________________________________________ | \ 1.636.410.0632 (voice) | Free Daemon Consulting, LLC \ 1.405.227.9094 (voice) | http://FreeDaemonConsulting.com \ 1.866.792.3418 (FAX) | "..in support of free software solutions." \ sip:freedaemon@ekiga.net | \ sip:4052279094@ekiga.net \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 37E7 D3EB 74D0 8D66 A68D B866 0326 204E 3F42 004A http://todd.fries.net/pgp.txt