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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:29:11+00:00 2026-05-26T05:29:11+00:00

I recently switched from using kqueue to GCD dispatch sources to monitor file changes.

  • 0

I recently switched from using kqueue to GCD dispatch sources to monitor file changes. This has worked out well and resulted in a much simpler API. I documented my switch here. The only issue I have is that now I cannot access the flags on the event that I was able to in kqueue. For example with kqueue I was able to check if the file was deleted, renamed, or it’s attributes were changed with the following:

struct kevent event;

...

if(event.flag & EV_DELETE)
{
    printf("File was deleted\n");
}

Is this API not available with GCD or do I need to set up dispatch sources up for each flag I would like to listen to. Or is it best to use kqueue since it provides greater visibility to the event that has occurred.

  • 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-26T05:29:12+00:00Added an answer on May 26, 2026 at 5:29 am

    I found the answer in the Concurrency Programming Guide. I had first looked in the GCD Reference but without luck. The relevant line from the guide was

    For a descriptor dispatch source that monitors file system activity, this function returns a constant indicating the type of event that occurred. For a list of constants, see the dispatch_source_vnode_flags_t enumerated type.

    Here is an example of how you can use it.

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    int fildes = open("path/to/some/file", O_EVTONLY);
    __block dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE,fildes, 
                                                      DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE | DISPATCH_VNODE_EXTEND | DISPATCH_VNODE_ATTRIB | DISPATCH_VNODE_LINK | DISPATCH_VNODE_RENAME | DISPATCH_VNODE_REVOKE,
                                                      queue);
    dispatch_source_set_event_handler(source, ^
    {
        unsigned long flags = dispatch_source_get_mask(source);
        if(flags & DISPATCH_VNODE_DELETE)
            printf("DISPATCH_VNODE_DELETE\n");
        if(flags & DISPATCH_VNODE_WRITE)
            printf("DISPATCH_VNODE_WRITE\n");
        if(flags & DISPATCH_VNODE_EXTEND)
            printf("DISPATCH_VNODE_EXTEND\n");
        if(flags & DISPATCH_VNODE_ATTRIB)
            printf("DISPATCH_VNODE_ATTRIB\n");
        if(flags & DISPATCH_VNODE_LINK)
            printf("DISPATCH_VNODE_LINK\n");
        if(flags & DISPATCH_VNODE_RENAME)
            printf("DISPATCH_VNODE_RENAME\n");
        if(flags & DISPATCH_VNODE_REVOKE)
            printf("DISPATCH_VNODE_REVOKE\n");
    });
    dispatch_source_set_cancel_handler(source, ^(void) 
    {
        close(fildes);
    });
    dispatch_resume(source);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently switched out log4net logging from using config files to being set up
I recently switched from using Linq to Sql to the Entity Framework. One of
I recently switched from using NSTimer to CVDisplayLink to redraw my OpenGL animation, but
I recently switched over to using Janus from a custom set of vim plugins
Our company has recently switched version control systems to SVN using TortoiseSVN as our
Our company has recently switched over to using After the Deadline for our spell
I have recently switched from using Eclipse to IntelliJ, and am preferring the experience.
I have recently switched from using separate resource files to using a texture atlas.
I recently switched from a Java based project to a C#/.net project. I previously
I've recently switched from being an employee of a small consulting company to being

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.