Use the Nice command to adjust the process priority level

Source: Internet
Author: User

Adjusting Process priority with nice

When Linux processes is started, they is started with a specific priority. By default, all regular processes is equal and was started with the same priority, which is the priority number 20. In some cases, it's useful to a change of the default priority which was assigned to the process when it was started. You can do this using the nice and Renice commands. Use the nice if you want to start a process with the adjusted priority. Use Renice to change the priority for a currently active process. Alternatively, you can use the R command from the top utility to change the priority of a currently running process.

Changing process priority could make sense in different scenarios. Suppose, for example, that's about-to-start a backup job that does not necessarily has to finish fast. Typically, backup jobs was rather resource intensive, so you might want to start it in a-a-do-it-not-annoying other Users too much, by lowering it priority.

Another example is the where you were about to start a very important calculation job. To ensure that it's handled as fast as possible, you might want to give it a increased priority, taking away CPU time fr Om other processes.

On earlier Linux versions, it could is dangerous to increase the priority of one job too much, because other processes (in cluding vital kernel processes) might risk being blocked out completely. On current Linux kernels, the situation are not so urgent anymore:

Modern Linux kernels differentiate between essential kernel threads that is started as real-time processes and normal u Ser processes. Increasing the priority of a user process would never be able to block out kernel threads or other processes that were star Ted as real-time processes.

Modern computers often has multiple CPU cores. A Single threaded process This is running with the highest priority would never be able to get beyond the boundaries of the CPU it is running on.

When using the nice or renice-to-adjust process priority, you can select from the values ranging from-20 to 19. The default niceness of a process is set to 0 (which results in the priority value of 20). By applying a negative niceness, you increase the priority. Use a positive niceness to decrease. It's a good idea does not use the ultimate values immediately. Instead, use increments of 5 and see how it affects the application.

TIP Don't set process priority to-20; It risks blocking other processes from getting served.


Let's take a look at examples's and renice. The command nice-n 5 dd If=/dev/zero of=/dev/null & starts an infinite i/o-intensive job, but with a adjust Ed niceness So, some place remains for other processes as well. To adjust the niceness of a currently running process, you need the PID of this process. The following-commands show how PS aux was used to find the PID of the DD job from the previous example. Next, you see how the Renice command was used to change the niceness of this command:

5 if=/dev/zero of=/dev/null &[12872[email protected] tmp]# jobs [1]+  Running                 5if=/dev/zero of=/dev/null &

1. Use PS aux | grep dd to find the PID of the DD command that you just started. The PID is in the second column of the command output.

[[Email protected] tmp]# PS aux |grep ddroot2  0.0  0.0      0     0? S Jun270:xx[Kthreadd]root +  0.0  0.0      0     0? s< Jun270:xx[Ipv6_addrconf]dbus618  0.0  0.0  34948  1856? SSL Jun270:xx/bin/dbus-daemon--system--address=systemd:--nofork--nopidfile--systemd-Activationroot2872 99.9  0.0 107936   620pts/1RnGeneva: at   2:Panax NotoginsengDdif=/dev/zero of=/dev/NULLRoot2883  0.0  0.0 112644   956pts/1r+Geneva: -   0:xxgrep--color=auto DD

2. use renice-n 10-p 1234 (assuming that 1234 are the PID you just found).
Note that regular users can is decrease the priority of a running process. You must is root to give processes increased.

Ten 2872 2872 5 New Ten

Use the Nice command to adjust the process priority level

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.