diff options
author | Angelo Marletta <angelo.marletta@gmail.com> | 2012-06-07 16:42:46 +0100 |
---|---|---|
committer | Angelo Marletta <angelo.marletta@gmail.com> | 2012-06-07 16:42:46 +0100 |
commit | 10c2915dd464de44047f182ecae9c8b34e24e772 (patch) | |
tree | 63938b5a5ed16bfc9ad865fb1a809ac4f1ec738c /tests | |
parent | cedb83232379d80a9abd2ca72e60d64e5b50d92b (diff) | |
download | cpulimit-10c2915dd464de44047f182ecae9c8b34e24e772.tar.gz |
new cross-platform code to list processes. works on linux and freebsd
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile | 11 | ||||
-rwxr-xr-x | tests/busy | bin | 5220 -> 5484 bytes | |||
-rwxr-xr-x | tests/process_iterator_test | bin | 0 -> 6895 bytes | |||
-rw-r--r-- | tests/process_iterator_test.c | 18 |
4 files changed, 28 insertions, 1 deletions
diff --git a/tests/Makefile b/tests/Makefile index 11f7e2a..7f1c8b4 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,13 +1,22 @@ CC?=gcc CFLAGS?=-Wall -O2 -TARGETS=busy +TARGETS=busy process_iterator_test LIBS?=-lpthread +UNAME := $(shell uname) + +ifeq ($(UNAME), FreeBSD) +LIBS+=-lkvm +endif + all:: $(TARGETS) busy: busy.c $(LIBS) $(CC) -o busy busy.c $(LIBS) $(CFLAGS) +process_iterator_test: process_iterator_test.c $(LIBS) + $(CC) -I../src -o process_iterator_test process_iterator_test.c ../src/process_iterator.o $(LIBS) $(CFLAGS) + clean: rm -f *~ *.o $(TARGETS) diff --git a/tests/process_iterator_test b/tests/process_iterator_test Binary files differnew file mode 100755 index 0000000..979cf89 --- /dev/null +++ b/tests/process_iterator_test diff --git a/tests/process_iterator_test.c b/tests/process_iterator_test.c new file mode 100644 index 0000000..080195a --- /dev/null +++ b/tests/process_iterator_test.c @@ -0,0 +1,18 @@ +#include <stdio.h> +#include <process_iterator.h> + +int main() +{ + struct process_iterator it; + struct process process; + init_process_iterator(&it); + while (read_next_process(&it, &process) != -1) + { + printf("Read process %d\n", process.pid); + printf("Parent %d\n", process.ppid); +// printf("Starttime %d\n", process.starttime); + printf("Jiffies %d\n", process.last_jiffies); + } + close_process_iterator(&it); + return 0; +} |