Re: How to wait for file closing?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi

That depends. The only way you can be sure that the eu program will read the program correctly is if the C program has close the file first.

The reason for this is that I believe the OS will 'hold on' to some bytes in a buffer, and this buffer won't be flushed to disk until the calling program closes, or releases, the file handle. In other words (and this is by way of illustration only)

C program

FILE *file = fopen("yum-yum.lst", "w"); 
fputs("Hot Fudge Sundae\n", file); 
fputs("Muffin\n", file); 
fputs("Hash Browns With Maple Syrup\n"); 

(fclose deliberately left off)

whats on the disk 
Hot Fudge Sundae 
Muffin 
Hash Browns Wi        (th Maple Syrup is still in the buffer) 

when fclose is called, th Maple Syrup is flushed, and the file on disk now looks like this

Hot Fudge Sundae 
Muffin 
Hash Browns With Maple Syrup 

Now, some file systems will let you read that partially created disk, and some won't, and I don't know if there is a way to tell that there is an open file handle associated with that file.

If you are writing the C++ program, then I would suggest writing a small 'indicator' file that the eu program checks for before it reads the file, ie

pseudocode

if file 'yumyum.lck' exists then don't read file

The C++ program at the same time creates and deletes yumyum.lck whenever it opens and closes the file

That is how I would do it without having to worry about how the OS handles file locking and releasing.

There are probably better, and more sophisticated ways of doing it though.

Chris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu