Hello,
I see that there is a Signal class in the core for catching signals.
Where
would the alarm system call be, for setting a SIGALRM? I can’t seem to
find
it.
Thanks,
Mike
Hello,
I see that there is a Signal class in the core for catching signals.
Where
would the alarm system call be, for setting a SIGALRM? I can’t seem to
find
it.
Thanks,
Mike
On Mon, Sep 25, 2006 at 10:55:19AM +0900, Michael P. Soulier wrote:
Hello,
I see that there is a Signal class in the core for catching signals. Where
would the alarm system call be, for setting a SIGALRM? I can’t seem to find
it.
% cat alarm.rb
trap(“ALRM”) do
puts “Alarm!”
end
Process.kill(“ALRM”, $$)
% ruby alarm.rb
Alarm!
HTH.
On 25/09/06 Logan C. said:
% cat alarm.rb
trap(“ALRM”) do
puts “Alarm!”
endProcess.kill(“ALRM”, $$)
% ruby alarm.rb
Alarm!
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
On 25/09/06 Logan C. said:
dlload “libc.#{so_ext}”
loop {}% ruby alarm.rb
Alarm!
Impressive that you could write this so quickly. Still, shouldn’t this
be in
the standard library? I certainly don’t want to do this with all of
POSIX.
Thanks,
Mike
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!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs