Return a set of tasks (schedulable entities) for the cgroup. If control == "cgroup.procs" these are processes else if control == "tasks" they are all tasks, roughly equivalent to threads.
| 888 | // If control == "cgroup.procs" these are processes else |
| 889 | // if control == "tasks" they are all tasks, roughly equivalent to threads. |
| 890 | Try<set<pid_t>> tasks( |
| 891 | const string& hierarchy, |
| 892 | const string& cgroup, |
| 893 | const string& control) |
| 894 | { |
| 895 | // Note: (from cgroups/cgroups.txt documentation) |
| 896 | // cgroup.procs: list of thread group IDs in the cgroup. This list is not |
| 897 | // guaranteed to be sorted or free of duplicate TGIDs, and userspace should |
| 898 | // sort/uniquify the list if this property is required. |
| 899 | Try<string> value = cgroups::read(hierarchy, cgroup, control); |
| 900 | if (value.isError()) { |
| 901 | return Error("Failed to read cgroups control '" + |
| 902 | control + "': " + value.error()); |
| 903 | } |
| 904 | |
| 905 | // Parse the values read from the control file and insert into a set. This |
| 906 | // ensures they are unique (and also sorted). |
| 907 | set<pid_t> pids; |
| 908 | istringstream ss(value.get()); |
| 909 | ss >> dec; |
| 910 | while (!ss.eof()) { |
| 911 | pid_t pid; |
| 912 | ss >> pid; |
| 913 | |
| 914 | if (ss.fail()) { |
| 915 | if (!ss.eof()) { |
| 916 | return Error("Failed to parse '" + value.get() + "'"); |
| 917 | } |
| 918 | } else { |
| 919 | pids.insert(pid); |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | return pids; |
| 924 | } |
| 925 | |
| 926 | } // namespace internal { |
| 927 |