summaryrefslogtreecommitdiffstats
path: root/freebsd/FreeBSDProcessList.c
blob: 275c10828c057ae3a7792a3d97a20768d823a3ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
htop - UnsupportedProcessList.c
(C) 2014 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/

#include "ProcessList.h"

#include <stdlib.h>
#include <sys/sysctl.h>

/*{

}*/

ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) {
   ProcessList* this = calloc(1, sizeof(ProcessList));
   ProcessList_init(this, usersTable, pidWhiteList);

   int cpus = 1;
   size_t sizeof_cpus = sizeof(cpus);
   int err = sysctlbyname("hw.ncpu", &cpus, &sizeof_cpus, NULL, 0);
   if (err) cpus = 1;
   this->cpuCount = MAX(cpus, 1);
   this->cpus = realloc(this->cpus, cpus * sizeof(CPUData));

   for (int i = 0; i < cpus; i++) {
      this->cpus[i].totalTime = 1;
      this->cpus[i].totalPeriod = 1;
   }

   return this;
}

void ProcessList_scan(ProcessList* this) {
   (void) this;
   // stub!
}