I have a ruby timeout that calls a system (bash) command like this..
Timeout::timeout(10) {
`my_bash_command -c12 -o text.txt`
}
but I think that even if the ruby thread is interrupted, the actual command keeps running in the background.. is it normal? How can I kill it?
I think you have to
kill
it manually:Perhaps this will help someone else looking to achieve similar timeout functionality, but needs to collect the output from the shell command.
I've adapted @shurikk's method to work with Ruby 2.0 and some code from Fork child process with timeout and capture output to collect the output.
Handling processes, signals and timers is not very easy. That's why you might consider delegating this task: Use the command
timeout
on new versions of Linux:in order to properly stop spawned process tree (not just the parent process) one should consider something like this:
this also allows you to track process status