[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Michael P. Soulier

9/25/2006 1:55:00 AM

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
--
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction." --Albert Einstein
4 Answers

Logan Capaldo

9/25/2006 3:13:00 AM

0

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.

Michael P. Soulier

9/25/2006 11:22:00 AM

0

On 25/09/06 Logan Capaldo said:

> % cat alarm.rb
> trap("ALRM") do
> puts "Alarm!"
> end
>
> Process.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
--
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction." --Albert Einstein

Logan Capaldo

9/25/2006 12:41:00 PM

0

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!


Michael P. Soulier

9/25/2006 1:34:00 PM

0

On 25/09/06 Logan Capaldo said:

> 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!

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
--
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction." --Albert Einstein