diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/walk_task.c | 50 |
2 files changed, 52 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 5999389..41aebd3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/include LDADD = $(top_srcdir)/src/.libs/libcgroup.la # compile the tests, but do not install them -noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats +noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats walk_task libcgrouptest01_SOURCES=libcgrouptest01.c test_functions.c libcgrouptest.h libcg_ba_SOURCES=libcg_ba.cpp @@ -10,6 +10,7 @@ setuid_SOURCES=setuid.c pathtest_SOURCES=pathtest.c walk_test_SOURCES=walk_test.c read_stats_SOURCES=read_stats.c +walk_task_SOURCES=walk_task.c EXTRA_DIST = pathtest.sh runlibcgrouptest.sh diff --git a/tests/walk_task.c b/tests/walk_task.c new file mode 100644 index 0000000..fb89963 --- /dev/null +++ b/tests/walk_task.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <libcgroup.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +int main(int argc, char *argv[]) +{ + int ret, i; + char *group = NULL; + FILE *tasks = NULL; + + if (argc < 2) { + printf("No list of groups provided\n"); + return -1; + } + + ret = cgroup_init(); + + if (ret) { + printf("cgroup_init failed with %s\n", cgroup_strerror(ret)); + return -1; + } + + for (i = 1; i < argc; i++) { + pid_t pid; + group = strdup(argv[i]); + printf("Printing the details of groups %s\n", group); + ret = cgroup_get_task_begin(group, "cpu", (void *) &tasks, + &pid); + while (!ret) { + printf("Pid is %u\n", pid); + ret = cgroup_get_task_next((void *) tasks, &pid); + if (ret && ret != ECGEOF) { + printf("cgroup_get_task_next failed with %s\n", + cgroup_strerror(ret)); + if (ret == ECGOTHER) + printf("failure with %s\n", + strerror(errno)); + return -1; + } + } + free(group); + group = NULL; + ret = cgroup_get_task_end((void **) &tasks); + } + + return 0; + +} |