kansaschuck has asked for the wisdom of the Perl Monks concerning the following question:

So this Perl stuff is going very well. And I heading toward having a regularly running Perl script (on Windows XP laptop or Windows XP workstation). It would be running 24X7 and needs to pulse/work about once a minute or less. So I'm thinking I could just have the Windows Scheduler run the scripts every minute (not liking this just because). Or I could start a Perl script from the command Window and have it loop. So I'm now curious about such things as resource usage and Command Prompt windows open for ever. Looking for the collective wisdom of the monks to help me build what the old MVS IBM programmers would call a started task. Thanks

Replies are listed 'Best First'.
Re: Long running Perl scripts (on purpose)
by BrowserUk (Patriarch) on Feb 05, 2008 at 02:04 UTC
    1. Who starts the application and when?
    2. Does the app continue to run if the user logs off?
    3. What about when another user logs on?
    4. Does the user need (or would it be useful for them to), interact with the app on occasion?

    For entirely unattended, background operations, start at boot and continue regardless of user, Win32::Daemon is probably the way to go though there is some learning curve involved. You have to understand the modes of operation for windows services and how to control and interact with them. Also, Jan Krynicky's Win32::Daemon::Simple is easier to get started with.

    If the user needs to interact with the app, either by querying it or configuring it, or if the app should only run for a specific user, then Win32::SysTray may be a more appropriate way to go.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I'm looking to run a home monitoring workstation attached to the internet. 1. The home user would start the application or it could start automatically on boot. 2) or it could run on a users personal PC and with that in mind it would need not be affected by the users activities. It would have control devices attached to it. 3) and when others log on it should keep running. It not a user function but a 'house' function. 4. I'd like to see the application have a window, or terminal, or some icon that could be minimized if needed. So you could see status or enter a display command. I do like the idea of having it shutdown, maybe everyday at midnight and have a cron/scheduler job restart it at 12.05.

        Sounds like a combination of a Daemon and a SysTray app that interfaces with it and the user would be the way to go. If you've never written either, then you have a lot of reading to do to get things going.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Long running Perl scripts (on purpose)
by ikegami (Patriarch) on Feb 05, 2008 at 01:13 UTC

    You could use the wperl executable that comes with ActivePerl instead of perl. It forgoes using a console.

    Or you could write your script as a service so you don't even need to be logged in for it to run. See Win32::Daemon

Re: Long running Perl scripts (on purpose)
by pc88mxer (Vicar) on Feb 05, 2008 at 04:34 UTC
    BrowserUK brings up some good points. The nature of your script's operation will dictate the kind of solution you'll want to use.

    I'll share one kind of solution I've used in a Unix environment. Something that needs to operate once a minute is just a little too frequent to use cron for. However, that doesn't mean that you couldn't use it to check on your process every so often just to make sure it is still running and restart it if necessary. I've seen long-running scripts which either purposely terminate or re-start themselves every so often to "clear out the cruft" that can build up over a long running session. Sometimes it's due to unavoidable memory or resource leaks, but it is also just defensive programming. I've even heard of companies which rebooted their machines every day (but that was a while ago, like back in the perl4 days.)

Re: Long running Perl scripts (on purpose)
by quester (Vicar) on Feb 05, 2008 at 05:37 UTC
    Another possibility would be to use Cygwin cron. Just using it for cron would be overkill, but I love Cygwin. It makes Windows almost tolerable.