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

How is Livepatch safeguarded against bad actors?

Canonical Livepatch is a security patching automation tool which supports reboot-less security updates for the…

4 hours ago

Accelerating data science with Apache Spark and GPUs

Apache Spark has always been very well known for distributing computation among multiple nodes using…

4 hours ago

Cut data center energy costs with bare metal automation

Data centers are popping up everywhere. With the rapid growth of AI, cloud services, streaming…

1 day ago

Build the future of *craft: announcing Starcraft Bounties!

Our commitment to building a thriving open source community is stronger than ever. We believe…

1 day ago

NodeJS 18 LTS EOL extended from April 2025 to May 2032 on Ubuntu

The clock was ticking: Node.js 18’s upstream End of Life (EOL) The OpenJS Foundation is…

1 day ago

Native integration now available for Pure Storage and Canonical LXD

June 25th, 2025 – Canonical, the company behind Ubuntu, and Pure Storage, the IT pioneer…

2 days ago