Class: Flatware::Pid

Inherits:
Struct
  • Object
show all
Defined in:
lib/flatware/pid.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commandObject

Returns the value of attribute command

Returns:

  • (Object)

    the current value of command



17
18
19
# File 'lib/flatware/pid.rb', line 17

def command
  @command
end

#pgidObject

Returns the value of attribute pgid

Returns:

  • (Object)

    the current value of pgid



17
18
19
# File 'lib/flatware/pid.rb', line 17

def pgid
  @pgid
end

#pidObject

Returns the value of attribute pid

Returns:

  • (Object)

    the current value of pid



17
18
19
# File 'lib/flatware/pid.rb', line 17

def pid
  @pid
end

#ppidObject

Returns the value of attribute ppid

Returns:

  • (Object)

    the current value of ppid



17
18
19
# File 'lib/flatware/pid.rb', line 17

def ppid
  @ppid
end

Class Method Details

.pids(&block) ⇒ Object



18
19
20
# File 'lib/flatware/pid.rb', line 18

def self.pids(&block)
  ps.select(&block).map(&:pid)
end

.psObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/flatware/pid.rb', line 22

def self.ps
  args = ['-o', members.join(',')]
  args += { 'Darwin' => %w[-c] }.fetch(Etc.uname.fetch(:sysname), [])

  IO
    .popen(['ps', *args])
    .readlines
    .map do |row|
    fields = row.strip.split(/\s+/, 4)
    new(*fields.take(3).map(&:to_i), fields.last)
  end
end

Instance Method Details

#pids_of_group(group_pid) ⇒ Object



35
36
37
38
39
# File 'lib/flatware/pid.rb', line 35

def pids_of_group(group_pid)
  ps
    .select { |pid| pid.pgid == group_pid }
    .map(&:pid)
end