aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAngelo Marletta <angelo.marletta@gmail.com>2012-06-07 02:24:56 +0100
committerAngelo Marletta <angelo.marletta@gmail.com>2012-06-07 02:24:56 +0100
commitd72e395ac6107e89b92e1c931b4b84ca42f60c2b (patch)
tree03ccefb6560690517fc49077a67b36a225b3c783 /src
parent3c10d8dc5820fde90bd293d95d82f5e4302d1c7d (diff)
downloadcpulimit-d72e395ac6107e89b92e1c931b4b84ca42f60c2b.tar.gz
started process iterator for FreeBSD. still unstable.
Diffstat (limited to 'src')
-rwxr-xr-x[-rw-r--r--]src/Makefile2
-rw-r--r--src/process.c2
-rw-r--r--src/procutils.c21
-rw-r--r--src/procutils.h2
4 files changed, 24 insertions, 3 deletions
diff --git a/src/Makefile b/src/Makefile
index 6deb69b..6e7a89e 100644..100755
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,7 +1,7 @@
CC?=gcc
CFLAGS?=-Wall -O2 -D_GNU_SOURCE
TARGETS=cpulimit
-LIBS=process.o procutils.o list.o
+LIBS=process.o procutils.o list.o -lkvm
all:: $(TARGETS)
diff --git a/src/process.c b/src/process.c
index 4f7403b..73c5883 100644
--- a/src/process.c
+++ b/src/process.c
@@ -170,7 +170,7 @@ static int get_jiffies(struct process *proc) {
return -1;
}
- process_data = kvm_getprocs(my_kernel, KERN_PROC_PID, pid, &processes);
+ process_data = kvm_getprocs(my_kernel, KERN_PROC_PID, proc->pid, &processes);
if ( (process_data) && (processes >= 1) )
my_jiffies = process_data->ki_runtime;
diff --git a/src/procutils.c b/src/procutils.c
index fb7aaae..7cf0e71 100644
--- a/src/procutils.c
+++ b/src/procutils.c
@@ -29,6 +29,7 @@
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/sysctl.h>
#include "procutils.h"
@@ -37,6 +38,10 @@
#include <errno.h>
#endif
+#ifdef __FreeBSD__
+#include <kvm.h>
+#endif
+
/* PROCESS STATISTICS FUNCTIONS */
//deprecated
@@ -190,6 +195,22 @@ int init_process_iterator(struct process_iterator *i) {
i->procList = result;
i->count = err == 0 ? length / sizeof *result : 0;
i->c = 0;
+#elif defined __FreeBSD__
+ kvm_t *kd;
+ struct kinfo_proc *procs = NULL;
+ char errbuf[_POSIX2_LINE_MAX];
+ int count;
+ /* Open the kvm interface, get a descriptor */
+ if ((kd = kvm_open(NULL, NULL, NULL, 0, errbuf)) == NULL) {
+ /* fprintf(stderr, "kvm_open: %s\n", errbuf); */
+ fprintf(stderr, "kvm_open: ", errbuf);
+ }
+ /* Get the list of processes. */
+ if ((procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, &count)) == NULL) {
+ kvm_close(kd);
+ /* fprintf(stderr, "kvm_getprocs: %s\n", kvm_geterr(kd)); */
+ fprintf(stderr, "kvm_getprocs: ", kvm_geterr(kd));
+ }
#endif
i->current = (struct process*)calloc(1, sizeof(struct process));
diff --git a/src/procutils.h b/src/procutils.h
index b5a91a3..c39a239 100644
--- a/src/procutils.h
+++ b/src/procutils.h
@@ -62,7 +62,7 @@ struct process_iterator {
struct kinfo_proc *procList;
int count;
int c;
-#elif defined __hpux
+#elif defined __FreeBSD__
int count;
#endif
struct process *current;
Un proyecto texto-plano.xyz