0

Bash shell on Ubuntu laptop

The nice and renice commands let you fine-tune how the kernel treats your processes by adjusting their priorities. Read this tutorial to learn how to use them in Linux and Unix-like operating systems such as macOS.

It’s All a Matter of Process

Inside your Linux or Unix-like computer, there will be many processes running even before you launch the application you want to use. The majority of these processes are vital elements of Linux itself or supporting 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 to go around. The Linux kernel is the controller for all of these processes.

It is the kernel that has to decide which processes get attention and resources right now, and which ones have to wait. The kernel is continually juggling processes and priorities to ensure that the computer runs as smoothly as it can and that all processes get their appropriate share. Some processes get preferential treatment. They are so important to the general operation of the computer that their needs have to come first ahead of, say, your browser.

The nice Value

One of the criteria used to determine how the kernel treats a process is the nice value. Every process has a nice value. The nice value is an integer in the range of -19 to 20. All standard processes are launched with a nice value of zero.

The trick here is that the higher the nice value, the nicer your process is being to the other 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 nice. The larger the negative nice value, the more selfish the process is. It is trying to get as much CPU time as it can, with no regard for the other processes.

We can use the nice command to set the nice value when a process is launched and we can use renice to adjust the nice value of a running process.

The nice Command

We can use the nice command to adjust the nice value for a program as we launch it. This allows us to increase or decrease the priority given to the process by the kernel, relative to the other processes.

Let’s suppose a programmer has written a program called ackermann . This calculates Ackerman functions. It is CPU and memory intensive. The programmer can launch the program with the following command:

./ackermann

Read the remaining 24 paragraphs


Post a Comment Blogger

We welcome comments that add value to the discussion. We attempt to block comments that use offensive language or appear to be spam, and our editors frequently review the comments to ensure they are appropriate. As the comments are written and submitted by visitors of The Sheen Blog, they in no way represent the opinion of The Sheen Blog. Let's work together to keep the conversation civil.

 
Top