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

You have to setsid too, to disassociate from your parent's process group:
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(setsid);

# Become a daemon
my $pid=fork;
exit if $pid; # Parent exits here
die "Couldn't fork $!" unless defined($pid);
die "Couldn't start new session $!" unless POSIX::setsid();

# Do your daemon bit...
  • Comment on Re: Answer: Is it possible to background a perl script from within itself?