Quote:
Originally Posted by jim mcnamara
You want: each new line as it appears in the file, the full line, correct?
When a C program calls fwrite() or even write, the data is stored in the kernel, not the file. The device I/O happens whenever the kernel decides to do it or is asked to do it.
The kernel also writes data is chunks, not in lines. The chunk wirtten is usually in the size of a disk block or one of some parameters (seen in stdio.h) like BUFSIZ or _DBUFSIZ. This is called a delayed write. It occurs when the kernel needs to reuse the buffer(s).
This is probably a bad suggestion... but... sync() queues a kernel dump of everything to disk that it has in cache - for all processes. It may have negative performance
implications, except in Linux where sync() is called by fflush() and fdatasync() as well.
Also I do not know if sync() exists for every flavor of unix. I do know that sync is the function called by the update daemon on systems I do know something about.
It sounds to me more like you have a management problem than a coding one. Get your manager to make the other coder add fflush() calls to his file I/O routine(s).
This means that the process doing the writing MUST cooperate to the extent that it calls fflush() on the stream after every fwrite / fputs call.
There is a difference in issuing fwrite (from I/O library) and just write call.
fwrite would take char * to the I/O buffer
and write would take char * to the kernel buffer directly
Only when the internal buffer (I/O buffer) private to the process is fillled the data (DISK_BLOCK_SIZE) is taken to the kernel buffer by a write system call initiated by the fwrite I/O library. (other specific conditions also include ... )
i have seen several codes using fwrite and explicitly issuing fflush after each fwrite. There is no need of such fflush after each fwrite
Flushing from a kernel buffer to the ultimate disk is the decision made by the kernel itself.
We can easily identify the difference (throughput) between using fwrite and write system call.
For small buffer size,
fwrite would be the optimal one and
for buffer size considerably larger its equivalent to issuing write after every fwrite system call hence throughput would come down.