# Alarm?

**URL:** <https://www.ruby-forum.com/t/alarm/69861>\
**Category:** Ruby\
**Created:** [September 25, 2006, 3:56am UTC](https://www.ruby-forum.com/t/alarm/69861 "2006-09-25T03:56:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_PSSoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@Michael\_PSSoulier](https://www.ruby-forum.com/u/Michael_PSSoulier)\
**Post date:** [September 25, 2006, 3:56am UTC](https://www.ruby-forum.com/t/alarm/69861/1 "2006-09-25T03:56:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_PSSoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@Michael\_PSSoulier](https://www.ruby-forum.com/u/Michael_PSSoulier)\
**Post date:** [September 25, 2006, 5:13am UTC](https://www.ruby-forum.com/t/alarm/69861/2 "2006-09-25T05:13:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_PSSoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@Michael\_PSSoulier](https://www.ruby-forum.com/u/Michael_PSSoulier)\
**Post date:** [September 25, 2006, 1:22pm UTC](https://www.ruby-forum.com/t/alarm/69861/3 "2006-09-25T13:22:00Z")

</div>

On 25/09/06 Logan C. 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

---

<div class="post-metadata">

**Author:** ![Michael\_PSSoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@Michael\_PSSoulier](https://www.ruby-forum.com/u/Michael_PSSoulier)\
**Post date:** [September 25, 2006, 3:36pm UTC](https://www.ruby-forum.com/t/alarm/69861/4 "2006-09-25T15:36:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_PSSoulier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@Michael\_PSSoulier](https://www.ruby-forum.com/u/Michael_PSSoulier)\
**Post date:** [September 25, 2006, 2:42pm UTC](https://www.ruby-forum.com/t/alarm/69861/5 "2006-09-25T14:42:13Z")

</div>

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!
