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 Best 10 Social Media Platforms for Photographers to Flaunt Their Talent

Social media offers an excellent opportunity for photographers to connect with potential clients. In the digital era, it's a great asset. By showcasing your work on these networks, you can reach new audiences. Whether you are a professional or freelance photographer, the following social platforms will help you show off your work and get the right people to take notice... 1. Behance Behance is a classic portfolio publishing network that functions like a LinkedIn for creatives. Designed by Adobe, this is one of the best photography networking sites currently out there. The platform is ideal for sharing your portfolio and favorite images, allowing other Behance users to like and comment on your photos. By learning from their feedback and professional critiques, you can improve your work. The coolest feature of Behance is that it lets you find professional gig opportunities right on the platform. With your portfolio already available on the site, getting work becomes effortless.

The 6 Best Platforms for Sharing Your Digital Art Online

Whether you're looking for somewhere to host your digital art portfolio or simply want to share your latest artworks, it can be difficult to choose a website to upload to. Or at least, it definitely is more so than before, now that art websites aren't bubbling with as much excitement as they used to be. You know that each site has its pros and cons, but it's hard to figure out what those are unless you make an account and see for yourself. Don't worry if you don't have time for that—we've got your back. Here are the websites we recommend for sharing digital art, and why you might want to consider them. 1. Pixiv If you were around when the online art scene was ridiculously active, chances are that your art style is influenced by anime and/or manga in some way. Otaku culture began its slow sneak into mainstream media back then, and Pixiv is a great home for artists that fall in that category. Pixiv started as a small online community based in Japan, but has s

Snapchat Suspends Two Anonymous Messaging Apps Over Cyberbullying Claims

In light of a lawsuit that was filed earlier, two Snapchat apps, Yolo and LMK have been suspended by Snap. The apps allowed users to send anonymous messages on the platform. The Lawsuit Calls for an Immediate Ban of Yolo and LMK According to a LA Times report, the lawsuit was filed on behalf of Kristin Bride, the mother of a teen who committed suicide in 2020. The lawsuit alleges that Bride's son took his own life after being cyberbullied via Yolo and LMK. In addition to this, the lawsuit alleges that Yolo and LMK aren't doing enough to tackle cyberbullying, and have consequently violated consumer protection law as well as their own terms of service and policies. Both apps use Snap Kit, a set of tools that allows developers to directly connect to Snapchat for better integration features. Today the family of a 16-year-old Oregon boy who took his own life after being cyberbullied sued Snap and the makers of apps YOLO and LMK, alleging that the companies should be "h