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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:55:51+00:00 2026-05-19T01:55:51+00:00

I encounter some problem when using inotify. I use inotify to monitor changes on

  • 0

I encounter some problem when using inotify.
I use inotify to monitor changes on files. Here is my code:

int fd = inotify_init();
int wd = inotify_add_watch(fd, "/root/temp", IN_ALL_EVENTS);
int bufSize = 1000;
char *buf = new char[bufSize];
memset(buf, 0, sizeof(buf));
int nBytes = read(fd, buf, bufSize - 1);
cout << nBytes << " bytes read" << endl;
inotify_event *eventPtr = (inotify_event *)buf;
int offset = 0;
while (offset < nBytes)
{
    cout << eventPtr->mask << endl;
    offset += sizeof(inotify_event) + eventPtr->len;
    eventPtr = (inotify_event *)(buf + offset);
}
delete []buf;

If I delete “/root/temp” and re-create such a file, any changes to this file is not monitored by inotify, anyone how is this? Thanks.

cheng

  • 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-19T01:55:52+00:00Added an answer on May 19, 2026 at 1:55 am

    That’s because inotify monitors the underlying inode, not the filename. When you delete that file, the inode you’re currently watching becomes invalid, therefore, you must invoke inotify_rm_watch. If you want to monitor a new file with the same name, but a different inode, you must detect when it’s created by monitoring its parent folder.

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

Sidebar

Related Questions

I encounter some problem when using useDelimiter from the Scanner class. Scanner sc =
I am using this code to insert some values in MySql table: <?php mysql_connect(localhost,root,root);
I encountered a problem when running some old code that was handed down to
Problem i encounter with outerHTML using IE Browser if i say: txt=Update Complete!; msg
I frequently encounter some definitions for Win32API structures (but not limited to it) that
I encountered some code reading typedef enum eEnum { c1, c2 } tagEnum; typedef
I am debugging some code and have encountered the following SQL query (simplified version):
I'm using error codes for handling errors in my c++ project. The problem is
i'm currently experiencing a little problem. I'm using nhibernate with around 40 entities mapped
I am using JAXP to generate and parse an XML document from which some

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.