/etc/compctl-unlimited control file support
[compctl.git] / cgroup.h
blobbf22a5a30172c9c01b787bb91e24b2b4c91bb1bf
1 /* Tiny cgroup manipulation toolkit. libcgroup is a mess. */
3 #ifndef CGROUP__H
4 #define CGROUP__H
6 #include <stdbool.h>
7 #include <sys/types.h>
9 /* In case of errors, this function is called; it is expected to
10 * report @s and errno contents. By default, it is bound to perror,
11 * but you can change that if you want e.g. to syslog errors. */
12 extern void (*cgroup_perror)(const char *s);
14 /* Setup the cgroups machinery and @chier cgroups hierarchy using
15 * @controllers. Return 0 if cgroups already set up, 1 on success,
16 * -1 on failure. */
17 int cgroup_setup(const char *chier, const char *controllers);
18 /* Setup a given control group. Return 0 if cgroups already set up,
19 * 1 on success, -1 on failure. */
20 int cgroup_create(const char *chier, const char *cgroup);
21 /* Return true if cgroup control is set up, false otherwise. */
22 bool cgroup_available(const char *chier, const char *cgroup);
24 /* Add a task to a given cgroup. Return 1 on success, -1 on failure. */
25 int cgroup_add_task(const char *chier, const char *cgroup, pid_t pid);
26 /* Check if a task is in a given cgroup. Return 0/1, -1 on failure. */
27 int cgroup_is_task_in_cgroup(const char *chier, const char *cgroup, pid_t pid);
28 /* Store a list of tasks in a given cgroup to @tasks. Returns number of tasks
29 * or -1 on failure. */
30 int cgroup_task_list(const char *chier, const char *cgroup, pid_t **tasks);
32 /* Get memory limit of a given cgroup. Return (size_t) -1 on failure. */
33 size_t cgroup_get_mem_limit(const char *chier, const char *cgroup);
34 /* Set a memory limit of a given cgroup. Return 1 on success, -1 on failure. */
35 int cgroup_set_mem_limit(const char *chier, const char *cgroup, size_t limit);
36 /* Get memory usage of a given cgroup. Return (size_t) -1 on failure. */
37 size_t cgroup_get_mem_usage(const char *chier, const char *cgroup);
39 #endif