Controlling Job Priority with nice

Controlling Job Priority with nice

Code Listing 9.9. By using nice plus an adjustment, you can let Unix determine how hard to work on your job.

[ejr@hobbes ejr]$ nice -n 19 slowscript 

Suppose you need an enormous file from the Internet that would take practically all afternoon to download. By downloading it, you would hog system resources and make the system response time much slower for other users. OK, bad example. Suppose your coworker needs to download an enormous file and would hog system resources all afternoon. You'd hope that she'd have the courtesy to not tie up system resources that you need to use.

Fortunately, she can, using nice, which lets her control job priority. As Code Listing 9.9 shows, you rank your job's priority using numbers from 1 to 19, with 1 being somewhat nice (higher priority) and 19 being fabulously nice (lower priority). The Unix system uses the number you provide to determine how much attention to devote to the job.

To Control Job Order with nice:

  • nice -n 19 slowscript

    At the shell prompt, type nice, followed by the appropriate adjustment (19, here), and the name of the program or script to run (Code Listing 9.9). In this example, slowscript is run with the lowest priority possible.


  • To find out how nice you need to be, you might check out how many processes(and which kinds) are currently running on the Unix system. You can do this using ps, as described later in this chapter.

  • You could use nice and run a job in the backgroundfor example, use nice -n 12 funscript & to run funscript in the background with a niceness level of 12.

  • You can just type nice plus the job name (as in nice sortaslow). Doing so will automatically specify 10 as the niceness level (the default setting).

  • If you are the system administrator and logged in as root, you can use negative numbers (down to 20) with nice to increase the priority (nice -n -16 priorityjob).

  • Use renice to change the niceness of a running job. For example, use renice -n 18 2958 (the job number). If you're the system administrator, you can increase or decrease the niceness of any job; if you're a peonwhoops, we mean a regular computer user at your companyyou can only decrease the priority of your own jobs, not increase it. In a pinch, you could ask your system administrator to increase the priority of your job.

Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: