module Process
class << self
def process_alive?(pid)
begin
Process.kill(0, pid)
true
rescue Errno::ESRCH
false
end
end
end
end
module Process
class << self
def process_alive?(pid)
Dir['/proc/[0-9]*'].map { |i| i.match(/\d+/)[0].to_i }.include?(pid)
end
end
end
irb(main):013:0> puts `ps aux | grep -i [t]omboy`
1000 26862 0.0 0.2 103972 9592 ? Sl Sep28 0:09 mono /usr/lib/tomboy/Tomboy.exe
=> nil
irb(main):014:0> Process.process_alive?(26862)
=> true
irb(main):015:0> Process.process_alive?(12345)
=> false
irb(main):016:0>
Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/sjuGmBNkEx0/12347