Read the name from cmdline instead of the comm file. It appears that
at least in ubuntu kernel the comm file is not even
exposed. Furthermore, the newline in the end of the cmdline is
replaced with null byte. This also ensures that the string is always
null terminated even though the string is otherwise truncated.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
if ((swapped + present) == 0)
continue;
- printf("% 6lld %sB % 6lld %sB % 5d %s",
+ printf("% 6lld %sB % 6lld %sB % 5d %s\n",
PAGE_TO_NICE(present), PAGE_TO_NICE_UNIT(present),
PAGE_TO_NICE(swapped), PAGE_TO_NICE_UNIT(swapped),
ps->pid, ps->name);
parse_pageframe(file, pageframe, maps, add_to_tree);
fclose(file);
- snprintf(path, sizeof(path), "/proc/%d/comm", pid);
+ snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
file = fopen(path, "rb");
if (!file)
return;
ret = fread(process->name, 1, sizeof(process->name), file);
+ if (ret > 0)
+ process->name[ret - 1] = 0;
fclose(file);
return;