Logan Capaldo
9/25/2006 12:41:00 PM
On Mon, Sep 25, 2006 at 08:21:44PM +0900, Michael P. Soulier wrote:
> But that doesn't tell the OS to send a SIGALRM at a predefined time. I've
> found the timeout library, and implemented what I needed with that, but isn't
> the alarm() system call exposed in Ruby? It is in Perl and Python.
>
> Thanks,
> Mike
Oops, sorry misunderstood the question. Is this better?
% cat alarm.rb
require 'dl/import'
module Alarm
extend DL::Importable
if RUBY_PLATFORM =~ /darwin/
so_ext = 'dylib'
else
so_ext = 'so'
end
dlload "libc.#{so_ext}"
extern "unsigned int alarm(unsigned int)"
end
trap("ALRM") do
puts "Alarm!"
exit
end
Alarm.alarm(3)
loop {}
% ruby alarm.rb
Alarm!