我使用一个调度器(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发布于 2011-01-04 21:28:25
unless `ps aux | grep ar_sendmai[l]` != ""发布于 2015-04-08 16:48:31
unless `pgrep -f ar_sendmail`.split("\n") != [Process.pid.to_s]发布于 2019-08-28 16:09:42
我认为这看起来更整洁,并且使用了内置的Ruby模块。发送0终止信号(即不终止):
# Check if a process is running
def running?(pid)
Process.kill(0, pid)
true
rescue Errno::ESRCH
false
rescue Errno::EPERM
true
end对Quick dev tips稍作修改,你可能不想拯救EPERM,意思是“它正在运行,但你不允许杀死它”。
https://stackoverflow.com/questions/4594043
复制相似问题