Ruby Process.spawn子项不接收术语

Ruby Process.spawn子项不接收术语,ruby,bash,shell,process,Ruby,Bash,Shell,Process,我试图以编程方式生成一个Puma进程,然后通过发送它来杀死它 为此,我使用了返回pid的Process.spawn。此PID不是puma进程的PID,而是生成puma的shell命令的PID pid = Process.spawn "bundle exec puma test/fixtures/app.ru -w 3 -t 1:1 -p 0 -e development > test/logs/puma_1961_1393875906.917352.log" => 10711 现在

我试图以编程方式生成一个Puma进程,然后通过发送它来杀死它

为此,我使用了返回pid的
Process.spawn
。此PID不是puma进程的PID,而是生成puma的shell命令的PID

pid = Process.spawn "bundle exec puma test/fixtures/app.ru -w 3 -t 1:1 -p 0 -e development > test/logs/puma_1961_1393875906.917352.log"
=> 10711
现在我可以运行
ps aux | grep puma
,我可以看到它正在运行

schneems        10719   0.0  0.1  2488912   7564 s000  S+    1:57PM   0:00.02 puma: cluster worker: 10712
schneems        10718   0.0  0.1  2488912   7524 s000  S+    1:57PM   0:00.02 puma: cluster worker: 10712
schneems        10717   0.0  0.1  2489936   7652 s000  S+    1:57PM   0:00.02 puma: cluster worker: 10712
schneems        10712   0.0  0.3  2478612  24596 s000  S+    1:57PM   0:00.47 ruby /Users/schneems/.gem/ruby/2.1.1/bin/puma test/fixtures/app.ru -w 3 -t 1:1 -p 0 -e development
但是您会注意到,正如我之前提到的,返回的PID
10711
未列出。这实际上是一个(sh)过程

现在回到红宝石地。当我试图通过
Process.kill('TERM',pid)
终止puma时,shell进程被终止,但puma继续在后台运行。彪马从未收到过
SIGTERM

puts pid
10711
Process.kill("TERM", pid)
=> 1
Process.wait(pid)
有没有其他方法可以从Ruby内部持续繁殖和杀死美洲狮?任何关于繁殖进程没有向其子进程(puma)发送信号的线索。这是我的操作系统、Ruby还是Puma中的一个bug?也许这是预期的行为


这是我的
app.ru

最快的黑客攻击是使用
exec

# Bad quick fix
pid = Process.spawn "exec bundle exec puma test/fixtures/app.ru -w 3 -t 1:1 -p 0 -e development > test/logs/puma_1961_1393875906.917352.log"
这将用调用的进程替换shell

但是,决不能将Process.spawn与shell命令一起使用。当与变量结合时,它会导致令人惊讶、不安全和不可预测的行为。相反,您应该分离参数并自行设置重定向:

# Good solution
pid = Process.spawn("bundle", "exec", "puma", "test/fixtures/app.ru", "-w", "3", "-t", "1:1", "-p", "0", "-e", "development", :out=>"test/logs/puma_1961_1393875906.917352.log")

这首先避免了shell。

看起来技巧是在我的命令'Process'之前添加“exec”。spawn(“exec”)也不使用
重定向stdout做同样的事情
# Good solution
pid = Process.spawn("bundle", "exec", "puma", "test/fixtures/app.ru", "-w", "3", "-t", "1:1", "-p", "0", "-e", "development", :out=>"test/logs/puma_1961_1393875906.917352.log")