ruby超时和系统命令

我有一个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
翻译自:https://stackoverflow.com/questions/8292031/ruby-timeouts-and-system-commands

转载注明原文:ruby超时和系统命令