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

25 Awesome iPhone App Icon Packs to Customize Your Home Screen

With the release of iOS 14, Apple made it possible to customize the app icons on your iPhone's Home Screen without worrying about duplicates. Of course, most of us aren't graphic designers, so we need to rely on iOS app icon packs made by other people to change the look of our Home Screen. We've scoured the web to find the coolest, most unique, and best-designed iOS app icon packs for you to download. Before You Customize Your iOS App Icons There are a few important points you need to know before you customize the app icons on your iPhone Home Screen: It's time-consuming: For every app icon you want to change, you need to create a new shortcut in the Shortcuts app, then add it to your Home Screen and hide the original app. If you have a lot of apps, this could take hours. Custom icons don't show notification badges: Customized app icons act as a shortcut to the original app. For this reason, they don't show red notification badges like normal apps. The o...

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...

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...