In C, append to file open for read by another program on Windows console and Linux -
i have 2 different c programs running on same machine. first program, called filereader, opens file reading, , keeps open. periodically, want program, fileappender, open file using "a" (append) mode, append data, , close file.
but don't want filereader close file whenever fileappender needs append data.
my questions: first, can done @ all, , if so, can done in portable, reliable way both windows console program , linux? reason i'm asking "reliable" because afraid in testing may work, not reliably.
second, if can done, portability- , reliability-wise, how can filereader program know if data has been appended? 1 thought had fseek eof, worry situation fileappender still in process of writing data file.
the linux/unix -tail command described in comments not exist windows, yes, there several ways without command. here 1 have used, should work cross-platform:
first recognize describing shared (file system) resource, can accessed 1 process @ 1 time. 2 (or more) applications need kind of semaphore (signalling) method signal current state of target file checking existence of another. have used token file this, , has worked me. token file file unique name indicates permission access target file, where target file is file being edited more 1 process. token file can checked processes (applications) existence. if token exists, target file busy, , should not accessed. if token not exist, create it, access target file. close token when done appending target.
simple concept flow:
process 1 while(token exists) { //sleep(20) } create token open target file append write target file close target file close token process 2 while(token exists) { //sleep(20) } create token open target file append write target file close target file close token
Comments
Post a Comment