Class: PSTree::ProcStruct

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

Overview

Process structure for storing and formatting process information.

This class encapsulates the essential details of a process including its parent process ID, process ID, owning user, and command line.

Examples:

Creating a new process structure

proc = PSTree::ProcStruct.new(1234, 5678, 'flori', '/usr/bin/ruby script.rb')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ppid, pid, user, cmd) ⇒ ProcStruct

Initializes a new process structure with the given process information.

Parameters:

  • ppid (String, Integer)

    the parent process ID

  • pid (String, Integer)

    the process ID

  • user (String)

    the user who owns the process

  • cmd (String)

    the command line of the process



36
37
38
# File 'lib/pstree.rb', line 36

def initialize(ppid, pid, user, cmd)
  @ppid, @pid, @user, @cmd = ppid.to_i, pid.to_i, user, cmd
end

Instance Attribute Details

#cmdObject (readonly)

The cmd reader method returns the command line of this process structure.



59
60
61
# File 'lib/pstree.rb', line 59

def cmd
  @cmd
end

#pidObject (readonly)

The pid reader method returns the process ID of this process structure.



49
50
51
# File 'lib/pstree.rb', line 49

def pid
  @pid
end

#ppidObject (readonly)

The ppid reader method returns the parent process ID of this process structure.



44
45
46
# File 'lib/pstree.rb', line 44

def ppid
  @ppid
end

#userObject (readonly)

The user reader method returns the username who owns this process



54
55
56
# File 'lib/pstree.rb', line 54

def user
  @user
end

Instance Method Details

#to_sString

The to_s method formats the process information into a string representation that displays the process ID, command, and user in a standardized format.

Returns:

  • (String)

    a formatted string containing the process ID, command, and user separated by spaces and parentheses



66
67
68
# File 'lib/pstree.rb', line 66

def to_s
 "%05u %s (%s)" % [ pid, cmd, user ]
end