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
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.
source https://www.makeuseof.com/change-processs-priority-linux-nice-renice/
Post a Comment for "How to Change Process Priority in Linux With nice and renice"
Comment when there are difficulties