Home: Perl Programming Help: Advanced:
Perl daemon exiting without warning

New User

Feb 10, 2011, 9:27 PM

Views: 3013
Perl daemon exiting without warning

hi, I have written a daemon example. But i dont know why it is not running. When i debugged using print statment, it is exiting after the (open STDIN, '/dev/null' or die "Can't read /dev/null: $!";) statement in the daemonize method. Can you please help me


# daemonize the program


$| = 1;


{ print "\nIn the While\n";


print MYFILE "Hello Sri\n";



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: $!";

open STDERR, '>>/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: $!";

umask 0;



Feb 24, 2011, 9:53 AM

Views: 2822
Re: [sktemkar] Perl daemon exiting without warning

maybe you should add

use File::Basename;
use strict;

above your script. well you use filehandler right...give it a shot
Be free to decide your dream, Put the details of your dream in your head and heart And don't give up 'till you drop dead.

Veteran / Moderator

Feb 24, 2011, 3:32 PM

Views: 2812
Re: [sktemkar] Perl daemon exiting without warning