I'm writing a benchmark tool in C++ where I want to clear the filesystem memory cache between experiments. I'm aware of the following console commands:
sync
echo 3 > /proc/sys/vm/drop_caches
My question is how can i do this programmatically directly within C++?
Any help is appreciated!
In all the Linux systems we have three options to clear cache without interrupting any services or processes. Now to set run permission, to clear ram cache, you have to call the script whenever required, setting a cron to clear RAM caches every day for 3 hours.
Just write to it :
sync();
std::ofstream ofs("/proc/sys/vm/drop_caches");
ofs << "3" << std::endl;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With