Showing posts with label Process. Show all posts
Showing posts with label Process. Show all posts

Monday, May 23, 2011

Ruote


Ruote is a workflow engine written in Ruby. Ruote is not a state machine library.
It could be described as an ‘operating system for business processes’.
A ruote engine may execute multiple process instances at a time. Processes are instantiated from process definitions written in a Ruby DSL or in XML (or directly as JSON). Process definitions describe the flow of work among participants. Participants stand for users, groups of users, services, legacy systems, etc.

Monday, October 4, 2010

Check whether a process is alive

Check whether a process is running (actually, present and alive) on a particular machine and/or system using its PID ...

Quick version ...

module Process
  class << self
    def process_alive?(pid)
      begin
        Process.kill(0, pid)
        true
      rescue Errno::ESRCH
        false
      end
    end
  end
end


A little bit slower version using /proc file system lookup ...

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


Simple use-case:

irb(main):013:0> puts `ps aux | grep -i [t]omboy`
1000 6862  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> 

http://snippets.dzone.com/posts/show/12347