Skip Navigation
 Search | Directories | Reference Tools
UW Home > Discover UW > IT Connect > Unix 

Using 'nice' to Sequentially Execute Jobs

Because the Unix resources are shared among a great number of people, each user should be responsible for using those resources in a way that minimizes possible detrimental effects on the system as a whole. The `nice' feature will aid you in being a considerate user.

You should only run one background job at a time. If you must run several jobs in the background, run them sequentially, not simultaneously. It would be appropriate to do this if you were going to go away for a while. When you run several jobs in the background sequentially, you can `nice' them, as shown in the example below. (The syntax is somewhat convoluted.)

     (nice +17 vtroff file1; nice +17 vtroff file2; nice +17
     vtroff file3) &

The parentheses must be used. Unfortunately, you can't put one nice in front of the parentheses to take care of all the files. Another way to handle this situation would be to run the three vtroff's at 3 a.m. (or some other time when the system is not busy). To do so, make an executable file with the following lines in it (if you are uncertain how to make a file executable, see `man chmod'):

     nice +17 vtroff file1
     nice +13 vtroff file2
     nice +18 vtroff file3

If, for example, you named the file `mytroffs,' then the command

     at 3am mytroffs

would cause the jobs to be run at 3 in the morning. For detailed information about the `at' command enter

     man at

If you have a pipe with several commands and want all the commands `niced,' you must put a `nice' in front of each command. To run nice vtroff's with pre- processors, be sure to nice the vtroff. The vtroff is the heavy machine cycle user. An appropriate command line might look like:

     tbl file1 file2 | eqn | nice +18 vtroff -me &

Something like that would also be necessary in an `at' command file, though you wouldn't put the ampersand in. If the following three lines were in a file called `mytroffs'

     eqn file1 | tbl | nice +18 vtroff -me
     eqn file2 | tbl | nice +18 vtroff -me
     eqn file3 | tbl | nice +18 vtroff -me

`at 3am mytroffs' would run these three jobs sequentially with niced vtroff's.

Although vtroff is used for the examples here, you should be aware that the above discussion applies to all non-interactive commands, not just to vtroff.