Teams nice
and renice
allow you to fine-tune how the kernel treats your processes by adjusting their priorities. Read this guide to learn how to use them on Linux and Unix-like operating systems such as macOS.
It’s all in the process
Inside your Linux or Unix-like computer, there will be many processes running even before you launch the application you want to use. Most of these processes are vital elements of Linux itself, or support processes for your graphical desktop environment. There’s a lot going on behind the scenes. Of course, there are only so many system resources and CPU time. The Linux kernel is the controller for all these processes.
It is up to the kernel to decide which processes are getting attention and resources now, and which are to wait. The kernel constantly manipulates processes and priorities to ensure that the computer runs as smoothly as possible and that all processes get their fair share. Some processes receive preferential treatment. They are so important to the overall operation of your computer that their needs must come before, say, your browser.
Good Value
One of the criteria used to determine how the kernel handles a process is a nice value. Each process has a pleasant value. A good value is an integer in the range -19 to 20. All standard processes start with a good value of zero.
The trick is that the higher the nice value, the nicer your process is in relation to others processes. In other words, a high nice value tells the kernel that this process is happy to wait. A negative number is the opposite of being good. The more negative the value, the more selfish this process. It tries to get as much CPU time as possible without paying attention to other processes.
We can use the command nice
for installations nice values when the process starts and we can use renice
for settings the nice value of the running process.
Good team
We can use the command nice
to set the nice value for the program when it starts. This allows us to increase or decrease the priority given to a process by the kernel over other processes.
Let’s assume that a programmer has written a program called ackermann
. This computes the Ackermann functions. It’s processor and memory intensive. The programmer can run the program with the following command:
./ackermann
We can use the command top
to view a running program.
верх
We can see program details ackermann
in top
. A good value is the number in the «NI column». It’s set to zero, as you’d expect.
Let’s restart it and make it less demanding this time We will set a good value of 15 for the program ackermann
in the following way. Type nice, a space, -15, another space, and then the name of the program you want to run. In our example, our fictional programmer uses ./ackermann
.