fcntl()在NFS共享上锁定文件时给出IO

时间:2016-09-01 09:07:24

标签: c++ c c++11 locking nfs

我试图在NFS中锁定文件,所以我尝试了以下操作,首先我已经使用了CLI

NSArray *searchResult;
UISearchController *mysearchController;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //code here for select the cell amd put the name of the SegueIdentifier
    [self performSegueWithIdentifier:@"getDetail" sender:indexPath];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([segue.identifier isEqualToString:@"getDetail"]) {

        if (searchResult != nil) {

            DetailViewController *detailViewController = segue.destinationViewController;

            NSIndexPath *indexPath = (NSIndexPath *) sender;
            NSDictionary *item = searchResult[indexPath.row];
            detailViewController.detailName = item[@"name"];
            detailViewController.detailLocation = item[@"address"];


        }else{

            DetailViewController *detailViewController = segue.destinationViewController;

            NSIndexPath *indexPath =  (NSIndexPath *) sender;
            NSDictionary *item = self.InfoArray[indexPath.row];
            detailViewController.detailName = item[@"name"];
            detailViewController.detailLocation = item[@"address"];

        }
    }

}

然后我发现exec 80>lock.file echo "testwrite" > &80 flock -s 80 [IO error] 在NFS中锁定文件的情况并不多,所以我打算去flock并编写以下代码

lockf

当我在本地运行它时,它编译的代码没有错误锁定文件,但是当我在已安装的路径中运行&#39; a.out&#34; filename&#34;&#39;我最终遇到了相同的IO错误。我解雇了 void write_lock(string path) { int fd; int error; fd = open(path.c_str(), O_CREAT | O_RDWR, 0664); if (fd < 0) { perror("open"); exit(EXIT_FAILURE); } // if len is zero, lock all bytes error = lockf(fd, F_LOCK, 0); if (error == 0){ printf("%#x: lock succeeds!\n", getpid()); cout<<"locked"<<endl; } else { perror("lockf"); } sleep(1); lockf(fd, F_ULOCK, 0); cout<<"unlocked"<<endl; close(fd); } 以嗅探回复消息,当我确实应用锁定(共享/独占)时,它会在下面说明

tshark

任何人都可以告诉我,我在这里遇到了什么问题,如果我发现它导致问题的原因我将在c ++ 11中编写代码来完成它......我很难用它来实现

0 个答案:

没有答案