Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Syntactic Confectionary Delight
 
PerlMonks

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

 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

( #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
Login:
Password
remember me
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 surveying the Monastery: (25)
GrandFather
talexb
jdporter
wfsp
runrig
jmcnamara
atcroft
mr_mischief
LTjake
kennethk
herveus
MidLifeXis
Marshall
davies
SFLEX
jkva
ssandv
stefbv
umasuresh
AndyZaft
Neighbour
RedElk
petecm99
DarthWavy
ldbpm
As of 2010-09-02 15:12 GMT
Sections?
Seekers of Perl Wisdom
Cool Uses for Perl
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Perl News
See About the sections of PerlMonks
Information?
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes?
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers?
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth?

My favourite poll on PerlMonks is ...

Your first Perl Book - the first one ever
Average number of caffeinated beverages per work day - the poll with the highest participation
My Thoughts on the New Voting/Experience System - the poll with the fewest votes cast
When I grow up, I want to be: - one of the polls with the fewest options
Perl 6 will primarily be: - the first one on Perl6
When I see a poll - one of the many polls about polls
this poll ;-)
yet to come
none - I hate polls. Bah.
some other

Results (49 votes), past polls