Fatmawati Ahmad Zaenuri / Shutterstock.com

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 command in terminal window

We can use the command top to view a running program.


top works in terminal

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 .

  хороший -15 ./ackermann 

good command 15 in terminal window

Note «-15» is not negative fifteen. This is a positive fifteen. «-» is required to say that we are passing a parameter. To specify a negative number, you must enter two «-» characters.

If we now start again with top we will see a change in behavior ackermann .


top works in terminal

With a good value of 15, ackermann does not consume most of the CPU time. GNOME and Rhythmbox use more. We are a little ackermann .

Now let’s do the opposite and ackermann negative nice value. Note the use of two «-» characters. To make the app more selfish and less nice you should use sudo . Anyone can make their app nicer, but only superusers can make another selfish one.

  sudo nice --10 ./ackermann 

good command -10 in terminal window

Let’s run and see what it has changed.


top works in terminal

This time ackermann has a good value of -10. He returned to the top line and consumes more CPU time than before.

Team Renice

Team renice allows us to set a nice value for a running process. We don’t need to stop it and restart from nice . We can set a new value on the fly.

Team renice accepts a process id or process PID as a command line parameter. We can either extract the process id from the «PID» column top or use ps and grep to find it for us as follows. Obviously you will be entering your username instead of dave and the name of the process you are interested in instead of ackermann .

  ps -eu dave |  Grep Ackermann 

ps via grep in a terminal window

Now that we have a PID, we can use this with renice . We ackermann to more ackermann behavior with a good value five. To change the nice value for a running process you should use sudo . Please note that in the parameter 5 No «-«. You don’t need one for positive numbers, and you only need one, not two, for negative numbers.

  sudo renice -n 5 2339 

renice command works in terminal window

We receive confirmation that the cost renice has changed. This shows us the old value and the new value.

The kernel is usually very good at handling priorities and allocating CPU time and system resources. But if you have a long task that requires a lot of CPU resources and you don’t care when it finishes, your computer will run a little smoother if you set the task to a higher value. It will be better for everyone.

Похожие записи