summaryrefslogtreecommitdiffstats
path: root/ProcessList.c
diff options
context:
space:
mode:
authorDenis Lisov <dennis.lissov@gmail.com>2021-12-13 01:34:27 +0300
committerBenBE <BenBE@geshi.org>2022-02-13 19:50:16 +0100
commit1a403eb7eb605927a79424144570b354c8143caa (patch)
tree47dcfdeeb68d0ebe3a9b271cec46b2bd8f0822c5 /ProcessList.c
parenta3a7958721607b8520199563d478a315dfac678f (diff)
ProcessList_buildTree: lookup parent via hashtable
While this change does not significantly affect performance, it removes the internal requirement to have the process list sorted by PID.
Diffstat (limited to 'ProcessList.c')
-rw-r--r--ProcessList.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/ProcessList.c b/ProcessList.c
index ef714b46..04d618c7 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -433,36 +433,24 @@ static void ProcessList_buildTree(ProcessList* this) {
}
pid_t ppid = Process_getParentPid(process);
-
- // Bisect the process vector to find parent
- int l = 0;
- int r = size;
+ bool isRoot = false;
// If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0)
- // on Mac OS X 10.11.6) cancel bisecting and regard this process as
- // root.
+ // on Mac OS X 10.11.6) regard this process as root.
if (process->pid == ppid)
- r = 0;
+ isRoot = true;
// 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)
- r = 0;
-
- while (l < r) {
- int c = (l + r) / 2;
- pid_t pid = ((Process*)Vector_get(this->processes, c))->pid;
- if (ppid == pid) {
- break;
- } else if (ppid < pid) {
- r = c;
- } else {
- l = c + 1;
- }
- }
+ isRoot = true;
+
+ // Lookup the parent via the processTable hashtable not modified in buildTree
+ if (ProcessList_findProcess(this, ppid) == NULL)
+ isRoot = true;
// If parent not found, then construct the tree with this node as root
- if (l >= r) {
+ if (isRoot) {
process = (Process*)Vector_take(this->processes, i);
process->indent = 0;
process->tree_depth = 0;

© 2014-2024 Faster IT GmbH | imprint | privacy policy