Ok, so I think I kinda got the hang of fork() (be gentle, today was my first time ever trying it (: ) but what's say I have a program that I want the maintainer to have the choice to daemonize or not. What's say, more, that if the script daemonizes all output should go to a file log vs STDOUT. Otherwise, all output goes to STDOUT (or STDERR of course which means that STDERR needs to go to a logfile too if we daemonize). How would I do this?
My current forking code...
## Should this program daemonize...
## ie: should it run all the time
## in the background?
my $daemonize = 1;
##################################################
# fork code
if ( $daemonize ) {
my $pid = fork();
die("fork() failed: $!") unless defined $pid;
## need to do something right here
## to get STDOUT and STDERR to go
## to a file vs the console/screen.
if ($pid) {
exit(0);
}
}
----------
- Jim
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.