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

Hi fellow monks, I want to create a daemon that runs two perl programs that I have made, but not if the programs is running one of the other programs schould be check every 5 min and the other schould be check every 15 min. and I want the daemon to run as xxdaemon not perl ./daemon.pl can anyone point help me. Thanks, Jameel

Replies are listed 'Best First'.
Re: how do i create a daemon ??
by Brovnik (Hermit) on Sep 28, 2001 at 20:17 UTC
    I want to create a daemon

    Use Proc::Daemon

    that runs two perl programs that I have made, but not

    Use fork to create new processes.

    if the programs is running one of the other programs schould be check every 5 min and the other schould be check every 15 min. and

    Several options, depending on how sure you want to be. One simple way is for the child process to save it's PID in a known location such as /var/run and delete as it exits. The parent can check for the known files before starting the child.

    Use sleep or e.g. Sys::AlarmCall to set timers.

    I want the daemon to run as xxdaemon not perl ./daemon.pl

    Rename daemon.pl as xxdaemon, make it executable and make sure it has a shebang line.
    --
    Brovnik

Re: how do i create a daemon ??
by miyagawa (Chaplain) on Sep 28, 2001 at 20:20 UTC
Re: how do i create a daemon ??
by strredwolf (Chaplain) on Sep 28, 2001 at 22:53 UTC
    I don't know what those perl scripts are doing, but still...

    • Use cron, and write your perl scripts to be one-shot deals. cron will run your script on time every time, so you don't have to fork 'em.
    • Have your Perl scripts check for a lock file. If it exists, delay for a whort while with sleep to make sure the other finishes. When there's no lock file, write one, do what you need to do, and then delete it.
    Simple is best in Perl... and Junkyard Wars...

    --
    $Stalag99{"URL"}="http://stalag99.keenspace.com";