• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Notification of file system modification arrives too early?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Notification of file system modification arrives too early?


  • Subject: Re: Notification of file system modification arrives too early?
  • From: Dave Keck <email@hidden>
  • Date: Sun, 30 May 2010 17:39:58 -1000

> Unfortunately you probably can’t do any better than that, since there’s no
cheap way to find out if another process has the file open.

proc_listpidspath() is meant for this, but it is indeed quite expensive. In
my testing, it takes about a second to complete this call; furthermore, its
status as a supported API is unclear. Nonetheless, here's some
somewhat-tested code of how to use it:

==============================

#import <libproc.h>

- (NSSet *)pidsAccessingPath: (NSString *)path
{

    const char *pathFileSystemRepresentation = nil;
    int listpidspathResult = 0;
    size_t pidsSize = 0;
    pid_t *pids = nil;
    NSUInteger pidsCount = 0,
               i = 0;
    NSMutableSet *result = nil;

        NSParameterAssert(path && [path length]);

    pathFileSystemRepresentation = [path GCSafeFileSystemRepresentation];
    listpidspathResult = proc_listpidspath(PROC_ALL_PIDS, 0,
pathFileSystemRepresentation, PROC_LISTPIDSPATH_EXCLUDE_EVTONLY, nil, 0);

        ALAssertOrPerform(listpidspathResult >= 0, goto cleanup);

    pidsSize = (listpidspathResult ? listpidspathResult : 1);
    pids = malloc(pidsSize);

        ALAssertOrPerform(pids, goto cleanup);

    listpidspathResult = proc_listpidspath(PROC_ALL_PIDS, 0,
pathFileSystemRepresentation, PROC_LISTPIDSPATH_EXCLUDE_EVTONLY, pids,
pidsSize);

        ALAssertOrPerform(listpidspathResult >= 0, goto cleanup);

    pidsCount = (listpidspathResult / sizeof(*pids));
    result = [NSMutableSet set];

    for (i = 0; i < pidsCount; i++)
        [result addObject: [NSNumber numberWithInt: pids[i]]];

    cleanup:
    {

        if (pids)
            free(pids),
            pids = nil;

    }

    return result;

}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Notification of file system modification arrives too early?
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >Re: Notification of file system modification arrives too early? (From: James Bucanek <email@hidden>)
 >Re: Notification of file system modification arrives too early? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Which color space?
  • Next by Date: Re: Value Transformer with multiple Model Key Paths
  • Previous by thread: Re: Notification of file system modification arrives too early?
  • Next by thread: Re: Notification of file system modification arrives too early?
  • Index(es):
    • Date
    • Thread