MCPcopy Create free account
hub / github.com/apache/mesos / cgroup

Function cgroup

src/linux/cgroups.cpp:1785–1821  ·  view source on GitHub ↗

Helper for finding the cgroup of the specified pid for the specified subsystem.

Source from the content-addressed store, hash-verified

1783// Helper for finding the cgroup of the specified pid for the
1784// specified subsystem.
1785Result<string> cgroup(pid_t pid, const string& subsystem)
1786{
1787 // Determine cgroup for hierarchy with the subsystem attached.
1788 string path = path::join("/proc", stringify(pid), "cgroup");
1789
1790 Try<string> read = os::read(path);
1791
1792 if (read.isError()) {
1793 return Error("Failed to read " + path + ": " + read.error());
1794 }
1795
1796 // Now determine the cgroup by parsing each line of the output which
1797 // should be of the form "N:subsystems:cgroup" where 'N' is the
1798 // hierarchy number and 'subsystems' are the attached subsystems and
1799 // 'cgroup' is the relative path to the cgroup from the hierarchy
1800 // path.
1801 Option<string> cgroup = None();
1802
1803 foreach (const string& line, strings::tokenize(read.get(), "\n")) {
1804 vector<string> tokens = strings::tokenize(line, ":");
1805
1806 // The second field is empty for cgroups v2 hierarchy.
1807 if (tokens.size() == 2) {
1808 continue;
1809 } else if (tokens.size() != 3) {
1810 return Error("Unexpected format in " + path);
1811 }
1812
1813 foreach (const string& token, strings::tokenize(tokens[1], ",")) {
1814 if (subsystem == token) {
1815 cgroup = tokens[2];
1816 }
1817 }
1818 }
1819
1820 return cgroup;
1821}
1822
1823} // namespace internal {
1824

Callers 5

TEST_FFunction · 0.85
TEST_FFunction · 0.85
_updateMethod · 0.85
cgroupsStatisticsMethod · 0.85
foreachvalueFunction · 0.85

Calls 9

NoneClass · 0.85
tokenizeFunction · 0.85
stringifyFunction · 0.70
readFunction · 0.70
errorMethod · 0.65
joinFunction · 0.50
ErrorFunction · 0.50
isErrorMethod · 0.45
sizeMethod · 0.45

Tested by 2

TEST_FFunction · 0.68
TEST_FFunction · 0.68