How to check for a running process with Ruby?

TomDogg picture TomDogg · Jan 4, 2011 · Viewed 14.4k times · Source

I use a scheduler (Rufus scheduler) to launch a process called "ar_sendmail" (from ARmailer), every minute.

The process should NOT be launched when there is already such a process running in order not to eat up memory.

How do I check to see if this process is already running? What goes after the unless below?

scheduler = Rufus::Scheduler.start_new

  scheduler.every '1m' do

    unless #[what goes here?]
      fork { exec "ar_sendmail -o" }
      Process.wait
    end

  end

end

Answer

stef picture stef · Jan 4, 2011
unless `ps aux | grep ar_sendmai[l]` != ""