Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > alarm?

Reply
Thread Tools

alarm?

 
 
Michael P. Soulier
Guest
Posts: n/a
 
      09-25-2006
--pZs/OQEoSSbxGlYw
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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
--=20
Michael P. Soulier <(E-Mail Removed)>
"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

--pZs/OQEoSSbxGlYw
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFFFzb9KGqCc1vIvggRAgDfAJ4pwHfbjzKFCyb6tXJebb 7Rm49gfwCcCO0T
7KLHIlG0TxSkJwYSmvmgexM=
=WL1I
-----END PGP SIGNATURE-----

--pZs/OQEoSSbxGlYw--

 
Reply With Quote
 
 
 
 
Logan Capaldo
Guest
Posts: n/a
 
      09-25-2006
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.

 
Reply With Quote
 
 
 
 
Michael P. Soulier
Guest
Posts: n/a
 
      09-25-2006
--b8GWCKCLzrXbuNet
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 25/09/06 Logan Capaldo said:

> % cat alarm.rb
> trap("ALRM") do
> puts "Alarm!"
> end
>=20
> Process.kill("ALRM", $$)
>=20
>=20
> % 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
--=20
Michael P. Soulier <(E-Mail Removed)>
"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

--b8GWCKCLzrXbuNet
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFFF7u1KGqCc1vIvggRApoRAJ92WmSxxvDYh5BPMWdfrj 4O7kxBKwCgrfiR
DCgUgStRfkSXYu5aKt3x+RA=
=5MPP
-----END PGP SIGNATURE-----

--b8GWCKCLzrXbuNet--

 
Reply With Quote
 
Logan Capaldo
Guest
Posts: n/a
 
      09-25-2006
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!


 
Reply With Quote
 
Michael P. Soulier
Guest
Posts: n/a
 
      09-25-2006
--SLauP2uySp+9cKYP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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 =3D~ /darwin/
> so_ext =3D 'dylib'
> else
> so_ext =3D 'so'
> end
> dlload "libc.#{so_ext}"
> extern "unsigned int alarm(unsigned int)"
> end
>=20
> trap("ALRM") do
> puts "Alarm!"
> exit
> end
>=20
> Alarm.alarm(3)
>=20
> loop {}
>=20
> % 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
--=20
Michael P. Soulier <(E-Mail Removed)>
"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

--SLauP2uySp+9cKYP
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFFF9rHKGqCc1vIvggRAmelAKCb25Wd9uLnMVswo3S0Ya QMWYqqRACgtm+f
tkjdudCs8/Xrv9fYOOvRrH0=
=7PNN
-----END PGP SIGNATURE-----

--SLauP2uySp+9cKYP--

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments