CC: | kane [...] cpan.org, zefram [...] fysh.org, gisle [...] aas.no |
Subject: | Re: Modification to IPC::Cmd |
Date: | Thu, 5 Sep 2013 17:00:59 -0700 |
To: | Philip Prindeville <philipp [...] cpan.org>, bug-IPC-Cmd [...] rt.cpan.org |
From: | Jos Boumans <jos [...] dwim.org> |
Hi Philip,
that's an interesting suggestion - I've copied bug-IPC-Cmd@rt.cpan.org,
so it's tracked inside the bug tracker as well.
That'll also give Chris a chance to review it and weigh in his opinion.
Cheers,
-Jos
On 5 Sep 2013, at 16:53, Philip Prindeville wrote:
Show quoted text
> Hi Jos,
>
> I was trying to use Time::HiRes's setitimer() to periodically run a script and collect output, but of course IPC::Cmd::run() uses alarm(), and hence clobbers any previously set interval timer.
>
> I was wondering if the following could be done?
>
> Inside ::run, get any pending interval timer with getitimer(ITIMER_REAL) and figure out what the remaining time is.
>
> Take this delta, and add it to the current time from gettimeofday().
>
> When the function completes and is about to return, IFF there had been a pending interval timer, check whether it has expired. If it has, kill ALARM, getpid(). If it hasn't expired, restore the remaining time and repetition interval with setitimer().
>
> This effectively implements a "stack" to save the pending interval timer returned by getitimer (if any) and then restores it (adjusting for elapsed time) on exit.
>
> It would be nice if Time::HiRes implemented the hooks to save and restore the itimer, but that's a "perfect world" scenario.
>
> Thanks,
>
> -Philip
>