Class: OsCtl::ExportFS::CGroup
- Inherits:
-
Object
- Object
- OsCtl::ExportFS::CGroup
- Defined in:
- lib/osctl/exportfs/cgroup.rb
Constant Summary collapse
- FS =
'/sys/fs/cgroup'
Instance Attribute Summary collapse
- #controller ⇒ String readonly
- #path ⇒ String readonly
Instance Method Summary collapse
- #create(name) ⇒ Object
- #destroy(name) ⇒ Object
- #enter(name) ⇒ Object
-
#initialize(controller, 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(controller, path) ⇒ CGroup
Returns a new instance of CGroup.
15 16 17 18 |
# File 'lib/osctl/exportfs/cgroup.rb', line 15 def initialize(controller, path) @controller = controller @path = path end |
Instance Attribute Details
#controller ⇒ String (readonly)
8 9 10 |
# File 'lib/osctl/exportfs/cgroup.rb', line 8 def controller @controller end |
#path ⇒ String (readonly)
11 12 13 |
# File 'lib/osctl/exportfs/cgroup.rb', line 11 def path @path end |
Instance Method Details
#create(name) ⇒ Object
21 22 23 |
# File 'lib/osctl/exportfs/cgroup.rb', line 21 def create(name) FileUtils.mkdir_p(File.join(FS, controller, path, name)) end |
#destroy(name) ⇒ Object
26 27 28 |
# File 'lib/osctl/exportfs/cgroup.rb', line 26 def destroy(name) Dir.rmdir(File.join(FS, controller, path, name)) end |
#enter(name) ⇒ Object
31 32 33 34 35 |
# File 'lib/osctl/exportfs/cgroup.rb', line 31 def enter(name) File.open(proc_list(name), 'w') do |f| f.write(Process.pid) end end |
#kill_all(name) ⇒ Integer
Returns number of killed processes.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/osctl/exportfs/cgroup.rb', line 39 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 end end end killed end |
#kill_all_until_empty(name) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/osctl/exportfs/cgroup.rb', line 58 def kill_all_until_empty(name) loop do break if kill_all(name) == 0 sleep(3) end end |
#proc_list(name) ⇒ Object (protected)
66 67 68 |
# File 'lib/osctl/exportfs/cgroup.rb', line 66 def proc_list(name) File.join(FS, controller, path, name, 'cgroup.procs') end |