qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] Allow setting qemu process name


From: Andi Kleen
Subject: [Qemu-devel] [PATCH] Allow setting qemu process name
Date: Wed, 1 Jul 2009 11:32:52 +0200
User-agent: Mutt/1.5.17 (2007-11-01)

[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 <address@hidden>

diff --git a/vl.c b/vl.c
index 7b7489c..584c48e 100644
--- a/vl.c
+++ b/vl.c
@@ -68,6 +68,7 @@
 #include <pty.h>
 #include <malloc.h>
 #include <linux/rtc.h>
+#include <sys/prctl.h>
 
 /* 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) {
-- 
address@hidden -- Speaking for myself only.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]