This course will focus on the Linux command line and the text-manipulation tools that let you effectively control just about anything on your system. We'll learn about terminal environments, working with text streams, file management and archives, system processes, advanced text searches, and terminal text editors.
If you have thoughts or suggestions for this course, please contact Cloud Academy at email@example.com.
Anytime you've got more than one process running on a system there's a risk that competition for finite resources might cause trouble. Because default priorities don't always work for every configuration, an operating system needs a tool that allows administrators to edit the priority scheduler.
Using nice to manage multiple processes
In Linux, that tool is called "nice." To make it a bit easier to see this actually working, using screen, I've opened two terminals. Running "top" in the upper terminal you can see that every process has a priority number under the PR column and under the NI column a nice value. By default, every process has a nice value of 0 and a PR value of 20. You can change a processes nice value to make it as high as 19, which would raise the PR to 39 or as low as minus 20, 19 or really, really nice would lower the priority of a process to the point that the needs of all other processes would take precedence. In other words, our process is being nice to everyone else.
Lowering its nice value to minus 20, will give a process a very high priority in the competition for system resources or in other words it's not being very nice to other processes at all. If you're launching a process, you can manually set the value through nice.
Let's say that you want to download a package using apt-get but you don't want it to take too many CPU cycles away from other programs that you've got going. You might launch the process through "nice" like this. You can see that the process being run by root has a nice value of 10. Note by the way that the minus 10 I used here is not negative 10 but -10. If you wanted to lower the nice value to say minus 10 I would do it with two dashes the first being a dash and the second the minus sign.
For processes that are already running, you can edit the nice value using "re-nice." Looking at "top" we can see the SSHD process is currently running with a nice value of 0. If I'd like to change that to minus 10 or to make it less nice I would note the process ID and in any other terminal run "re-nice minus 10-p" for process and the process ID. See how within a second or two the SSHD's nice value changes. Re-nice doesn't take a dash as part of the syntax so a single dash would in fact mean the minus sign. Don't blame me for all of this. I didn't come up with these rules. I just have to learn to live with them just like you.
Besides "top" you can also use "ps" to view all processes nice values using the "-elf" switch. You can also of course "grep" for a particular program or PID. Not only will nice and re-nice control the priority given to an individual process but they can also be used to control all processes launched by particular users or groups. To raise the nice level of the user Ubuntu to 10 use re-nice followed by "-u" and the user name. To lower the nice value of a group use "-g" and then the name of the group. Let's review. A really nice process can have a value as high as 19. While a nasty, un-nice process can be selfish and go as low as minus 20. Launching a new process to control its nice value can be done using the nice program. Adjusting the nice value of a running process is done using "re-nice." You can edit nice values for users and groups and view nice values using either "top" or "ps."
David taught high school for twenty years, worked as a Linux system administrator for five years, and has been writing since he could hold a crayon between his fingers. His childhood bedroom wall has since been repainted.
Having worked directly with all kinds of technology, David derives great pleasure from completing projects that draw on as many tools from his toolkit as possible.
Besides being a Linux system administrator with a strong focus on virtualization and security tools, David writes technical documentation and user guides, and creates technology training videos.
His favorite technology tool is the one that should be just about ready for release tomorrow. Or Thursday.