红宝石超时和系统命令

我有一个ruby超时,调用一个系统(bash)命令像这样..

Timeout::timeout(10) {
  `my_bash_command -c12 -o text.txt`
}

但是我认为即使ruby线程中断,实际的命令仍然在后台运行。是正常的吗?我该怎么杀?

我想你必须手动杀死它:

require 'timeout'

puts 'starting process'
pid = Process.spawn('sleep 20')
begin
  Timeout.timeout(5) do
    puts 'waiting for the process to end'
    Process.wait(pid)
    puts 'process finished in time'
  end
rescue Timeout::Error
  puts 'process not finished in time, killing it'
  Process.kill('TERM', pid)
end
http://stackoverflow.com/questions/8292031/ruby-timeouts-and-system-commands

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:红宝石超时和系统命令