Contributed by jeroenes
on Nov 16, 2000 at 21:16 UTC
Q&A
> input and output
Answer: How do I run a script in the background? How should I run a script as daemon? contributed by jeroenes If you run a script in a the background with
exec, things go nasty after a while
when you
kill your terminal. You can prevent this (I tried
it only under linux) by setting
SIG{INT}='IGNORE'.
Actually, a better solution is the Proc::daemon
module, or the Net::daemon module if you need to
claim a socket. | Answer: How do I run a script in the background? How should I run a script as daemon? contributed by c0d34w4y
Try this...
close STDIN; close STDOUT; close STDERR;
if (open(DEVTTY, "/dev/tty")) {
ioctl(DEVTTY,0x20007471,0);
close DEVTTY;
}
open(STDIN,"</dev/null");
open(STDOUT,">/dev/null");
open(STDERR,">&STDOUT");
# at this point there are two processes... for parent, fork wi
+ll return a 'true' number,
# for child it'll return 0. thus, parent will exit and child w
+ill remain to run.
fork && exit;
# certain signals should be ignored
$SIG{"HUP"} = $SIG{"ALRM"} = $SIG{"PIPE"} = $SIG{"INT"} = "IGN
+ORE";
# set some priority for the process...
# (so that it doesn't end up wasting your
# server resources)
setpriority( "PRIO_PROCESS", 0, 10 );
|
Please (register and) log in if you wish to add an answer
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
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.
|
|