char *cgroup_get_controller_name(cgroup_controller *controller)
+ int cgroup_attach_task(cgroup * cgroup)
+ int cgroup_attach_task_pid(cgroup * cgroup, pid_t pid)
+
# vim: set et ts=4 sw=4:
from posix.types cimport pid_t
cimport cgroup
+import os
cdef class Version:
CGROUP_UNK = cgroup.CGROUP_UNK
if ret is not 0:
raise RuntimeError("cgroup_delete_cgroup failed: {}".format(ret))
+ def attach(self, pid=None, root_cgroup=False):
+ """Attach a process to a cgroup
+
+ Arguments:
+ pid - pid to be attached. If none, then the current pid is attached
+ root_cgroup - if True, then the pid will be attached to the root cgroup
+
+ Description:
+ Attach a process to a cgroup
+ """
+ if pid is None:
+ if root_cgroup:
+ ret = cgroup.cgroup_attach_task(NULL)
+ else:
+ ret = cgroup.cgroup_attach_task(self._cgp)
+ else:
+ if root_cgroup:
+ ret = cgroup.cgroup_attach_task_pid(NULL, pid)
+ else:
+ ret = cgroup.cgroup_attach_task_pid(self._cgp, pid)
+
+ if ret is not 0:
+ raise RuntimeError("cgroup_attach_task failed: {}".format(ret))
+
def __dealloc__(self):
cgroup.cgroup_free(&self._cgp);