Quote:
Originally Posted by bigearsbilly
As the EOF pointer is the same for each fork'd file descriptor, and each
is updated (I think atomically) with an append.
|
If you open the file in append mode (also requires reading mode,) all output will be written to the end regardless of how many processes are writing to the file. Without the append flag, though, that's not guaranteed.
Do the line pairs have to stay together in the file? If so, you should either use a file lock or switch the output buffer mode to "fully-buffered" with
setvbuf and flush the buffer after outputting each pair of lines. Write operations are implicitly locking (in other words, they lock out writing by other processes,) so if output is fully-buffered then all output is written at once when you flush the buffer. It will probably be line-buffered by default, which means it will write every time a newline is output, allowing for the remote possibility of line pairs not showing up together.
Keep in mind that file locks aren't mandatory unless the file system is mounted with the
mand option (for mandatory locks) and the file has certain flags set (setgid without group-execute.) You can't count on that, so your processes all need to honor a mutex-style locking system. I'd use
fcntl to remain Unix-portable for file locks if you're going to use them.
ta0kira