Categories: TutorialsUbuntu

How to Set Process Priority in Linux

Every Linux system has multiple processes running at the same time. They are scheduled for execution by kernel scheduler that determines the next process to be executed depending on multiple factors. It uses a priority-based scheduling algorithm to rank and run processes. Processes with higher priority are executed before those with lower priority. In most cases, it is advisable to leave process scheduling to the Linux system. But if you need to set process priority in Linux, that can also be done. In this article, we will learn how to set process priority in Linux.

How to Set Process Priority in Linux

Sponsored

There are two kinds of priority values associated with each process – one is a niceness value that ranges from -20(highest priority) to 19(lowest priority), and the other is real-time priority ranging from 1 to 99. When we mean to set process priority, we will be changing the niceness value of a process.

You can check niceness value of process, using ps, top or htop.

$ ps -eo pid,ppid,ni,comm

The NI column in following output shows the niceness value. You can also use top and htop which show niceness values by default.

If you have a long-running CPU intensive program that you don’t think will run anytime soon, then you can use nice command to set its priority. Here is the syntax of nice command.

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

If you don’t provide any niceness-value, the above command will use a default priority of 10. Please note, only root users will be able to change nice values of programs. If you don’t use any nice default value, the programs get a default priority of 0.

Here are a couple of commands to set priority of commands using nice command.

Sponsored
$ sudo nice -n 5 tar -czf backup.tar.gz /home/ubuntu/data
OR
$ sudo nice --adjustment=5 tar -czf backup.tar.gz /home/ubuntu/data

If a program is already running, you can change its priority dynamically using renice command. The first command allows you to change priority using PID (1243) or using process name (apache).

$ renice -n  -12  -p 1243
$ renice -n -2  -u apache

In this article, we have learnt how to set process priority in Linux. Linux is pretty good at scheduling processes and setting their priority values. In most cases, you don’t need to change process priorities. But if you have some long running or system intensive processes, then you can use nice or renice commands. If you are yet to run commands, then use nice to set their priority before they are run. If your commands are already running, use renice to change their priority.

Also read:

How to Set Default MySQL Data Directory in Linux
How to Fix firewall-cmd commant not found
How to Protect Hard & Symbolic Links
How to Run Shell Script on Another Server
How to Manage Systemd Services on Remote Server

The post How to Set Process Priority in Linux appeared first on Fedingo.

Ubuntu Server Admin

Recent Posts

Everything you need to know about FIPS 140-3 on Ubuntu | Videos

FIPS 140 is a highly demanding security standard that’s mandatory for almost all high-security and…

7 hours ago

A CISO’s preview of open source and cybersecurity trends in 2026 and beyond

Open source has come a long way. Recently I was watching a keynote address by…

5 days ago

Canonical Kubernetes officially included in Sylva 1.5

Sylva 1.5 becomes the first release to include Kubernetes 1.32, bringing the latest open source…

5 days ago

Canonical expands total coverage for Ubuntu LTS releases to 15 years with Legacy add-on

Expansion ensures business continuity without forcing major upgrades Today, Canonical announced the expansion of the…

6 days ago

Announcing YARD-Lint: Keep Your Ruby Documentation Solid

TL;DR: YARD-Lint catches documentation issues, just like RuboCop for code. Star it and use it…

6 days ago

Canonical releases FIPS-enabled Kubernetes

Deploy a FedRAMP-ready kubernetes cluster and application suite, with FIPS 140-3 crypto and DISA-STIG hardening…

1 week ago