How to check file is open or close in cocoa for mac osx (objective -c)
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/bash"];
[task setArguments:@[ @"-c", [NSString stringWithFormat:@"lsof %@",FILE_PATH]];
[task launch];
[task waitUntilExit];
int status = [task terminationStatus];
if(status==0 ){
//file is open
}
if(status==1){
//file is closed
}
}
task=nil;
No comments:
Post a Comment