Skip to main content

How to Change Process Priority in Linux With nice and renice

Linux lets you run lots of processes on one machine without skipping a beat. Sometimes, an intensive process can slow your system down. Wouldn't it be great if there was a way you could somehow put it on the back burner when you keep going with other tasks? You can, with a utility called nice.

Playing nice With Processes

Nice is a utility built into Linux and Unix systems that can reduce the CPU priority of a process. This utility is an artifact of the era when Unix ran on multiuser minicomputers and mainframes, but it's still useful today running on single-user desktops.

You might be playing a game and experiencing lag because of some intensive process that you know will take a long time to get the output, like a torrent client. Just reassign it to the background and keep playing.

Nice is either a standalone program or built into the shell. To figure out which is the case on your system, type:

which nice

On Ubuntu, the version of nice installed is the GNU version.

Nice uses the concept of a "nice number," which is the process priority of any process. On the GNU version, it ranges from 19 to -20. The negative numbers give more priority to the process, while positive numbers give less. You can see this nice number as the NI column in utilities like top or htop.

To run a process with lower priority, use this command:

nice processname

Replace processname with the process you want to run. By default, nice will assign the nice number of 10. Any processes started normally will default to 0.

If you want a specific number, in this case, the absolute minimum priority, use the -n option with the nice number you want:

nice -n 19 processname

Changing Process Priority With renice

Now you can start commands with a reduced priority, but what about changing the priority of running processes? You can do that too with another utility, renice.

You'll need the PID, or Process ID, of the process you want to change. You can find that by using the ps command, top, or htop. Once you've found that, you just need to feed it to the renice command.

To set a new nice number for your PID, type:

renice priority PID

...where priority is the nice number you want to use.

The -n flag changes the process priority by the increment you mentioned, either positive or negative, so if you had a process that was at 10 and you wanted to change it to 8, type:

sudo renice -n -2 PID

Only the superuser can renice processes that belong to another user or increase a process's priority. You can use the -u switch followed by the username to adjust priority for any user:

renice priority -u username

Related: What is a Process in Linux?

Now You Can Change Process Priorities for the Best Performance

With nice and renice, you can change any process's priority in Linux. This will surely help you in times when a heavy process is eating up a huge chunk of your system resources. Also, optimizing your system performance with monitoring tools like Stacer can be helpful.

Comments

Popular posts from this blog

The 9 Different Types of NFTs

Jack Dorsey, the creator of Twitter, sold the world's first tweet for $2.9 million; this bit of news is what introduced most people to the world of NFTs (Non-Fungible Tokens). Now all the rage, NFTs are being bought and sold like priceless pieces of art. The NFT market is seemingly swarming with digital Mona Lisas, but the question is: besides tweets and pictures, what other types of NFTs are there in the wild? Let's take a dive into the world of NFTs and find that answer. First Off: What Are NFTs? Digital media can be replicated easily and redistributed; however, try making an honest-to-goodness copy of the Mona Lisa down to the brush strokes and the original paper. Think of NFTs as digital non-replicable pieces of art. These are properties that can not be copied or replaced at all. Sure, the media itself can be copied and posted to a person's social media, but the buyer will retain ownership of the NFT, regardless. Hitting Ctrl + C on an NFT and posting it is the equi...

64 Best Free WordPress Blog Themes for 2020

Are you looking for a free WordPress blog theme for your website? There are thousands of free blog themes for WordPress, making it hard for beginners to choose between all the different options. The best WordPress themes can be tough to find. Your free theme needs to be reliable and easily customizable. In this article, we have hand-picked some of the best free WordPress blog themes that you can use on your site. Getting Started with WordPress First, you need to make sure that you are using the best blogging platform . Self-hosted WordPress.org is the perfect platform to start your blog because it gives you lots of freedom, flexibility, and control. We have a useful guide on the difference between WordPress.org and WordPress.com . WordPress.org is open source. It comes with support for thousands of free templates (called themes) and extensions (called plugins) that help you grow your blog faster. Take a look at our article on why you should use WordPress to learn more. You can...

The 7 Best Wired Headphones

Premium pick Sony WH1000XM4/B Over-Ear Headphones See On Amazon Brand Sony Battery Life 30 hours Material Synthetic leather Editors choice PeohZarr On-Ear Headphones See On Amazon Brand PeohZarr Material Synthetic leather Bluetooth No Best value Vogek On-Ear Headphones See On Amazon Brand Vogek Material Protein leather Bluetooth No Grado SR80e Prestige See On Amazon Brand Grado Battery Life N/A Material Leather Sony MDR-XB50AP Extra Bass See On Amazon Brand Sony Bluetooth No Additional Tips Yes Summary List 9.20 /10 1. Premium pick: Sony WH1000XM4/B Over-Ear Headphones 9.00 /10 2. Editors choice: PeohZarr On-Ear Headphones 9.00 /10 3. Best value: Vogek On-Ear Headphones 9.00 /10 4. Grado SR80e Prestige 9.00 /10 5. Sony MDR-XB50AP Extra Bass 8.60 /10 6. Panasonic ErgoFit 9.20 /10 7. Apple Ear...