想手动清除linux系统的缓存,调用Process来执行:
//sync; echo 1 > /proc/sys/vm/drop_caches
ProcessBuilder pb0 = new ProcessBuilder("sync",";","echo","1",">","/proc/sys/vm/drop_caches");
try {
Process ps0 = pb0.start();//Starting a new process.
InputStream is = ps0.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
while( (line = br.readLine())!=null){
System.out.println(line);
}
ps0.waitFor();//Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.
ps0.destroy();//Kills the subprocess.
} catch (Exception e) {
e.printStackTrace();
}
可发现运行起来,通过free -m来查看,并没有真正的清除linux系统的缓存。
要怎么才能真正实现清除缓存呢?