I need to know what the best way, if possible in a perl or shell script, to determine if a file is open by a process, and if it is open for writing.
While I would rather use a perl or shell script, if I have to use C, that would be ok.
Thanks.
I need to know what the best way, if possible in a perl or shell script, to determine if a file is open by a process, and if it is open for writing.
While I would rather use a perl or shell script, if I have to use C, that would be ok.
Thanks.
According to me this is much more easy in C.
Here is a way to find out :-
You can use fwrite function to write data into file. Before using fwrite function use fcntl and check whether the file is locked by other thread/program.
For more information refer to the man pages of fcntl & fwrite.
Aniruddha
There is a standard program called "fuser" that can tell you who has a file open. And there is a much better freeware program called "lsof" to do the same thing.