Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Is it possible to background a perl script from within itself?

by Fastolfe (Vicar)
on Nov 15, 2000 at 19:18 UTC ( [id://41773]=note: print w/replies, xml ) Need Help??


in reply to Is it possible to background a perl script from within itself?

I typically use a variation of this 'daemonize' code taken from perlipc. This sets up the script's environment and disassociates it from the caller entirely.
sub daemonize { chdir '/' or die "Can't chdir to /: $!"; open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>/dev/null' or die "Can't write to /dev/nul +l: $!"; defined(my $pid = fork) or die "Can't fork: $!"; exit if $pid; setsid or die "Can't start a new session: $!"; open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; }
You could also open STDOUT to point to, say, a log file here. Or a tied filehandle passing its data to syslog.
  • Comment on Re: Is it possible to background a perl script from within itself?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://41773]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-19 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found