Class: Sys::ProcTable::CgroupEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/linux/sys/proctable/cgroup_entry.rb

Overview

This represents a cgroup entry

Have a look at ‘man 5 proc` on a linux distribution, to get some more information about the lines and their fields in `/proc//cgroup`.

Example:

entry = CgroupEntry.new '7:devices:/init.scope'
entry.hierarchy_id  # => 7
entry.subsystems    # => ['devices']
entry.control_group # => '/init.scope'

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ CgroupEntry

Create a new cgroup entry object

This expects a string of ‘7:devices:/init.scope’ - see ‘man 5 proc` for a reference.



22
23
24
25
26
27
# File 'lib/linux/sys/proctable/cgroup_entry.rb', line 22

def initialize(string)
  @string = string.chomp
  @fields = @string.split(/:/)
rescue StandardError
  @fields = []
end

Instance Method Details

#control_groupObject

control group in the hierarchy to which the process belongs



42
43
44
# File 'lib/linux/sys/proctable/cgroup_entry.rb', line 42

def control_group
  @fields[2]
end

#hierarchy_idObject

This returns the hierarchy id of the cgroup entry



30
31
32
# File 'lib/linux/sys/proctable/cgroup_entry.rb', line 30

def hierarchy_id
  @fields[0].to_i
end

#subsystemsObject

Return sets of subsystems bound to the hierarchy



35
36
37
38
39
# File 'lib/linux/sys/proctable/cgroup_entry.rb', line 35

def subsystems
  @fields[1].split(/,/)
rescue StandardError
  []
end

#to_sObject

Return the line itself



47
48
49
# File 'lib/linux/sys/proctable/cgroup_entry.rb', line 47

def to_s
  @string
end