Play nice with others — Linux Tip #4


If you need to run a process that will take a lot of cpu resources and has to run for a long time, it is nice to run it using the program nice.

In a nutshell, nice will run your process but allow it to be bumped by more important processes. For example if you run

nice watch ls -l

then ls will be run at a niceness of 10. Then if you look in top you will see

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 8986 eric      16   0  127m  71m  13m S  2.0 14.6   2:40.43 mono
28492 eric      26  10  3132 1004  748 S  1.0  0.2   0:00.02 watch

So now if the other process here (mono) needs to take more CPU time, the watch command will give it up until mono is done. Notice how top also reports the nice-ness of each process (NI).

Good processes to run under nice are backups, compiles, or any other batch processes.

See also man 1 nice

Eric Davis