Using Unix Process Controll Methods in Ruby

Posted by John F. Miller on Stack Overflow See other posts from Stack Overflow or by John F. Miller
Published on 2009-10-22T03:10:11Z Indexed on 2010/03/28 1:23 UTC
Read the original article Hit count: 337

Ryan Tomayko touched off quite a fire storm with this post about using Unix process control commands.

We should be doing more of this. A lot more of this. I'm talking about fork(2), execve(2), pipe(2), socketpair(2), select(2), kill(2), sigaction(2), and so on and so forth. These are our friends. They want so badly just to help us.

I have a bit of code (a delayed_job clone for DataMapper that I think would fit right in with this, but I'm not clear on how to take advantage of the listed commands. Any Ideas on how to improve this code?

def start
  say "*** Starting job worker #{@name}"
  t = Thread.new do
    loop do
      delay = Update.work_off(self)
      break if $exit
      sleep delay
      break if $exit
    end
    clear_locks
  end

  trap('TERM') { terminate_with t }
  trap('INT')  { terminate_with t }

  trap('USR1') do
    say "Wakeup Signal Caught"
    t.run
  end
end

© Stack Overflow or respective owner

Related posts about ruby

Related posts about unix-programming