Add a new API cgroup_attach_thread_tid(), that will allow the users to
move all threads sharing the same tid (thread group leader).
Example:
---------
#include <libcgroup.h>
#include <stdio.h>
#include <stdlib.h>
#define CGRP_NAME "cgrp_foo"
int main(int argc, char **argv)
{
struct cgroup_controller *cgc = NULL;
struct cgroup *cgroup = NULL;
int ret = 0;
ret = cgroup_init();
if (ret) {
fprintf(stderr, "cgroup_init failed\n");
exit(1);
}
cgroup = cgroup_new_cgroup(CGRP_NAME);
if (!cgroup) {
fprintf(stderr, "Failed to allocate cgroup %s\n", CGRP_NAME);
exit(1);
}
cgc = cgroup_add_controller(cgroup, "cpu");
if (!cgc) {
fprintf(stderr, "Failed to add controller cpu cgroup %s\n", CGRP_NAME);
exit(1);
}
ret = cgroup_create_cgroup(cgroup, 0);
if (ret)
fprintf(stderr, "Failed to create cgroup %s\n", CGRP_NAME);
ret = cgroup_attach_thread_tid(cgroup, atoi(argv[1]));
if (ret)
fprintf(stderr, "failed to write threads tid %d\n", atoi(argv[1]));
cgroup_free(&cgroup);
exit(0);
}
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
*/
int cgroup_register_unchanged_process(pid_t pid, int flags);
+/**
+ * Move given threads (=thread) to given control group.
+ * @param cgroup Destination control group.
+ * @param tid The task to move.
+ */
+int cgroup_attach_thread_tid(struct cgroup *cgroup, pid_t tid);
+
/**
* @}
* @}
return cgroup_attach_task_tid(cgroup, tid, 0);
}
+/**
+ * cgroup_attach_thread_tid is used to assign threads to a cgroup.
+ * struct cgroup *cgroup: The cgroup to assign the thread to.
+ * pid_t tid: The thread to be assigned to the cgroup.
+ *
+ * returns 0 on success.
+ * returns ECGROUPNOTOWNER if the caller does not have access to the cgroup.
+ * returns ECGROUPNOTALLOWED for other causes of failure.
+ */
+int cgroup_attach_thread_tid(struct cgroup *cgroup, pid_t tid)
+{
+ return cgroup_attach_task_tid(cgroup, tid, 1);
+}
+
/**
* cg_mkdir_p, emulate the mkdir -p command (recursively creating paths)
* @path: path to create
is_cgroup_mode_hybrid;
is_cgroup_mode_unified;
cgroup_is_systemd_enabled;
+ cgroup_attach_thread_tid;
} CGROUP_2.0;