Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cgroup.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License version 2.1 as published by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17 
24 #ifndef LXCPP_CGROUPS_CGROUP_HPP
25 #define LXCPP_CGROUPS_CGROUP_HPP
26 
28 
29 namespace lxcpp {
30 
31 class CGroup {
32 
33 public:
38  CGroup(const std::string& subsys, const std::string& name) :
39  mSubsys(subsys),
40  mName(name)
41  {
42  }
43 
47  CGroup(const std::string& subsysAndCgroup);
48 
53  bool exists() const;
54 
59  void create();
60 
66  void destroy();
67 
72  void setCommonValue(const std::string& param, const std::string& value);
73 
78  std::string getCommonValue(const std::string& param) const;
79 
84  void setValue(const std::string& param, const std::string& value);
85 
90  std::string getValue(const std::string& param) const;
91 
96  void assignGroup(pid_t pid);
97 
102  void assignPid(pid_t pid);
103 
108  std::vector<pid_t> getPids() const;
109 
113  static CGroup getCGroup(const std::string& subsys, pid_t pid);
114 
115 private:
116  const Subsystem mSubsys; // referred subsystem
117  const std::string mName; // path relative to subsystem "root"
118 };
119 
120 } //namespace lxcpp
121 
122 #endif // LXCPP_CGROUPS_CGROUP_HPP
std::string getCommonValue(const std::string &param) const
Get common 'cgroup' paramter.
Definition: cgroup.cpp:99
const std::string mName
Definition: cgroup.hpp:117
void create()
Create cgroup directory.
Definition: cgroup.cpp:75
Definition: cgroup.hpp:31
void assignGroup(pid_t pid)
Assign all processes in threadgroup of pid to this cgroup.
Definition: cgroup.cpp:136
Definition: subsystem.hpp:34
Control-groups management.
bool exists() const
Check if cgroup exists.
Definition: cgroup.cpp:68
std::string getValue(const std::string &param) const
Get cgroup parameter.
Definition: cgroup.cpp:123
void destroy()
Destroy cgroup directory Equivalent of: rmdir subsys.path / mName Note: set memory.force_empty before removing a cgroup to avoid moving out-of-use page caches to parent.
Definition: cgroup.cpp:81
static CGroup getCGroup(const std::string &subsys, pid_t pid)
Get cgroup of process pid in given subsystem.
Definition: cgroup.cpp:168
CGroup(const std::string &subsys, const std::string &name)
Define control-group object.
Definition: cgroup.hpp:38
void setValue(const std::string &param, const std::string &value)
Set cgroup parameter to value (name validity depends on subsystem).
Definition: cgroup.cpp:112
void setCommonValue(const std::string &param, const std::string &value)
Set common 'cgroup' parameter.
Definition: cgroup.cpp:88
const Subsystem mSubsys
Definition: cgroup.hpp:116
void assignPid(pid_t pid)
Assign single process to this cgroup (will be removed from previous cgroup automatically).
Definition: cgroup.cpp:141
std::vector< pid_t > getPids() const
Get list of pid assigned to this group.
Definition: cgroup.cpp:147