如何以编程方式清除C中的文件系统内存缓存++在Linux系统上?
问题描述:
我写C ++中的基准测试工具,我想清楚了实验之间的文件系统内存缓存。我知道下面的控制台命令:
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
我的问题是如何才能做到这一点编程直接在C ++?
My question is how can i do this programmatically directly within C++?
任何帮助AP preciated!
Any help is appreciated!
答
刚写它:
sync();
std::ofstream ofs("/proc/sys/vm/drop_caches");
ofs << "3" << std::endl;