Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Answer: How do I run a script in the background? How should I run a script as daemon?

( #131513=categorized answer: print w/ replies, xml ) Need Help??

Q&A > input and output > 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 );

Comment on Answer: How do I run a script in the background? How should I run a script as daemon?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-10-25 01:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (139 votes), past polls