[erlang-questions] File is_open()

Bengt Kleberg bengt.kleberg@REDACTED
Tue Mar 4 09:29:40 CET 2008


Greetings,

There is no unix support for opening a file as the exclusive reader. The
only time O_EXCL has any meaning is with O_CREAT, where it will make
sure that the file does not exist before you create it. This will stop
you from having several writers to the same file.

If you want to limit the number of readers of a file I would recommend a
resource handler. A process that keeps track of the number of readers.


bengt

On Tue, 2008-03-04 at 08:23 +0100, Ali Yakout wrote:
> Hi,
> 
> I'm doing some file processing and I want to prevent opening files
> while it is already opened. 
> I tried to open the files in write mode but it always succeed (I can
> open the file for writing many times)
> 
> 1> file:open("file",[write]). 
> {ok, <0,35,0>} 
> 2> file:open("file",[write]). 
> {ok, <0,37,0>}
> 
> I tried to rename the file after opening and it also succeeds,
> although the documentation says "Renaming of open files is not allowed
> on most platforms"
> 
> 3> file:open("file",[read]). 
> {ok, <0,35,0>} 
> 4> file:rename("file","file2"). 
> ok
> 
> Any clues ?
> 
> 
> Thanks
> 
> Regards, 
> Ali Yakout
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list