Class: Pazuzu::Cgroup

Inherits:
Object
  • Object
show all
Defined in:
lib/pazuzu/cgroup.rb

Defined Under Namespace

Classes: CgroupCreationFailed

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fs_root_path, path, subsystems) ⇒ Cgroup

Returns a new instance of Cgroup.



14
15
16
17
18
# File 'lib/pazuzu/cgroup.rb', line 14

def initialize(fs_root_path, path, subsystems)
  @fs_root_path = fs_root_path
  @path = path
  @subsystems = subsystems
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



41
42
43
# File 'lib/pazuzu/cgroup.rb', line 41

def path
  @path
end

Class Method Details

.available?Boolean

Are cgroups available?

Returns:

  • (Boolean)


9
10
11
# File 'lib/pazuzu/cgroup.rb', line 9

def available?
  File.exist?('/proc/cgroups')
end

Instance Method Details

#exec(command) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/pazuzu/cgroup.rb', line 28

def exec(command)
  unless system("cgcreate -g #{@subsystems.join(',')}:#{@path}")
    raise CgroupCreationFailed, "Could not create cgroup hiearchy #{@path}"
  end
  command = "cgexec -g #{@subsystems.join(',')}:#{@path} #{command}"
  return Process.exec(command)
end

#mounted?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/pazuzu/cgroup.rb', line 20

def mounted?
  return @subsystems.any? { |subsystem|
    Dir.glob(File.join(@fs_root_path, subsystem, @path, "cgroup.procs")).any? { |file_name|
      File.exists?(file_name)
    }
  }
end

#pidsObject



36
37
38
39
# File 'lib/pazuzu/cgroup.rb', line 36

def pids
  pids = pids_including_children
  pids.reject { |pid| pids.include?(parent_pid_for(pid)) }
end