Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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 (Bishop) 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 (Prior) 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 (Prior) 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
[Dumu]: got it. Anyway. Perl question. Can you use binmode more than once with an open filehandle to read a file first in binary mode, then in utf8 mode?
[ambrus]: Dumu: you can use binmode multiple times, but mostly at the start before you read things. it would be strange to change the io layers after you've already read things, and might not work too well.
[ambrus]: Dumu: why would you want to read the same file both in binary mode and utf8 mode?
[Corion]: Dumu: Yes, but switching needs to be done with caution, as you might read half an UTF-8 character in binary mode, and then switch to utf8 mode...
[Corion]: Personally, I would do the decoding of data in the program and not in the filehandle
[Corion]: ambrus: Maybe a record-based file where some data is strings encoded as utf8
[Corion]: But again, I would read all data as binary and then decode from utf8
[ambrus]: Corion: that wouldn't be my guess, but I'll wait for Dumu
[Corion]: Meh. I'm now on Firefox 57 ("Quantum") and again have to remove Pocket, and reinstall the adblocker, uMatrix (because NoScript doesn't work) and silence the about:blank page to not download crap from the internet
[Corion]: Maybe I shouldn't update software ...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2017-11-20 17:48 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (290 votes). Check out past polls.