diff options
author | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-04-22 15:30:20 +0530 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-04-22 15:46:54 +0530 |
commit | e672700698bf8078ed8cc277855760d6d030dae5 (patch) | |
tree | 1f706d0aa7e341aa325e8cf44c43f7ad70dfffdd /tests/walk_task.c | |
parent | 9414f3be0c3f191fdea212ecc3157af5e70a45de (diff) | |
download | libcg-e672700698bf8078ed8cc277855760d6d030dae5.tar.gz libcg-e672700698bf8078ed8cc277855760d6d030dae5.tar.xz libcg-e672700698bf8078ed8cc277855760d6d030dae5.zip |
libcgroup: Add test cases for new get_task API
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,
[dhaval@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
[dhaval@gondor tests]$
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Acked-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Diffstat (limited to 'tests/walk_task.c')
-rw-r--r-- | tests/walk_task.c | 50 |
1 files changed, 50 insertions, 0 deletions
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; + +} |