Making Processes Nice


Making Processes "Nice"

The kill command is one of the process-management tools that you can use both from the command line and within top. You read earlier of another tool, though, that you can use to alter a process's scheduling priority. This tool is the renice command, which alters the priority (or "nice" level) of any currently running process.

The scheduling priority is an integer value between -20 and 20, with -20 being the highest possible priority (confusingly enough). Take a look at top; the values in the NICE column are the priorities of each process. Notice that most processes have a priority of 0. Zero priority is the default because, in most circumstances, you don't need to specify any particular priority. Still, certain services run at predefined "nice" levels to ensure they will run at a certain time or get out of the way of more important processes.

If you're not root, you can set a process to a lower priority (a higher "nice" value), but not to a higher one (a lower "nice" value).

From the command line, you can alter a process's priority to 10 using renice:

# renice 10 1442


Within top, you can press R to get the renice prompt. Enter a priority level between -20 and 20, followed by the PID of the process you want to change, and you can see the results in the NICE column. This is an easy, interactive, alternate solution to the problem caused by the testprog problem you saw earlier. Rather than killing the runaway process outright, you could simply set its priority to 20, which would theoretically make it back off and allow other processes to run uncontested.

The nice command (which is a program in /usr/bin, but also a built-in shell command in the csh/tcsh shell) provides a way to set the priority level of a process at the time you run it. You precede a command with nice and the priority level, like so:

# nice -10 ls


This starts the ls process with a priority level of 10.

Note

The priority level in the nice command is preceded by a dash, which means that positive (lower) priorities are specified as shown in the previous renice example. However, to specify a negative (higher) priority, you would have to use the following:

# nice --10 top


Unfortunately, though, the double-dash syntax only works in the /usr/bin/nice command, and not in the nice command built into csh/tcsh (which supersedes the system's nice). If you're using bash, the preceding syntax will work; but if you're using csh, you need to use the command /usr/bin/nice --10 top to achieve the effect described here.





FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net