From: Timo Kokkonen Date: Tue, 29 Nov 2022 13:38:12 +0000 (+0200) Subject: Show full process argument list instead only executable name X-Git-Url: http://git.itanic.dy.fi/?p=scan-pagemap;a=commitdiff_plain Show full process argument list instead only executable name 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 --- diff --git a/pidlib.c b/pidlib.c index 1d3358e..7324720 100644 --- 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; }