This is the test case for the new API. This test takes one argument, the group name.
Sample run on my system with this test case returns, [dha...@gondor tests]$ ../libtool --mode=execute ./walk_task a Printing the details of groups a Pid is 6092 Pid is 11315 Pid is 11318 Pid is 11319 Pid is 11324 Pid is 13234 [dha...@gondor tests]$ Signed-off-by: Dhaval Giani <[email protected]> --- tests/Makefile.am | 3 ++- tests/walk_task.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) Index: libcg/tests/Makefile.am =================================================================== --- libcg.orig/tests/Makefile.am +++ libcg/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 Index: libcg/tests/walk_task.c =================================================================== --- /dev/null +++ libcg/tests/walk_task.c @@ -0,0 +1,49 @@ +#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 0; + } + + ret = cgroup_init(); + + if (ret) { + printf("cgroup_init failed with %s\n", cgroup_strerror(ret)); + return 0; + } + + 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)); + } + } + free(group); + group = NULL; + ret = cgroup_get_task_end((void *) tasks); + } + + return 0; + +} ------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p _______________________________________________ Libcg-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libcg-devel
