How to Set Priority of a Running Process in Linux

In this article, we’ll briefly explain the kernel scheduler (also known as the process scheduler), and process priority, which are topics beyond the scope of this guide.

Then we will dive into a little bit of Linux process management: see how to run a program or command with modified priority and also change the priority of running Linux processes.

Understanding the Linux Kernel Scheduler

A kernel scheduler is a component of the kernel responsible for selecting the most appropriate process to run next from all the processes that are ready to execute.

It manages the allocation of CPU time among these processes on the system. A process is considered runnable when it is waiting solely for CPU time and is prepared to be executed.

The scheduler forms the core of multitasking in Linux, using a priority-based scheduling algorithm to choose between the runnable processes in the system. It ranks processes based on the most deserving as well as the need for CPU time.

Understanding Process Priority and Nice Value

The kernel stores a great deal of information about processes including process priority which is simply the scheduling priority attached to a process. Processes with a higher priority will be executed before those with a lower priority, while processes with the same priority are scheduled one after the next, repeatedly.

There are a total of 140 priorities and two distinct priority ranges implemented in Linux. The first one is a nice value (niceness) which ranges from -20 (highest priority value) to 19 (lowest priority value) and the default is 0, this is what we will uncover in this guide.

The other is the real-time priority, which ranges from 1 to 99 by default, then 100 to 139 are meant for user-space.

One important characteristic of Linux is dynamic priority-based scheduling, which allows the nice value of processes to be changed (increased or decreased) depending on your needs, as we’ll see later on.

How to Check Nice Value of Linux Processes

To see the nice values of processes, we can use utilities such as ps, top or htop.

To view processes nice value with ps command in user-defined format (here the NI the column shows the niceness of processes).

ps -eo pid,ppid,ni,comm
View Linux Processes Nice Values
View Linux Processes Nice Values

Alternatively, you can use top or htop utilities to view Linux processes’ nice values as shown.

Check Linux Process Nice Values using Top Command
Check Linux Process Nice Values using Top Command
Check Linux Process Nice Values using Htop Command
Check Linux Process Nice Values using Htop Command

Difference Between PR or PRI and NI

From the top and htop outputs above, you’ll notice that there is a column called PR and PRI receptively which shows the priority of a process.

This, therefore, means that:

  • NI – is the nice value, which is a user-space concept, while
  • PR or PRI – is the process’s actual priority, as seen by the Linux kernel.

How To Calculate PR or PRI Values

Total number of priorities = 140
Real time priority range(PR or PRI):  0 to 99 
User space priority range: 100 to 139

Nice value range (NI): -20 to 19

PR = 20 + NI
PR = 20 + (-20 to + 19)
PR = 20 + -20  to 20 + 19
PR = 0 to 39 which is same as 100 to 139.

But if you see a rt rather than a number as shown in the screenshot below, it basically means the process is running under real-time scheduling priority.

Linux rt Process
Linux rt Process

How to Run A Command with a Given Nice Value in Linux

Here, we will look at how to prioritize the CPU usage of a program or command. If you have a very CPU-intensive program or task, but you also understand that it might take a long time to complete, you can set it a high or favorable priority using the nice command.

The syntax is as follows:

nice -n niceness-value [command args] 
nice -niceness-value [command args] 	
nice --adjustment=niceness-value [command args]


  • If no value is provided, nice sets a priority of 10 by default.
  • A command or program run without nice defaults to a priority of zero.
  • Only root can run a command or program with increased or high priority.
  • Normal users can only run a command or program with low priority.

For example, instead of starting a program or command with the default priority, you can start it with a specific priority using the following nice command.

