如何使用 Ruby 检查正在运行的进程?
我使用调度程序(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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这看起来更简洁,并且使用内置的 Ruby 模块。发送 0 杀死信号(即不杀死):
稍作修改自 快速开发提示 您可能不想拯救 EPERM,意思是“它正在运行,但不允许您杀死它”。
This looks neater I think, and uses built-in Ruby module. Send a 0 kill signal (i.e. don't kill):
Slightly amended from Quick dev tips You might not want to rescue EPERM, meaning "it's running, but you're not allowed to kill it".