java怎么编写 sync; echo 1 > /proc/sys/vm/drop_caches 执行Linux清除缓存命令

想手动清除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系统的缓存。
        
        要怎么才能真正实现清除缓存呢?
阅读 3.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题