aboutsummaryrefslogtreecommitdiffstats
path: root/ProcessTable.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2024-01-10 11:17:08 +0100
committerDaniel Lange <DLange@git.local>2024-01-10 11:17:08 +0100
commite7372d18a1a661d8c3dba9f51e1f17b5f94171a7 (patch)
treee8270dd60ec096bee8157dbadf029e15ed584592 /ProcessTable.c
parent937052b231259a47d881d539ad5748245ef55b99 (diff)
downloaddebian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.tar.gz
debian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.tar.bz2
debian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.zip
New upstream version 3.3.0
Diffstat (limited to 'ProcessTable.c')
-rw-r--r--ProcessTable.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/ProcessTable.c b/ProcessTable.c
new file mode 100644
index 0000000..ac6fc70
--- /dev/null
+++ b/ProcessTable.c
@@ -0,0 +1,92 @@
+/*
+htop - ProcessTable.c
+(C) 2004,2005 Hisham H. Muhammad
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "config.h" // IWYU pragma: keep
+
+#include "ProcessTable.h"
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include "Hashtable.h"
+#include "Row.h"
+#include "Settings.h"
+#include "Vector.h"
+
+
+void ProcessTable_init(ProcessTable* this, const ObjectClass* klass, Machine* host, Hashtable* pidMatchList) {
+ Table_init(&this->super, klass, host);
+
+ this->pidMatchList = pidMatchList;
+}
+
+void ProcessTable_done(ProcessTable* this) {
+ Table_done(&this->super);
+}
+
+Process* ProcessTable_getProcess(ProcessTable* this, pid_t pid, bool* preExisting, Process_New constructor) {
+ const Table* table = &this->super;
+ Process* proc = (Process*) Hashtable_get(table->table, pid);
+ *preExisting = proc != NULL;
+ if (proc) {
+ assert(Vector_indexOf(table->rows, proc, Row_idEqualCompare) != -1);
+ assert(Process_getPid(proc) == pid);
+ } else {
+ proc = constructor(table->host);
+ assert(proc->cmdline == NULL);
+ Process_setPid(proc, pid);
+ }
+ return proc;
+}
+
+static void ProcessTable_prepareEntries(Table* super) {
+ ProcessTable* this = (ProcessTable*) super;
+ this->totalTasks = 0;
+ this->userlandThreads = 0;
+ this->kernelThreads = 0;
+ this->runningTasks = 0;
+
+ Table_prepareEntries(super);
+}
+
+static void ProcessTable_iterateEntries(Table* super) {
+ ProcessTable* this = (ProcessTable*) super;
+ // calling into platform-specific code
+ ProcessTable_goThroughEntries(this);
+}
+
+static void ProcessTable_cleanupEntries(Table* super) {
+ Machine* host = super->host;
+ const Settings* settings = host->settings;
+
+ // Finish process table update, culling any exit'd processes
+ for (int i = Vector_size(super->rows) - 1; i >= 0; i--) {
+ Process* p = (Process*) Vector_get(super->rows, i);
+
+ // tidy up Process state after refreshing the ProcessTable table
+ Process_makeCommandStr(p, settings);
+
+ // keep track of the highest UID for column scaling
+ if (p->st_uid > host->maxUserId)
+ host->maxUserId = p->st_uid;
+
+ Table_cleanupRow(super, (Row*) p, i);
+ }
+
+ // compact the table in case of deletions
+ Table_compact(super);
+}
+
+const TableClass ProcessTable_class = {
+ .super = {
+ .extends = Class(Table),
+ .delete = ProcessTable_delete,
+ },
+ .prepare = ProcessTable_prepareEntries,
+ .iterate = ProcessTable_iterateEntries,
+ .cleanup = ProcessTable_cleanupEntries,
+};

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