Why doesn't my program write a file when using Proc :: Daemon?

I am writing some test code before use Proc::Daemon, as my test code is:

#! /usr/bin/perl

use strict;
use warnings;
use Proc::Daemon;

Proc::Daemon::Init();
my $continue = 1;
$SIG{TERM} = sub { $continue = 0 ; }

while ( $continue ) {
    sleep(5) ;
    &greeting ;
}

sub greeting {
    open ( FH, ">>/home/daogu/foo" ) or die "can't open it" ;
    print FH "hello word\n" ;
    close FH ;
}

After I launched the demon toy, I did not find anything that was written in " foo". can anyone explain why this is happening? thanks.

+3
source share
2 answers

First, you need a comma to complete the assignment on line 9:

$SIG{TERM} = sub { $continue = 0 ; };

Until I added that your program does not even start, so I assume that you have this in a script and skipped it here.

, , , . . top. script, Perl. , Perl. script , , .

- die warn . , (, top, ). , , .

: Yup, + STDERR = , . , , , STDERR:

Proc::Daemon::Init();
my $continue = 1;
$SIG{TERM} = sub { $continue = 0 ; };

while ( $continue ) {
    sleep(5);
    greeting();
}

sub greeting {
    open STDERR, '>>', '/Users/telemachus/log'
        or die "Can't reopen STDERR to log: $!";
    open my $fh, '>>', '/usr/local/foo'
        or warn "Can't open /usr/local/foo for writing: $!";
    print $fh "hello word\n";
    close $fh;
}

, :

foo : Permission denied at daemon line 21. print() $fh 22.

+7

script . , - , , , , .

script , .

+3

Source: https://habr.com/ru/post/1715275/


All Articles