博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何检测Linux中是否有其他进程正在写入文件?
阅读量:2516 次
发布时间:2019-05-11

本文共 1254 字,大约阅读时间需要 4 分钟。

How to detect whether a file is being written by any other process in ?

如何检测是否有其他进程正在写入文件?

Before a program open a file to processes it, it wants to ensure no other processes are writing to it. Here, we are sure after the are written and closed, they will not be written any more. Hence, one-time checking will be good enough.

在程序打开文件进行处理之前,它要确保没有其他进程正在写入该文件。 在这里,我们确定在写入和关闭之后,它们将不再被写入。 因此,一次检查就足够了。

You may not know whether the file is being written. However, you may use to check whether the file is opened by any other processes. Programs like will close the file after the work is done. So you may bet on it for most situations.

您可能不知道是否正在写入文件。 但是,您可以使用来检查文件是否被其他进程打开。 诸如程序将在工作完成后关闭文件。 因此,在大多数情况下,您都可以下注。

For a file without any other process opening it:

对于没有其他任何打开过程的文件:

$ lsof -f -- ~/.bashrc

With one process openning for reading:

随着一个过程的开放阅读:

$ lsof -f -- ~/.bashrc   PID USER   FD   TYPE DEVICE SIZE/OFF     NODE NAMEless    14558  zma    4r   REG  253,3     1356 27787271 /home/zma/.bashrc

With one process openning for writing:

随着一个开放的写作过程:

$ lsof -f -- ~/.bashrcCOMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF     NODE NAMEvim     14840  zma   10w   REG  253,3     1355 27787271 /home/zma/.bashrc
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自:

转载地址:http://pfowd.baihongyu.com/

你可能感兴趣的文章
ps -aux
查看>>
Uploadify 上传文件插件详解
查看>>
游戏开发设计模式之子类沙盒模式(unity3d 示例实现)
查看>>
时间复杂度与空间复杂度
查看>>
Ajax 是什么?Ajax 的交互模型?同步和异步的区别?如何解决跨域问题
查看>>
Session 起航 登录会话和注销请求 重定向和转发
查看>>
毕设问题小记——Struts2如何将父类属性序列化为JSON格式
查看>>
有效投标不足三家不应是重新招标的必要条件
查看>>
标准分页
查看>>
3dContactPointAnnotationTool开发日志(二四)
查看>>
C语言运算符优先级
查看>>
javascript 之this指针-11
查看>>
完成登录与注册页面的前端
查看>>
hihocoder 1643 Puzzle Game(北京icpc2017 现场赛)
查看>>
vim 简单理解三种模式 粗暴入门
查看>>
django模板层之静态文件引入优化
查看>>
转载使用命令wsimport构建WebService客户端
查看>>
java实现23种设计模式之模版方法模式
查看>>
小程序·云开发实战 - 校园约拍小程序
查看>>
闲话函数式变成与OOP
查看>>