2
我在Ruby中启动后台进程时遇到了一些困难。如何在Ruby中启动后台进程?
我现在有这段代码。
#!/usr/bin/env ruby -w
require "daemons"
require 'rubygems'
path = "#{File.expand_path(File.dirname(__FILE__))}/.."
Daemons.run_proc('stalker',{
:dir_mode => :normal,
:dir => "#{path}/tmp/pids",
:backtrace => true,
:monitor => false,
:log_output => true
}) do
system "stalk #{path}/config/jobs.rb"
end
我然后使用script/stalker start
启动脚本。
问题是我无法阻止它。它将错误的PID保存到pid文件中。
像这样:
script/stalker start
=> stalker: process with pid **39756** started.
ps aux | grep ruby
=> linus **39781** 0,3 1,9 2522752 78864 ?? S 8:39pm 0:10.11 ruby stalk script/../config/jobs.rb
为什么不第一PID比赛的一个印刷用ps aux | grep ruby
?
我试过使用exec
,%x{}
和这一个system
来运行脚本。