]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
Handle the process name better
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Mon, 5 Jul 2010 19:21:46 +0000 (22:21 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Mon, 5 Jul 2010 19:21:46 +0000 (22:21 +0300)
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>
analyze.c
parse.c

index 4cb42e7c88ed08cc5560d32d85bac7476034264f..c9b99e3c1b7c4b7d711ede51339187a4423dc049 100644 (file)
--- a/analyze.c
+++ b/analyze.c
@@ -98,7 +98,7 @@ void print_pid_stats(struct pageframe *pf, struct process *process_list)
                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);
diff --git a/parse.c b/parse.c
index 289a27ff9e7e8eeec122b91ec52655aa2f2f4f97..e514fc09b5272ad5d1e88ed562e20fb259d04673 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -239,13 +239,15 @@ void read_pageframe(int pid, struct pageframe *pageframe,
        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;