Class: Mutx::Support::Processes
- Inherits:
-
Object
- Object
- Mutx::Support::Processes
- Defined in:
- lib/mutx/support/processes.rb
Class Method Summary collapse
- .fork_this(command) ⇒ Object
- .kill_all_these(pids = nil) ⇒ Object
- .kill_by_result_id(result_id) ⇒ Object
- .kill_dash_nine(pid) ⇒ Object
- .kill_p(pid) ⇒ Object
- .mutx_pids ⇒ Object
- .pid_for(result_id) ⇒ Object
-
.process_childs(pid) ⇒ Object
Recibe un PID y devuelve un array con los PID de sus hijos.
- .process_running?(pid) ⇒ Boolean
-
.sidekiq_pids ⇒ Array
Returns a list of sidekiq pids.
Class Method Details
.fork_this(command) ⇒ Object
101 102 103 |
# File 'lib/mutx/support/processes.rb', line 101 def self.fork_this command fork{exec("#{command}")} end |
.kill_all_these(pids = nil) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mutx/support/processes.rb', line 85 def self.kill_all_these pids=nil if pids until pids.empty? pid = pids.pop if process_running? pid begin kill_dash_nine(pid) rescue Errno::ESRCH puts "Could not find process id #{pid} to kill" end end end end end |
.kill_by_result_id(result_id) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mutx/support/processes.rb', line 6 def self.kill_by_result_id(result_id) pid = pid_for(result_id) return false if pid.nil? childs = process_childs(pid) unless pid.zero? begin childs.each{|ch_pid| kill_p(ch_pid)} unless childs.empty? kill_p(pid) true # Process killed rescue Errno::EPERM # Denied permission to kill process begin kill_dash_nine(pid) and true # Process killed rescue false end rescue Errno::ESRCH # Process did not exist false end else puts "Cannot find process id" end end |
.kill_dash_nine(pid) ⇒ Object
44 45 46 47 48 |
# File 'lib/mutx/support/processes.rb', line 44 def self.kill_dash_nine(pid) pid = pid.to_i if pid.respond_to? :to_i puts "kill -9 #{pid}" if $DEBUG Mutx::Support::Console.execute "kill -9 #{pid}" end |
.kill_p(pid) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mutx/support/processes.rb', line 33 def self.kill_p(pid) return false if pid.nil? pid = pid.to_i if pid.respond_to? :to_i begin Process.kill('INT', pid) and true rescue => e puts "#{e} [#{pid}]" false end end |
.mutx_pids ⇒ Object
72 73 74 75 |
# File 'lib/mutx/support/processes.rb', line 72 def self.mutx_pids res = Mutx::Support::Console.execute "ps -fea | grep 'unicorn.rb -p #{Mutx::Support::Configuration.port}'" res.split("\n").select{|lines| !lines.include? "grep"}.map{|line| line.split[1]} end |
.pid_for(result_id) ⇒ Object
50 51 52 53 |
# File 'lib/mutx/support/processes.rb', line 50 def self.pid_for(result_id) result = Mutx::Results::Result.get(result_id) result.pid.to_i end |
.process_childs(pid) ⇒ Object
Recibe un PID y devuelve un array con los PID de sus hijos
66 67 68 69 70 |
# File 'lib/mutx/support/processes.rb', line 66 def self.process_childs(pid) res = Mutx::Support::Console.execute("ps -fea | grep #{pid} | grep -v grep | awk '$2!=#{pid} && $8!~/awk/ && $3==#{pid}{print $2}'") File.open("#{__FILE__}#{__LINE__}","a+"){|f| f.write res} res end |
.process_running?(pid) ⇒ Boolean
55 56 57 58 59 60 61 62 |
# File 'lib/mutx/support/processes.rb', line 55 def self.process_running? pid unless pid.nil? res = Mutx::Support::Console.execute("ps -p #{pid}").split("\n").last unless res.nil? res.include? "#{pid}" and !res.include? "<defunct>" end end end |