Commands.page Logo

How to Sort Processes by Nice Value in htop on Ubuntu

Managing system resources effectively requires understanding process priorities. This article provides a concise guide on using the htop utility within Ubuntu to organize and view running processes based on their nice value. By following these steps, you can quickly identify which tasks have higher or lower CPU priority and manage system performance accordingly.

Prerequisites

Ensure htop is installed on your Ubuntu system. If it is not already available, open a terminal and install it using the following command:

sudo apt update
sudo apt install htop

Launching htop

Open your terminal and run the following command to start the process viewer:

htop

You may need to use sudo htop if you want to view processes owned by other users or change priorities later.

Sorting by Nice Value

Once htop is running, follow these steps to sort the process list by nice value:

  1. Press the F6 key on your keyboard. This opens the sort menu.
  2. Use the arrow keys to navigate through the list of available columns.
  3. Select NICE from the list.
  4. Press Enter to apply the sort.

Alternatively, if you are using a mouse within the terminal, you can simply click on the NICE column header to sort the processes.

Understanding Nice Values

The nice value determines the priority of a process. The range typically spans from -20 to 19.

Sorting by this column allows you to immediately see which processes are favored by the scheduler and which are deprioritized.

Changing Process Priority

If you need to adjust the nice value of a specific process while in htop:

  1. Select the process using the arrow keys.
  2. Press F7 to increase priority (decrease nice value).
  3. Press F8 to decrease priority (increase nice value).

Note that increasing priority (lowering the nice value) usually requires root privileges.

Exiting htop

To close the application and return to your standard terminal prompt, press the F10 key or q.

By mastering these sorting and management techniques, you can maintain better control over your Ubuntu system’s workload distribution.