Class: OsCtl::ExportFS::CGroup
- Inherits:
-
Object
- Object
- OsCtl::ExportFS::CGroup
- Defined in:
- lib/osctl/exportfs/cgroup.rb
Constant Summary collapse
- FS =
'/sys/fs/cgroup'.freeze
Instance Attribute Summary collapse
- #path ⇒ String readonly
Instance Method Summary collapse
- #abs_cgroup_path(*names) ⇒ Object protected
- #create(name) ⇒ Object
- #destroy(name) ⇒ Object
- #enter(name) ⇒ Object
-
#initialize(path) ⇒ CGroup
constructor
A new instance of CGroup.
-
#kill_all(name) ⇒ Integer
Number of killed processes.
- #kill_all_until_empty(name) ⇒ Object
- #proc_list(name) ⇒ Object protected
Constructor Details
#initialize(path) ⇒ CGroup
Returns a new instance of CGroup.
12 13 14 |
# File 'lib/osctl/exportfs/cgroup.rb', line 12 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ String (readonly)
9 10 11 |
# File 'lib/osctl/exportfs/cgroup.rb', line 9 def path @path end |
Instance Method Details
#abs_cgroup_path(*names) ⇒ Object (protected)
67 68 69 70 71 72 73 |
# File 'lib/osctl/exportfs/cgroup.rb', line 67 def abs_cgroup_path(*names) args = [FS] args << 'systemd' unless OsCtl::Lib::CGroup.v2? args << path args.concat(names) File.join(*args) end |
#create(name) ⇒ Object
17 18 19 |
# File 'lib/osctl/exportfs/cgroup.rb', line 17 def create(name) FileUtils.mkdir_p(abs_cgroup_path(name)) end |
#destroy(name) ⇒ Object
22 23 24 |
# File 'lib/osctl/exportfs/cgroup.rb', line 22 def destroy(name) Dir.rmdir(abs_cgroup_path(name)) end |
#enter(name) ⇒ Object
27 28 29 |
# File 'lib/osctl/exportfs/cgroup.rb', line 27 def enter(name) File.write(proc_list(name), Process.pid) end |
#kill_all(name) ⇒ Integer
Returns number of killed processes.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/osctl/exportfs/cgroup.rb', line 33 def kill_all(name) killed = 0 File.open(proc_list(name)) do |f| f.each_line do |line| pid = line.strip.to_i begin killed += 1 Process.kill('TERM', pid) rescue Errno::ESRCH # ignore end end end killed end |
#kill_all_until_empty(name) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/osctl/exportfs/cgroup.rb', line 53 def kill_all_until_empty(name) loop do break if kill_all(name) == 0 sleep(3) end end |
#proc_list(name) ⇒ Object (protected)
63 64 65 |
# File 'lib/osctl/exportfs/cgroup.rb', line 63 def proc_list(name) abs_cgroup_path(name, 'cgroup.procs') end |