我正试着从红宝石开始一个牢骚的任务。此任务将永远运行,因为它启动了服务器。
稍后,在红宝石脚本中,我想关闭我用咕噜声启动的服务器。
我现在有以下几点:
grunt_proxy_pid = spawn("TARGET_PORT=#{port+1} PROXY_PORT=#{port} grunt server:test", :out=>"/dev/null")
Process.detach grunt_proxy_pid
... ruby code ...
Process.kill "SIGINT", grunt_proxy_pid
但是,这并不会终止grunt任务,只有执行grunt server:test
命令的shell命令(在任务管理器中,带有pid 'grunt_proxy_pid‘的任务类似于sh -c TARGET_PORT=3523 PROXY_PORT=3224 grunt server:test
--尽管grunt进程本身有另一个pid。
我怎样才能得到任务pid,这样我就可以终止这个任务?
发布于 2014-05-29 09:24:13
事实证明,以这种方式设置环境变量才是问题所在。以这种方式设置它们是可行的:
grunt_proxy_pid = spawn({
"TARGET_PORT" => "#{port+1}",
"PROXY_PORT" => "#{port}"
}, "grunt server:test", :out=>"/dev/null")
Process.detach grunt_proxy_pid
这样,grunt命令不是用sh -c
启动的,而grunt_proxy_pid
是grunt进程本身的pid。
https://stackoverflow.com/questions/23721111
复制相似问题