One way to write into a file is by using
Sun Grid Engine
You can use the
fflush function after each write to flush the output buffer to disk.
fprintf(fileptr, "writing to file\n"); fflush(fileptr);
If you really want to be sure the file is written to disk, i.e. you want to flush the kernel buffers as well as the userspace buffers, also use
fflush should be sufficient. Don't bother with
fsync unless you find that you need to.