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 7977117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:06:07+00:00 2026-06-04T09:06:07+00:00

My problem is that I use inotify to watch multiple directories and I use

  • 0

My problem is that I use inotify to watch multiple directories and I use read() function to read any changes. My point is that I cant watch all of this directories in “same time” (“for” loop), because read() function stop program until something happens to currently watched directory.

There is simplified “main” code:

while (1){

    for(int i = 0; i < numberOfDirectories; i++){

        string fileEnd = get_event(fd[i], catalogs[i]).c_str());
        if(string != "") do some code;

    }
sleep(1);
}

Where get_event return path to changed file, fd[i] is instance of inotify, catalogs[i] contain name of watched directory.

And there is some code of get_even func:

#define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024)
string get_event(int fd, string target)
{
    ssize_t len;    
    char buff[BUFF_SIZE] = {0};       

    len = read (fd, buff, BUFF_SIZE); 

At this point main “for” loop stop work and wait until something happens in first directory. I want to just check is there any changes in watched directory instead of waiting for changes.

Help :<

  • 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-04T09:06:08+00:00Added an answer on June 4, 2026 at 9:06 am

    Call

    fcntl(fd, F_SETFL, O_NONBLOCK);
    

    just before read(…) function to force your file descriptors into nonblocking mode.

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

Sidebar

Related Questions

Ive got this problem: Line 20 (LOOT_FromContainer(container) I need that to use as Invoke
This problem is for a piece of software that is use by companies that
In a couple of scripts that I use I have problem that is intermittent.
I find I've been confused by the problem that when I needn't to use
My problem is that I was looking for way to use both storyboard and
I need to use something like get_or_create() but the problem is that I have
I have a HTML form where I use several buttons. The problem is that
I use Spring MVC [version: 2.5] and Security[version: 2.0.4]. My problem looks like that:
I have a little problem with autoconf, I know that you can use configure.ac
I have teamcity project that use mercurial. I did a few manually changes to

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.