alarm?

M

Michael P. Soulier

--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 <[email protected]>
"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)

iD8DBQFFFzb9KGqCc1vIvggRAgDfAJ4pwHfbjzKFCyb6tXJebb7Rm49gfwCcCO0T
7KLHIlG0TxSkJwYSmvmgexM=
=WL1I
-----END PGP SIGNATURE-----

--pZs/OQEoSSbxGlYw--
 
L

Logan Capaldo

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.
 
M

Michael P. Soulier

--b8GWCKCLzrXbuNet
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

% 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 <[email protected]>
"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)

iD8DBQFFF7u1KGqCc1vIvggRApoRAJ92WmSxxvDYh5BPMWdfrj4O7kxBKwCgrfiR
DCgUgStRfkSXYu5aKt3x+RA=
=5MPP
-----END PGP SIGNATURE-----

--b8GWCKCLzrXbuNet--
 
L

Logan Capaldo

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

Michael P. Soulier

--SLauP2uySp+9cKYP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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 <[email protected]>
"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)

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

--SLauP2uySp+9cKYP--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,743
Latest member
WoodrowMea

Latest Threads

Top