如何使用Ruby检查正在运行的进程?

时间:2011-01-04 13:21:37

标签: ruby-on-rails process rufus-scheduler

我使用调度程序(Rufus调度程序)每分钟启动一个名为“ar_sendmail”的进程(来自ARmailer)。

当已经存在这样的进程以便不占用内存时,不应启动该进程。

如何查看此进程是否已在运行?在unless之后发生了什么?

scheduler = Rufus::Scheduler.start_new

  scheduler.every '1m' do

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

  end

end

3 个答案:

答案 0 :(得分:23)

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

答案 1 :(得分:8)

unless `pgrep -f ar_sendmail`.split("\n") != [Process.pid.to_s]

答案 2 :(得分:0)

我认为这看起来更整洁,并使用内置的Ruby模块。发送0个终止信号(即不要终止):

enter code here

in 'sql' i can :
select a,b,c from X.tb
except
select a,b,c from Y.tb
how can i make it work by pandas and python? or use some functions of 
python?
i have already use pandas like 'isin' :


'df1': select a,b,c from X.tb
'df2': select a,b,c from Y.tb
df1[df1.isin(df2)==False]

Quick dev tips中稍作修改,您可能不想营救EPERM,意思是“它正在运行,但您不允许杀死它”。