Kill a process using its PID in ruby

kill-process, pid, process, ruby, windows

Solution

For your timing, you can use a thread:

Thread.new do
  sleep 10 * 60
  begin
    Process.kill('QUIT', pid)
  rescue Errno::ESRCH
    # process exited normally
  end
end

_, status = Process.wait2 pid
puts status.exited?

I am unsure of why QUIT is not working for you. I could not replicate your error.

Problem

I'm trying to kill a process using its PID after a given period of time, i.e, if the process keeps running for more than 10 minutes, I have to call a method to kill it. I have two problems: first, i can't manage to kill the process, i'm using: ``` Process.kill('INT', pid) ``` but errors keep popping up like `Bad file descriptor`, or `unsupported name 'SIGQUIT'` when I use the `QUIT` signal instead of `INT`. Second, how do I make the 10 minutes timer before I call the method to kill the process? Thanks.

Original source