Class: ProcessMonitor
- Inherits:
-
Object
- Object
- ProcessMonitor
- Defined in:
- lib/process_monitor.rb
Class Method Summary collapse
- .get_process_status(process_type, process_pattern) ⇒ Object
- .process_is_up?(process_type, process_pattern) ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.get_process_status(process_type, process_pattern) ⇒ Object
22 23 24 25 |
# File 'lib/process_monitor.rb', line 22 def self.get_process_status(process_type,process_pattern) pid = get_pid(process_type,process_pattern) `cat /proc/#{pid}/status|grep State` end |
.process_is_up?(process_type, process_pattern) ⇒ Boolean
28 29 30 31 32 33 34 |
# File 'lib/process_monitor.rb', line 28 def self.process_is_up?(process_type,process_pattern) pid = get_pid(process_type,process_pattern) # The folder /proc/<pid>/ contains information about the process # The file /proc/<pid>/status gives information about the process as to if it is sleeping and so on. # If the folder exists it would mean the process exists. (pid.nil? || !File.exists?("/proc/#{pid}"))? false : true end |
Instance Method Details
#get_pid(process_type, process_pattern) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/process_monitor.rb', line 3 def get_pid(process_type,process_pattern) # Parse the output to fetch the process id. process_id_reg_exp = %r{^(.*)\s*} process_information_lines = `pgrep #{process_type}|xargs ps`.split("\n") pid = nil process_information_lines.each do |process_line| # The name of the process will be verity-spider # This is to make sure we don't kill any other ruby process other than spider. if process_line =~ /#{process_pattern}/ process_id_reg_exp.match(process_line) pid = $1.gsub(/\s*/, "").to_i end end pid end |