Are you talking about committing the buffer cache to disk, as when you would simply type
in a terminal window?
If so, you would more likely want to use either the
sync() function or the
syncfs() function (see the manual page,
man 2 sync, for details):
Quote:
DESCRIPTION
sync() causes all buffered modifications to file metadata and data to be written to
the underlying file systems.
syncfs() is like sync(), but synchronizes just the file system containing file
referred to by the open file descriptor fd.
|
Both functions are part of
glibc, the
sync() function is pretty much universal (it's found in UNIX and Linux systems), the
syncfs() function is Linux-specific.
I would think that calling
sync() would probably be your better choice; it's usually a good idea to use the library functions rather than the low-level functions/macros such as
sys_sync because the library functions are written to invoke the low-level call with appropriate arguments and you'll usually be more successful that way.
Simply typing
sync at a command prompt you'll probably notice that it takes a while to execute (the system buffers are being written to disk). I would write a little C program that simply calls
sync() and see if it either takes a while or returns immediately -- if it takes a while, you're good to go but if the program exits immediately that means that the
sync() is forked and exec'd and you would want to include a few seconds of sleep after the call to allow the buffers to be flushed to disk(s).
Something like this will give you an idea
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
void main (int argc, char *argv [])
{
time_t t0 = (time_t) 0; /* start time */
time_t t1 = (time_t) 0; /* finish time */
/* get a start time */
if (time (&t0) < (time_t) 0)
(void) fprintf (stderr,
"%s:\tcan't read system clock\n", argv [0]);
/* call the sync() library function */
sync();
/* get a finish time */
if (time (&t1) < (time_t) 0)
(void) fprintf (stderr,
"%s:\tcan't read system clock\n", argv [0]);
(void) fprintf (stderr,
"%s duration %g seconds\n",
argv [0], difftime (t1, t0));
exit (EXIT_SUCCESS);
}
Hope this helps some.