CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



sktemkar
New User

Feb 10, 2011, 9:27 PM

Post #1 of 3 (1174 views)
Perl daemon exiting without warning Can't Post

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

Post #2 of 3 (983 views)
Re: [sktemkar] Perl daemon exiting without warning [In reply to] Can't Post

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

Feb 24, 2011, 3:32 PM

Post #3 of 3 (973 views)
Re: [sktemkar] Perl daemon exiting without warning [In reply to] Can't Post

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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives