]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
Show full process argument list instead only executable name master
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Tue, 29 Nov 2022 13:38:12 +0000 (15:38 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Tue, 29 Nov 2022 13:38:12 +0000 (15:38 +0200)
Some systems have same executable running multiple times, executed
with different command line arguments. These may be difficult to
distinguish from each other if we don't see also the arguments.

Show the whole argument list for each processes as this usually what
we want to see.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
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;
 }