sudo nice -n 5 tar -czf backup.tar.gz ./Documents/*
sudo nice --adjustment=5 tar -czf backup.tar.gz ./Documents/*

You can also use the third method which is a little confusing, especially for negative niceness values.

sudo nice -5 tar -czf backup.tar.gz  ./Documents/*

Change the Scheduling Priority of a Process in Linux

As we mentioned before, Linux allows dynamic priority-based scheduling. Therefore, if a program is already running, you can change its priority with the renice command in this form:

renice -n  -12  -p 1055
renice -n -2  -u apache
Change Process Priority
Change Process Priority

From the sample top output below, the niceness of the teamspe+ with PID 1055 is now -12 and for all processes owned by user apache is -2.

Still using this output, you can see the formula PR = 20 + NI stands,

PR for ts3server = 20 + -12 = 8
PR for apache processes = 20 + -2 = 18
Watch Processes Nice Values
Watch Processes Nice Values

Any changes you make with the renice command to a user’s processes nice values are only applicable until the next reboot. To set permanent default values, read the next section.

How To Set Default Nice Value Of a Specific User’s Processes

You can set the default nice value of a particular user or group in the /etc/security/limits.conf file. Its primary function is to define the resource limits for the users logged in via PAM.

The syntax for defining a limit for a user is as follows (and the possible values of the various columns are explained in the file):

#<domain>   <type>  <item>  <value>

Now use the syntax below where hard – means enforcing hard links and soft means – enforcing the soft limits.

<username>  <hard|soft>  priority  <nice value>

Alternatively, create a file under /etc/security/limits.d/ which overrides settings in the main file above, and these files are read in alphabetical order.

Start by creating the file /etc/security/limits.d/tecmint-priority.conf for user tecmint:

vi /etc/security/limits.d/tecmint-priority.conf

Then add this configuration to it:

tecmint  hard  priority  10

Save and close the file. From now on, any process owned by tecmint will have a nice value of 10 and PR of 30.

For more information, read the man pages of nice and renice:

man nice
man renice 

You might also like to read the following articles about Linux process management.

In this article, we briefly explained the kernel scheduler, and process priority, looked at how to run a program or command with modified priority, and also changed the priority of active Linux processes.

You can share any thoughts regarding this topic via the feedback form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.


Leave a Reply
  1. As @Will mentioned over a year ago, setting nice/renice manually is great, but it will only last until the end of the user session.

    If your system is started via systemd (most distros, including many embedded systems such as NAS, are slowly moving towards systemd as the de facto standard way of booting a Linux server), you will very likely manage services by configuring files inside /etc/systemd/system or thereabouts. You can set the nice level at boot time by adding the directive Nice=XX where XX can be set from -20 (highest priority) and 19 (lowest priority) — the default value is zero.


  2. The last section explains how to set a whole group of processes to be a given niceness. How do I set just one process instead of a whole group? As an example, I have a Linux system running the OpenMediaVault NAS array. My objective is to set the omv-engined process and the smbd process as a -20 niceness.

    • @Will

      Just run this command specifying your process:

      $ sudo nice -5 process_name arguments1 arguement2 ....

      If it’s already running, renice it like this(replace 1055 with the actual process ID):

      $ sudo renice -n  -12  -p 1055
      • Sorry, I meant permanently. As I understand it Renice and Nice only are in effect until the next user session. I want the processes to always run under that priority without me issuing a command every time.

  3. It is not clear how a task with priority 0 (nice value of -20) instead of 39 (nice value of 19) gets higher preference in execution, since it is stated in the article that “Processes with a higher priority will be executed before those with a lower priority…”.

    Probably you may have to explain the handling of user space task priority in kernel in more detail! Otherwise, it’s a nice, well-written article. Keep it up!

    • Everywhere I’ve seen the same confusing “explanation” and they make it even worse.

      The correct understanding is I suppose:

      high priority = lower priority value

      Another confusing thing, see the output of:

      # renice -n -12 $PID

      is: old priority 0 new priority – 12?

      When in reality is the nice value!!! because the old priority is 20 and new 8!

  4. Hello. There is a typo in this page:

    “It’s primary function is to define the resource limits for the users logged in via PAM.”

    should be “Its primary function (…)”.


Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.