Re: Timer/Alarm for MUD script



On 2005-05-20, cstegmann@xxxxxxxxx scribbled these
curious markings:

Being overly addicted to MUDs and online gaming, I feel obligated to
followup to this. :)

> i'm switching from windows to mandrake and have to give up on my zmud
> system and craft an identical one in perl for kmuddy. I figured out how
> to do most of my zmud coding in perl except for one thing: the #alarm
> function in zmud.
> THe syntax goes like this-> #alarm +3 {command}
> This would wait for 3 seconds and then execute the command which could
> be setting a certain variable or running a subroutine.
>
> I read a little and only saw a lot of references to the sleep funtion.
> But that halts the whole script and i'll be running this timer from in
> a subroutine or a trigger and cannot have the rest of my system
> disabled for that time.
>
> Does anyone have any suggestions?

What you'll want is Perl's built-in alarm function. It conveniently
takes a number of seconds as an argument. You'll need to set up a
handler for SIGALRM (see perlipc).

Unfortunately, you can only have one alarm running at a time. If you
want anything more complicated than that, you'll either need to keep
track of each applicable timer's countdown in the SIGALRM handler (which
would be kind of fun, actually...) and call alarm with the timeout for
the lowest countdown. Or you could use a prebuilt event-based framework,
like Event or POE.

<OT>Having a look at the project in which you'll be using this, I'm not
sure if using alarm will actually work. Do you know if kmuddy would
receive the signal, or if some external perl process would? If kmuddy
would, then it needs to propagate that signal to your script, or alarm
won't do you any good. You may find a better answer on
comp.unix.programmer or perhaps a KDE-specific mailing list.</OT>

Best Regards,
Christopher Nehren
--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
If you ask the wrong questions, you get answers like "42" and "God".
Unix is user friendly. However, it isn't idiot friendly.
.



Relevant Pages

  • Timer/Alarm for MUD script
    ... i'm switching from windows to mandrake and have to give up on my zmud ... system and craft an identical one in perl for kmuddy. ... be setting a certain variable or running a subroutine. ...
    (comp.lang.perl.misc)
  • Re: Bash: command output to variable
    ... list top 10 cpu intensive processes. ... An optimized perl solution: ... # reads a key without echo and with a timeout of $timeout seconds ... alarm $timeout; ...
    (comp.unix.shell)
  • Re: How to time out a forked command but still see output?
    ... Haven't done Perl in years. ... I tried a few things involving alarm() and eval but couldn't get them ... I also tried something like redirecting CMD to STDOUT but when I do ... die "\nTimed out command $command after waiting ...
    (comp.lang.perl.misc)
  • Re: Bash: command output to variable
    ... ReadMode "normal"; ... # reads key with a timeout of 5 seconds without echo ... alarm $timeout; ... # if the Perl syntax error message string exists and is not ...
    (comp.unix.shell)
  • Re: Cursor moving in one position
    ... On Mon, 9 Feb 2004, Ricardo Pichler wrote: ... I tested the following on RedHat Linux 9.0 using Perl 5.8.0. ... The alarm() function only has resolution to about 1 ... This means you can cancel your "spinner" using ...
    (perl.beginners)