Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8519097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:09:17+00:00 2026-06-11T06:09:17+00:00

I use daemonize to create a daemon process and then write something to the

  • 0

I use daemonize to create a daemon process and then write something to the file named log,
but when I ran it, it did not work.

Why could I not write to the log?

use POSIX;

sub daemonize{
    chdir '/';
    umask 0;
    open STDIN,'/dev/null'   || die "can not open /dev/null:$!";
    open STDOUT,'>/dev/null' || die "can not open /dev/null:$!";
    open STDERR,'>/dev/null' ||die "can not open /dev/null:$!";
    defined ($pid=fork) || die "can not fork a process:$!";
    exit if $pid;
    setsid || die "can not create session:$!";
}

&daemonize;
open LOG,">>/dev02/ycq/test/log" ||die "can not open file:$!";
my $num=0;
while(1){
    print LOG "$num\n";
    sleep 1;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:09:19+00:00Added an answer on June 11, 2026 at 6:09 am

    When using open (or any other function or subroutine), you need to take into consideration the operator precedence. In your case, the || operator has higher precedence than the , (comma) operator.

    Your lines that look like this:

    open LOG, "file.txt" ||die "can not open file:$!";
    

    Actually mean this, when precedence is taken into consideration:

    open LOG, ("file.txt || die ...);
    

    Since "file.txt" is a true statement, it will never trigger the die statement.

    What you need is either:

    open(LOG, "file.txt") || die ...
    

    or

    open LOG, "file.txt" or die ...
    

    In the first case, the parens override the operator precedence, in the second case, the or operator has lower precedence than the comma operator.

    What all this means is that your open calls may have failed silently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to write a daemon in python. But I have no idea how
I'm currently trying to manually create a simple daemon process, I don't want to
use C#,want to upload excel file on google doc. bellow syntax use to upload
use pthread_create to create limited number of threads running concurrently Successfully compile and run
Use Case: End-User searches for something and an ArrayCollection is returned with Result objects.
use warnings; use Test::More; use File::Find::Rule; use Test::File::Find::Rule; my $rule = File::Find::Rule->file->name('*.pl')->not_grep(qr/^\s*use\s+strict;/m, sub {
Use case: I find a piece of code that I do not understand at
I would like to use the popular Thor gem to create a daemonized task.
Use case: 3rd party application wants to programatically monitor a text file being generated
Use trap to capture signals like this: i=-1;while((++i<33)); do trap echo $i >> log.txt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.