Class: GetRunningProcesses::Processes
- Inherits:
-
Object
- Object
- GetRunningProcesses::Processes
- Defined in:
- lib/get_running_processes/processes.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#commands_with_pids ⇒ Object
readonly
Returns the value of attribute commands_with_pids.
-
#pids_with_commands ⇒ Object
readonly
Returns the value of attribute pids_with_commands.
Instance Method Summary collapse
- #get_all ⇒ Object
- #get_commands ⇒ Object
- #get_commands_with_pids ⇒ Object
- #get_process_array ⇒ Object
-
#initialize ⇒ Processes
constructor
A new instance of Processes.
Constructor Details
#initialize ⇒ Processes
Returns a new instance of Processes.
8 9 10 11 12 |
# File 'lib/get_running_processes/processes.rb', line 8 def initialize @all = self.get_all @commands = self.get_commands @commands_with_pids = self.get_commands_with_pids end |
Instance Attribute Details
#all ⇒ Object (readonly)
Returns the value of attribute all.
3 4 5 |
# File 'lib/get_running_processes/processes.rb', line 3 def all @all end |
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
3 4 5 |
# File 'lib/get_running_processes/processes.rb', line 3 def commands @commands end |
#commands_with_pids ⇒ Object (readonly)
Returns the value of attribute commands_with_pids.
3 4 5 |
# File 'lib/get_running_processes/processes.rb', line 3 def commands_with_pids @commands_with_pids end |
#pids_with_commands ⇒ Object (readonly)
Returns the value of attribute pids_with_commands.
3 4 5 |
# File 'lib/get_running_processes/processes.rb', line 3 def pids_with_commands @pids_with_commands end |
Instance Method Details
#get_all ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/get_running_processes/processes.rb', line 14 def get_all processes = self.get_process_array all = [] processes.each do |process| command = {} command["UID"] = process[0] command["PID"] = process[1].to_i command["PPID"] = process[2].to_i command["C"] = process[3] command["STIME"] = process[4] command["TTY"] = process[5] command["TIME"] = process[6] command["CMD"] = process[7] all << command end return all end |
#get_commands ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/get_running_processes/processes.rb', line 36 def get_commands processes = self.get_process_array commands = [] processes.each do |process| commands << process[7] end return commands end |
#get_commands_with_pids ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/get_running_processes/processes.rb', line 47 def get_commands_with_pids processes = self.get_process_array commands_with_pids = [] processes.each do |process| command = {} command[process[7]] = process[1].to_i commands_with_pids << command end return commands_with_pids end |
#get_process_array ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/get_running_processes/processes.rb', line 75 def get_process_array output = `ps -ef` processes = [] lines = [] output.lines.each do |line| process = line.split(' ') lines << process end lines.each do |line| if line[0] == "UID" else result = line.slice!(7, 30).join(' ').strip line << result processes << line end end return processes end |