How to find out if a file is open for writing


I have a function that writes to a file, how can I use another script to check if the file is used for writing or is it closed?

Edit: this file can be opened for writing by another script / application / system ...

thank.

+3
source share
3 answers

You should use flockin both scenarios. This puts the flag in the file so that other scripts are informed that the file is being used. The flag is turned off either intentionally, using fclose, or implicitly at the end of the script.

+2
source

Unix, lsof ( "LiSt Open Files" ). "FD" , , .

, ", X , -..." . , , .

+1

I would say just use the file open function, if it returns false then the file is obviously still open.

-3
source

Source: https://habr.com/ru/post/1784385/


All Articles