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 <dtorrance@piedmont.edu>
This commit is contained in:
Tilmann Hentze 2020-03-30 11:36:40 -04:00 committed by Carlos R. Mafra
parent 53bc19104a
commit 51132ae7ee

View file

@ -508,16 +508,13 @@ int process_parse_procfs(struct process *process) {
* Extract cpu times from data in /proc filesystem. * Extract cpu times from data in /proc filesystem.
* For conversion types see man proc(5). * 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, procname,
&process->user_time,&process->kernel_time, &process->user_time,&process->kernel_time,
&process->vsize,&process->rss); &process->vsize,&process->rss);
if (rc<5) if (rc<5)
return 1; return 1;
/* r = procname;
* Remove parentheses from the process name stored in /proc/ under Linux...
*/
r = procname+1;
/* remove any "kdeinit: " */ /* remove any "kdeinit: " */
if (r == strstr(r, "kdeinit")) if (r == strstr(r, "kdeinit"))
{ {
@ -559,7 +556,7 @@ int process_parse_procfs(struct process *process) {
else else
{ {
q = deparenthesised_name; q = deparenthesised_name;
while (*r && *r!=')') while (*r)
*q++ = *r++; *q++ = *r++;
*q = 0; *q = 0;
} }