Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Perl daemon ?

by baxy77bax (Deacon)
on Nov 20, 2009 at 20:40 UTC ( [id://808521]=note: print w/replies, xml ) Need Help??


in reply to Perl daemon ?

hi,

to make a simple daemon just de-attach the called script with this peace of code:

die "Cannot continue :$!" unless(defined(my $kid = fork())); unless ($kid){ system("my scheduler"); exit; }
and now when you demonize your script then you can with a simple while loop schedule all scripts set in some dir like:
in my scheduler : ----------------- while(1){ # predefined diractory opendir(DIR,"some dir") || die "$!"; foreach my $sc (readdir(DIR)){ next if ($sc=~/\./g); system($sc); } sleep 3600; # of whatever time you need }
and that is more-or-less what you need to set up your first crone-like application. (just remember to set the absolute path with readdir -> it just captures the names of scripts in opened folder). of course don't forget to chmod to 555 to all files in defined dir (either through perl or manually).

good luck !

Replies are listed 'Best First'.
Re^2: Perl daemon ?
by newbie01.perl (Sexton) on Nov 23, 2009 at 10:26 UTC

    Hi,

    I think this is more or less what I wanted. I found some example that uses fork as well but not sure whether that will actually make any difference.

    Also found a Daemon.pm, but not to sure on how to use it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://808521]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2025-11-11 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (67 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.