我使用调度器(Rufus scheduler)每分钟启动一个名为“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
ps aux | grep ar_sendmai[l] | awk '{ print $2 }'
- phatmann!=
中使用unless
,因为它会导致精神痛苦。相反,请使用if
和==
:if something == something_else
比unless something != something_else
更容易理解。 - the Tin Manpidof ar_sendmail
。 - Mike Lowery