diff --git a/Gemfile b/Gemfile index a65e487b3..b0db7bead 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,4 @@ source "http://rubygems.org" gem "cucumber" gem "rake" gem "osmlib-base" +gem "sys-proctable" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 042bc0e96..d4bff7b41 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,6 +14,7 @@ GEM json (1.6.5) osmlib-base (0.1.4) rake (0.9.2.2) + sys-proctable (0.9.1) term-ansicolor (1.0.7) PLATFORMS @@ -23,3 +24,4 @@ DEPENDENCIES cucumber osmlib-base rake + sys-proctable diff --git a/Rakefile b/Rakefile index bb0d960e1..0c5fb768a 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,7 @@ require 'OSM/StreamParser' require 'socket' require 'digest/sha1' require 'cucumber/rake/task' +require 'sys/proctable' SANDBOX = 'sandbox' 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 - process_list = `ps -o pid -o state -o ucomm` - process_list.scan /(\d+)\s+([^\s]*)\s+(#{name})/ do |pid,state| - yield pid.to_i, state.strip if ['I','R','S','T'].include? state[0] -end + Sys::ProcTable.ps do |process| + if process.comm.strip == name.strip + yield process.pid.to_i, process.state.strip + end + end end def up? diff --git a/features/support/launch.rb b/features/support/launch.rb index ba0e092ca..d125985ac 100644 --- a/features/support/launch.rb +++ b/features/support/launch.rb @@ -1,4 +1,5 @@ require 'socket' +require 'sys/proctable' class OSRMLauncher def initialize &block @@ -11,10 +12,11 @@ class OSRMLauncher end def each_process name, &block - process_list = `ps -o pid -o state -o ucomm` - process_list.scan /(\d+)\s+([^\s]*)\s+(#{name})/ do |pid,state| - yield pid.to_i, state.strip if ['I','R','S','T'].include? state[0] -end + Sys::ProcTable.ps do |process| + if process.comm.strip == name.strip + yield process.pid.to_i, process.state.strip + end + end end def osrm_up?