Report abuse

#!/usr/bin/ruby

require 'facter'

pattern = "/usr/bin/ruby"

ps = Facter["ps"].value

regex = Regexp.new(pattern)
ary = []

IO.popen(ps) { |table|
        table.each { |line|
                if regex.match(line)
                    ary = line.sub(/^\s+/, '').split(/\s+/)
                end
        }
}

ary[1] != nil ? puts("Pid is: #{ary[1]}") : puts("Could not find the pid")