From 720fa1ade10ff521307aa0cfb9c560d631ab91c5 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Tue, 29 Nov 2022 15:38:12 +0200 Subject: [PATCH] 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 --- pidlib.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; } -- 2.44.0