in reply to Re^3: Creating a perl daemon
in thread Creating a perl daemon
This always works for me.
I found it by googling.daemonize(); 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/null: $!"; 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: $!"; }
Suyash Jain
suyash@linuxhacks.in
http://www.LinuxHacks.in
A Blog for Every Windows User,FEEL THE Linux freedom To RULE THE BOX.
|
---|
In Section
Seekers of Perl Wisdom