Add support for the memsw limits that limit memory+swap
[compctl.git] / cgroup.h
blobfb08728103ce3bf7350426e99ed441682631d2d5
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);
22 /* Add a task to a given cgroup. Return 1 on success, -1 on failure. */
23 int cgroup_add_task(const char *chier, const char *cgroup, pid_t pid);
24 /* Check if a task is in a given cgroup. Return 0/1, -1 on failure. */
25 int cgroup_is_task_in_cgroup(const char *chier, const char *cgroup, pid_t pid);
26 /* Store a list of tasks in a given cgroup to @tasks. Returns number of tasks
27 * or -1 on failure. */
28 int cgroup_task_list(const char *chier, const char *cgroup, pid_t **tasks);
30 /* Get memory limit of a given cgroup. Return (size_t) -1 on failure. */
31 size_t cgroup_get_mem_limit(const char *chier, const char *cgroup);
32 /* Set a memory limit of a given cgroup. Return 1 on success, -1 on failure. */
33 int cgroup_set_mem_limit(const char *chier, const char *cgroup, size_t limit);
34 /* Get memory usage of a given cgroup. Return (size_t) -1 on failure. */
35 size_t cgroup_get_mem_usage(const char *chier, const char *cgroup);
37 #endif