]> git.itanic.dy.fi Git - scan-pagemap/blobdiff - pidlib.c
Show full process argument list instead only executable name
[scan-pagemap] / pidlib.c
index 1d3358ebaa300eefde16a6ff71e8a8e3b6f0aa4f..73247203da432199f6c0a32ee1417069452ce451 100644 (file)
--- a/pidlib.c
+++ b/pidlib.c
@@ -137,7 +137,7 @@ int read_cmdline(int pid, int tid, char *cmdline, size_t len)
 {
        FILE *file;
        char path[512];
-       int ret;
+       int ret, i;
 
        snprintf(path, sizeof(path), "/proc/%d/task/%d/cmdline", pid, tid);
        file = fopen(path, "rb");
@@ -150,6 +150,15 @@ int read_cmdline(int pid, int tid, char *cmdline, size_t len)
                cmdline[ret - 1] = 0;
        fclose(file);
 
+       /*
+        * Process arguments are separated by NULL bytes. Replace
+        * these with spacese so that the arguments become visible
+        * too.
+        */
+       for (i = 0; i < ret - 1; i++)
+               if (cmdline[i] == '\0')
+                       cmdline[i] = ' ';
+
        return ret > 0 ? 0 : -1;
 }