Skip to content

Commit 79a6f6c

Browse files
tanriolBenBE
authored andcommitted
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.
1 parent deb05fe commit 79a6f6c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ProcessList.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,17 @@ static void ProcessList_buildTree(ProcessList* this) {
274274

275275
// If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0)
276276
// on Mac OS X 10.11.6) regard this process as root.
277-
if (process->pid == ppid)
277+
if (process->pid == ppid) {
278278
process->isRoot = true;
279+
continue;
280+
}
279281

280282
// On Linux both the init process (pid 1) and the root UMH kernel thread (pid 2)
281283
// use a ppid of 0. As that PID can't exist, we can skip searching for it.
282-
if (!ppid)
284+
if (!ppid) {
283285
process->isRoot = true;
286+
continue;
287+
}
284288

285289
// We don't know about its parent for whatever reason
286290
if (ProcessList_findProcess(this, ppid) == NULL)

0 commit comments

Comments
 (0)