Edit : Fork and exec no longer work, since OSX cannot really fork correctly. Single thread magic:
setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE); system("nice -n 20 /usr/bin/purge"); setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_DEFAULT);
It can be anywhere, in the sending unit, if you want, or anywhere in the application. No fork in sight. Also, feel free to replace system with NSTask if you want to stay ObjCish.
How about the old old fork n exec :
#include <unistd.h> #include <sys/resource.h>
and
if(fork()) { setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE); execl("nice", "-n", "20", "/usr/bin/purge"); }
Letโs go through this:
I / O priority is inherited, and the nice part sets a good value.
source share