Search code examples
ruby-on-railsprocessrufus-scheduler

How to check for a running process with Ruby?


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

Solution

  • unless `ps aux | grep ar_sendmai[l]` != ""