alarm?

Discussion in 'Ruby' started by Michael P. Soulier, Sep 25, 2006.

  1. --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 <>
    "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--
     
    Michael P. Soulier, Sep 25, 2006
    #1
    1. Advertising

  2. 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.
     
    Logan Capaldo, Sep 25, 2006
    #2
    1. Advertising

  3. --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 <>
    "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--
     
    Michael P. Soulier, Sep 25, 2006
    #3
  4. 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!
     
    Logan Capaldo, Sep 25, 2006
    #4
  5. --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 <>
    "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--
     
    Michael P. Soulier, Sep 25, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. service

    alarm workaround

    service, Nov 6, 2003, in forum: Perl
    Replies:
    0
    Views:
    597
    service
    Nov 6, 2003
  2. Tim Zych

    Authentication with Zone Alarm?

    Tim Zych, Jan 11, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    329
    Tim Zych
    Jan 11, 2004
  3. honcho
    Replies:
    0
    Views:
    450
    honcho
    Jun 24, 2005
  4. Ole Weigelt

    Greenhorn Alarm

    Ole Weigelt, Sep 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    429
  5. Boki
    Replies:
    2
    Views:
    413
Loading...

Share This Page