use ruby to fetch process list

This commit is contained in:
Emil Tin 2012-02-14 16:09:11 +01:00
parent e2a3fb5c61
commit a8e9b148eb
4 changed files with 15 additions and 8 deletions

View File

@ -3,3 +3,4 @@ source "http://rubygems.org"
gem "cucumber" gem "cucumber"
gem "rake" gem "rake"
gem "osmlib-base" gem "osmlib-base"
gem "sys-proctable"

View File

@ -14,6 +14,7 @@ GEM
json (1.6.5) json (1.6.5)
osmlib-base (0.1.4) osmlib-base (0.1.4)
rake (0.9.2.2) rake (0.9.2.2)
sys-proctable (0.9.1)
term-ansicolor (1.0.7) term-ansicolor (1.0.7)
PLATFORMS PLATFORMS
@ -23,3 +24,4 @@ DEPENDENCIES
cucumber cucumber
osmlib-base osmlib-base
rake rake
sys-proctable

View File

@ -2,6 +2,7 @@ require 'OSM/StreamParser'
require 'socket' require 'socket'
require 'digest/sha1' require 'digest/sha1'
require 'cucumber/rake/task' require 'cucumber/rake/task'
require 'sys/proctable'
SANDBOX = 'sandbox' SANDBOX = 'sandbox'
DATA_FOLDER = 'osm_data' DATA_FOLDER = 'osm_data'
@ -30,10 +31,11 @@ task osm_data_area_name.to_sym {} #define empty task to prevent rake from whin
def each_process name, &block def each_process name, &block
process_list = `ps -o pid -o state -o ucomm` Sys::ProcTable.ps do |process|
process_list.scan /(\d+)\s+([^\s]*)\s+(#{name})/ do |pid,state| if process.comm.strip == name.strip
yield pid.to_i, state.strip if ['I','R','S','T'].include? state[0] yield process.pid.to_i, process.state.strip
end end
end
end end
def up? def up?

View File

@ -1,4 +1,5 @@
require 'socket' require 'socket'
require 'sys/proctable'
class OSRMLauncher class OSRMLauncher
def initialize &block def initialize &block
@ -11,10 +12,11 @@ class OSRMLauncher
end end
def each_process name, &block def each_process name, &block
process_list = `ps -o pid -o state -o ucomm` Sys::ProcTable.ps do |process|
process_list.scan /(\d+)\s+([^\s]*)\s+(#{name})/ do |pid,state| if process.comm.strip == name.strip
yield pid.to_i, state.strip if ['I','R','S','T'].include? state[0] yield process.pid.to_i, process.state.strip
end end
end
end end
def osrm_up? def osrm_up?