linux系统长时间运行,caches会越来越少,需要定时释放
//半夜释放缓存
static void freeCaches() {
time_t timer = time(NULL);
struct tm *localtm = localtime(&timer);
//[00:00:00 - 00:00:15]执行
if ((0 == localtm->tm_hour) && (localtm->tm_min < 1) &&
(localtm->tm_sec < 15)) {
char cmd[100];
sprintf(cmd,
"echo 123456 | sudo -S sh -c 'echo 3 > /proc/sys/vm/drop_caches'");
printf("\ncmd=%s\n", cmd);
system(cmd);
}
}