This patch adds a function to count the number of tasks in the
container. The result is not reliable as it may change with a fork
or an exit, but in some cases, for example, there is only one task, or
the container is frozen, the result is accurate.
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
close(fd);
return ret;
}
+
+int lxc_cgroup_nrtasks(const char *name)
+{
+ char *nsgroup;
+ char path[MAXPATHLEN];
+ int pid, ret, count = 0;
+ FILE *file;
+
+ ret = lxc_cgroup_path_get(&nsgroup, name);
+ if (ret)
+ return -1;
+
+ snprintf(path, MAXPATHLEN, "%s/tasks", nsgroup);
+
+ file = fopen(path, "r");
+ if (!file) {
+ SYSERROR("fopen '%s' failed", path);
+ return -1;
+ }
+
+ while (fscanf(file, "%d", &pid) != EOF)
+ count++;
+
+ fclose(file);
+
+ return count;
+}
int lxc_rename_nsgroup(const char *name, struct lxc_handler *handler);
int lxc_unlink_nsgroup(const char *name);
int lxc_cgroup_path_get(char **path, const char *name);
-
+int lxc_cgroup_nrtasks(const char *name);
#endif