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
來運行腳本。