This patch adds a function to count the number of tasks in the
container.
Signed-off-by: Daniel Lezcano <[email protected]>
---
src/lxc/cgroup.c | 27 +++++++++++++++++++++++++++
src/lxc/cgroup.h | 2 +-
2 files changed, 28 insertions(+), 1 deletion(-)
Index: lxc/src/lxc/cgroup.c
===================================================================
--- lxc.orig/src/lxc/cgroup.c
+++ lxc/src/lxc/cgroup.c
@@ -219,3 +219,30 @@ int lxc_cgroup_get(const char *name, con
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;
+}
Index: lxc/src/lxc/cgroup.h
===================================================================
--- lxc.orig/src/lxc/cgroup.h
+++ lxc/src/lxc/cgroup.h
@@ -29,5 +29,5 @@ struct lxc_handler;
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
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Lxc-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lxc-devel