Sounds like you want the sync command, or the sync() function.
If you want disk cache flushing: echo 3 | sudo tee /proc/sys/vm/drop_caches
Sounds like you want the sync command, or the sync() function.
If you want disk cache flushing: echo 3 | sudo tee /proc/sys/vm/drop_caches