本文共 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
翻译自:
转载地址:http://pfowd.baihongyu.com/