ANL Physics computing, hints and kinks, nice

The utility, nice, allows you to run your programs at lower than interactive priority. Say you are running a job called 'sort' and you want it to run so that it only takes cpu time when the computer has nothing else to do. If you are running the csh or tcsh shell, you would start the job by:
     nice 19 sort &
19 is the nicest you can ever be. The "&" at the end will put the job in the background. There are unfortunately two different versions of this program. The one you execute depends on the shell you are running.

Here comes the weird part: to be nice and run in the background you should say:

    case: csh or tcsh shells:

            nice 19 ....

    case: sh or from a script:

            nice -19 ....

There is a possibility for confusion here!

Most script files are running the /bin/sh shell even when started from the csh or tcsh shells (unless you have - #!/bin/csh - in the first line of your script) so we have the strange situation that if you start 'sort' from inside a script, you would use "nice -19 ..." to run low priority. However, if you start it directly from the csh or tcsh shell you would use "nice 19 ..."

Another alternative is to always say "/usr/bin/nice" rather than just "nice". This guarantees that you always use the sh version and you would not have to remember the above cases. In the first example on the page you would say:

     /usr/bin/nice -19 sort &
and that would work the same from scripts as well as any shells you may use.

... isn't UNIX just fun???