From ca6cabe41dcaaf74a344e27b4438a20e6f5a2a4f Mon Sep 17 00:00:00 2001 From: Benoit Dejean Date: Sun, 21 Jun 2015 20:23:27 +0200 Subject: [PATCH] For processes with threads, only reports the pid once. On my system, this brings proclist's output from +300 to 72. --- sysdeps/freebsd/proclist.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sysdeps/freebsd/proclist.c b/sysdeps/freebsd/proclist.c index 975c7e29..19fae167 100644 --- a/sysdeps/freebsd/proclist.c +++ b/sysdeps/freebsd/proclist.c @@ -70,6 +70,7 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf, glibtop_proc_state procstate; size_t len; unsigned int i; + pid_t prev; glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROCLIST), 0); @@ -97,6 +98,17 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf, pid = (pid_t) pinfo[i].ki_pid; + /* If a process has many threads, kern.proc.all reports multiple + times the same pid. So don't look twice at the same pid. + FIXME?: not sure that kern.proc.all reports a partially sorted + list (all pid/threads grouped). + */ + if (i > 0 && pid == prev) { + continue; + } + + prev = pid; + switch (which & GLIBTOP_KERN_PROC_MASK) { case GLIBTOP_KERN_PROC_ALL: break;