From 79a6f6cb5b9d059c9a70e67cc16157b28f5b8758 Mon Sep 17 00:00:00 2001 From: Denis Lisov Date: Fri, 7 Jan 2022 02:23:21 +0300 Subject: [PATCH] ProcessList_buildTree: skip hashtable if known root Don't waste time looking up the parent if the current process is already known to be a root process. --- ProcessList.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ProcessList.c b/ProcessList.c index e86f6ea4..2e99041e 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -274,13 +274,17 @@ static void ProcessList_buildTree(ProcessList* this) { // If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0) // on Mac OS X 10.11.6) regard this process as root. - if (process->pid == ppid) + if (process->pid == ppid) { process->isRoot = true; + continue; + } // On Linux both the init process (pid 1) and the root UMH kernel thread (pid 2) // use a ppid of 0. As that PID can't exist, we can skip searching for it. - if (!ppid) + if (!ppid) { process->isRoot = true; + continue; + } // We don't know about its parent for whatever reason if (ProcessList_findProcess(this, ppid) == NULL)