From 51132ae7ee500abd56d315a3947df9e7e0ef1470 Mon Sep 17 00:00:00 2001 From: Tilmann Hentze <0xcafe@directbox.com> Date: Mon, 30 Mar 2020 11:36:40 -0400 Subject: [PATCH] wmtop: patch for process name extraction on Linux I received the following patch from Tilmann Hentze <0xcafe@directbox.com> in an email: > Hello, > there are processes, that have space characters in their names, for example > Firefoxe's "Web Content" process. > The current sscanf line for Linux would only considers the first part of > the process name, e.g. "Web" and cut off the rest. > Attached patch should consider the complete process name between parentheses. > Further I did not touch the handling of removal of "kdeinit", since > I am not using KDE and am not sure if the assumptions in the source code > are still valid. > Best Regards, > Tilmann. Signed-off-by: Doug Torrance --- wmtop/wmtop.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/wmtop/wmtop.c b/wmtop/wmtop.c index bf065de..2f648ee 100644 --- a/wmtop/wmtop.c +++ b/wmtop/wmtop.c @@ -508,16 +508,13 @@ int process_parse_procfs(struct process *process) { * Extract cpu times from data in /proc filesystem. * For conversion types see man proc(5). */ - rc = sscanf(line,"%*s %s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lu %lu %*s %*s %*s %*s %*s %*s %*s %lu %ld", + rc = sscanf(line,"%*s (%[^)]) %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %lu %lu %*s %*s %*s %*s %*s %*s %*s %lu %ld", procname, &process->user_time,&process->kernel_time, &process->vsize,&process->rss); if (rc<5) return 1; - /* - * Remove parentheses from the process name stored in /proc/ under Linux... - */ - r = procname+1; + r = procname; /* remove any "kdeinit: " */ if (r == strstr(r, "kdeinit")) { @@ -559,7 +556,7 @@ int process_parse_procfs(struct process *process) { else { q = deparenthesised_name; - while (*r && *r!=')') + while (*r) *q++ = *r++; *q = 0; }