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



sktemkar
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

#!/usr/bin/perl

# daemonize the program

&daemonize;

$| = 1;

while(1)

{ print "\nIn the While\n";

open(MYFILE,'>>temp.txt');

print MYFILE "Hello Sri\n";

close(MYFILE);

}

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;

}


britantyo
Novice

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.


FishMonger
Veteran / Moderator

Feb 24, 2011, 3:32 PM


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

http://search.cpan.org/search?query=daemon&mode=all