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

  • SEARCH
  • Home
  • 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 7696297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:44:49+00:00 2026-05-31T21:44:49+00:00

I have a daemon process written in Perl that uses Inotify2 to watch directories

  • 0

I have a daemon process written in Perl that uses Inotify2 to watch directories for incoming files. On arrival of each file, the daemon will fork a child process. Now, it seems too many files are arriving at the same time (hence too many forks), because I got this error in my log file:

Cannot allocate memory at notifyd.pl line ...

which is the result of fork().

Basically I have the following code:

    my $inotify = new Linux::Inotify2() or die($!);

    foreach my $k (@PATHS) {
        $inotify->watch($k,
IN_MOVE_SELF|IN_DELETE_SELF|IN_CLOSE_WRITE, \&watcher) or die($!);
    }

    $inotify->blocking(1) or die($!);

    for(;;) {
        $inotify->poll() or die($!);
    }

with the watcher function doing fork and then execv:

sub watcher {
        my $e = shift;
        my $pid = fork();
        if(!defined $pid) {
            print "[ERROR]", $!;
        }
        elsif($pid == 0) {
            my @args = ($e->fullname, $e->mask);
            exec($childprocess, @args) or die($!);
        }
}

I cannot afford to miss events by not forking a process.

Does anyone have suggestions how I can improve this and make sure fork will not fail?


Edit: it seems like the child processes were becoming zombies once they exited since the daemon would not respond to SIGCHLD. So a lot of zombie child processes could have been the reason why fork() failed. The daemon now does $SIG{CHLD} = 'IGNORE'; before forking.

  • 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-05-31T21:44:50+00:00Added an answer on May 31, 2026 at 9:44 pm

    Solve the problem by adding another layer of indirection.

    When you receive an event, put the file name into a job queue. The queue starts a new job processing the file when resources are reasonable free; this scheme guarantees that the event will eventually be acted upon, just not all of them immediately.

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

Sidebar

Related Questions

I have a process x which uses system C function to start ntpd daemon.
I have a process that is running as a java daemon on Ubuntu Linux.
I have a daemon that forks the process. This daemon access a database using
Is it so memory consuming to have a daemon written on php (which listens/process
I have a python daemon process that gets started via rc.local. This same script,
I have a daemon app written in C and is currently running with no
I have a daemon that does the following retrieves site members from a mysql
We have a small daemon application written in C for a couple of various
I have a small daemon that I'm writing in C and I need a
To create a daemon I have read somewhere that in order to close all

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.