如何在 Linux 系统上以编程方式清除 C++ 中的文件系统内存缓存? [英] How to programmatically clear the filesystem memory cache in C++ on a Linux system?
本文介绍了如何在 Linux 系统上以编程方式清除 C++ 中的文件系统内存缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用 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++?
感谢任何帮助!
推荐答案
写信给它:
sync();
std::ofstream ofs("/proc/sys/vm/drop_caches");
ofs << "3" << std::endl;
这篇关于如何在 Linux 系统上以编程方式清除 C++ 中的文件系统内存缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文