clear buffer cache on Mac OS X

前端 未结 5 1199
挽巷
挽巷 2020-12-30 04:46

Is there a way to programatically clear the buffer cache on the Mac, preferrably in C?

Basically, I\'m looking for the equivalent of the source of 10.5 (and greater)

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 05:00

    Wouldn't you be interested in turning off the cache for a file instead? Depending on what you are trying to achieve, it could be an alternative. Good summary here.

    UBC can be cleared by running 'purge' which allocates a lot of memory to force the cache to clear.

    fcntl(fd, F_GLOBAL_NOCACHE, 1)  
    

    can be used turn caching off for a particular file. This can be done in any process and the file can be closed after.

提交回复
热议问题