Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

proc Daemon

by sthangav (Initiate)
on Jan 13, 2013 at 05:57 UTC ( #1013085=perlquestion: print w/replies, xml ) Need Help??
sthangav has asked for the wisdom of the Perl Monks concerning the following question:

Can any one have sample code for making Daemon process ? please send me the code to it helps me to make my script to daemon.


Thanks Friends !

Replies are listed 'Best First'.
Re: proc Daemon
by eyepopslikeamosquito (Chancellor) on Jan 13, 2013 at 06:17 UTC

    Please take the time to read How (Not) To Ask A Question before posting again.

    In particular, you need to show some effort and not ask people to email you. From How (Not) To Ask A Question:

    This is a forum, not a mailing list. If you post your email address, then you are only going to allow spam bots to find it and add it to their spam lists. If you take the time to register yourself as a user, you can go to your User Settings and check the box that says '/msg me when there's a reply' under the Miscellaneous options to receive a private message when someone replies. Otherwise, check back in about 10 to 20 minutes, and then once every hour until you have an answer that satisfies you. You should also check back the next day and maybe even the next week - you never know when someone will post a 'late' response that is very helpful and informative.

Re: proc Daemon
by Anonymous Monk on Jan 13, 2013 at 08:22 UTC
Re: proc Daemon
by LanX (Archbishop) on Jan 13, 2013 at 06:18 UTC
    O dear, seems like you have no access to google search! :(

    Just wait a little I'll do the search for you and will send the results ASAP to your google mail account...

    Cheers Rolf

Re: proc Daemon
by karlgoethebier (Monsignor) on Jan 13, 2013 at 16:42 UTC
    "please send me the code..."

    OK, but please cash in advance.

    Update: If this is beyond your budget, here is a hint.


    «The Crux of the Biscuit is the Apostrophe»

Re: proc Daemon
by parv (Priest) on Jan 14, 2013 at 09:46 UTC
    You know you should pick up Python programming instead as I read somewhere around here that Python community is not as cynic nor as snooty as Perl one.
      Definitely! ;-)

      And what's even worse, some monks are not clever enough to spot clever cynicism and will start downvoting you.¹ =)

      Cheers Rolf


      ¹) ... for the wrong reasons.

        Don't make it a good (or appropriate) answer tho.
Re: proc Daemon
by karlgoethebier (Monsignor) on Jan 14, 2013 at 23:42 UTC

    Another hint:

    #!/usr/bin/perl + # use POSIX qw(setsid); use IO::All; use strict; use warnings; daemonize(); my $date_time; while (1) { $date_time = scalar localtime; qq($date_time\n) > io('/tmp/daemon.log'); sleep 5; } sub daemonize { defined (my $child = fork) or die qq(I really can't do that...!\n); exit if ( $child ); setsid(); open( STDIN, "</dev/null" ); # open( STOUT, ">/dev/null" ); # inferior mistake! open( STDOUT, ">/dev/null" ); + open( STDIN, ">&STDOUT" ); chdir '/'; umask(0); # ENV{PATH} = qq(what/you/really/need); + } __END__

    Update: Mea culpa! I talked pretty big before. Perhaps it would have been better if someone pointed me out on this awkward typo? I've seen hints on typos already at the monastery. Anyway - i'm sorry about this.

    Examine the result:

    tail -f /tmp/daemon.log

    Get the PID:

    # ps aux | grep '[/]usr/bin/perl ./' | perl -ane 'print $F[1] +'; # if many... ps aux | grep '[/]usr/bin/perl ./' | perl -ane 'print $F[1] . + qq(\n)'

    Get rid of it:


    # kill -TERM $(ps aux | grep '[/]usr/bin/perl ./' | perl -ane + 'print $F[1]';) # if many... kill -TERM $(ps aux | grep '[/]usr/bin/perl ./' | perl -ane ' +print $F[1] . qq(\n)')

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1013085]
Approved by rovf
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2018-12-12 07:56 GMT
Find Nodes?
    Voting Booth?
    How many stories does it take before you've heard them all?

    Results (57 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!