在C / C Linux的文件锁定++ [英] Locking files in linux with c/c++

查看:121
本文介绍了在C / C Linux的文件锁定++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,您可以:锁住一个行或在Linux中的文件和文件的其余部分的单个字符应该仍可以访问其他进程?
我收到了关于与/ C ++在Linux下C文件模拟交易的任务。
请给我一个答案,如果答案是肯定的,给我从那里我可以采取偷看,使这项工作的一些链接。

I am wondering if you can : lock only a line or a single character in a file in linux and the rest of the file should remain accessible for other processes? I received a task regarding simulating transaction on a file with c/c++ under linux . Please give me an answer and if this answer is yes ,give me some links from where i could take a peek to make this task.

谢谢,
Madicemickael

Thanks, Madicemickael

推荐答案

是的,这是可能的。

Unix的方式做,这是通过 的fcntl 提供lockf
不管你选择,确保只使用它,而不是将两者搅和。有一个关于它的看这个问题(与答案):<一href=\"http://stackoverflow.com/questions/575328/fcntl-lockf-which-is-better-to-use-for-file-locking\">fcntl,提供lockf,这是更好的为文件锁定使用?。

The Unix way to do this is via fcntl or lockf. Whatever you choose, make sure to use only it and not mix the two. Have a look at this question (with answer) about it: fcntl, lockf, which is better to use for file locking?.

如果可以,在 UNIX环境高级编程

这篇关于在C / C Linux的文件锁定++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