~ubuntu-branches/ubuntu/maverick/libcgroup/maverick-proposed

« back to all changes in this revision

Viewing changes to tests/walk_task.c

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-08-26 11:29:17 UTC
  • Revision ID: james.westby@ubuntu.com-20090826112917-402ews2uj6v350d2
Tags: upstream-0.34
ImportĀ upstreamĀ versionĀ 0.34

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <libcgroup.h>
 
3
#include <stdlib.h>
 
4
#include <string.h>
 
5
#include <errno.h>
 
6
 
 
7
int main(int argc, char *argv[])
 
8
{
 
9
        int ret, i;
 
10
        char *group = NULL;
 
11
        void *handle;
 
12
 
 
13
        if (argc < 2) {
 
14
                printf("No list of groups provided\n");
 
15
                return -1;
 
16
        }
 
17
 
 
18
        ret = cgroup_init();
 
19
 
 
20
        if (ret) {
 
21
                printf("cgroup_init failed with %s\n", cgroup_strerror(ret));
 
22
                return -1;
 
23
        }
 
24
 
 
25
        for (i = 1; i < argc; i++) {
 
26
                pid_t pid;
 
27
                group = strdup(argv[i]);
 
28
                printf("Printing the details of groups %s\n", group);
 
29
                ret = cgroup_get_task_begin(group, "cpu", &handle, &pid);
 
30
                while (!ret) {
 
31
                        printf("Pid is %u\n", pid);
 
32
                        ret = cgroup_get_task_next(&handle, &pid);
 
33
                        if (ret && ret != ECGEOF) {
 
34
                                printf("cgroup_get_task_next failed with %s\n",
 
35
                                                        cgroup_strerror(ret));
 
36
                                if (ret == ECGOTHER)
 
37
                                        printf("failure with %s\n",
 
38
                                                        strerror(errno));
 
39
                                return -1;
 
40
                        }
 
41
                }
 
42
                free(group);
 
43
                group = NULL;
 
44
                ret = cgroup_get_task_end(&handle);
 
45
        }
 
46
 
 
47
        return 0;
 
48
 
 
49
}