Re: How to wait for file closing?
- Posted by ChrisB (moderator) Dec 11, 2012
- 1661 views
Hi
That looks a little tangled. Try (pseudocode)
c program
file *fp, *fl //get data from sensors fl = fopen("lock_file", "w") puts(fl, "~") fclose(fl) fp = fopen("datafile", "w") //put all your data in there fclose(fp) unlink("lock_file")
then in the eu program
if file_exists("lock_file") then --can't do anything, come back later else -- get your data data = read_lines(datafile) end if
Note, unless you've got a huge data file to write from the C program, then the chances of the eu program encountering the lock file are low. The other danger of course is that the C program starts to write a new datafile before the eu program has finished reading it - you could always write another don't write anything lock file from the eu program, to be checked by the C program before it starts writing.
Chris