96

Is it possible to set a new nice level of a running process with a known id?

Does this operation require root access, or just being the owner of the process?

0

7 Answers 7

88

Terminal

If you're at a terminal you can use renice

renice [-n] priority [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...]

A simple example would be

renice 8 31043
31043: old priority 5, new priority 8

You can also pass it hard flags, but it follows that order (you have to pass priority first and then the pid - if you change the order it will show the usage messagge)

renice -n 5 -p 31043
31043: old priority 8, new priority 5

Priorities work on a scale of -20 to 19 - The lower the number, the higher it's priority on the system.

If you own the process then you won't need root - however, if the process is owned by another user or if you plan on changing the group/user of the process root (via sudo) will be required.

6
  • 14
    You cannot decrease niceness as user. :)
    – htorque
    Jun 14, 2011 at 13:05
  • 9
    As @htorque says, a non-root user can only increase niceness--they cannot decrease niceness, not even to a previous level of niceness the process had, and not even to a previous level of niceness they had themselves reniced the process down from. I recommend editing this answer to incorporate that information. Oct 14, 2012 at 14:35
  • 3
    Is there any downside to making a process priority -20? Jun 4, 2016 at 4:03
  • 2
    @JamesWatkins You could stall your computer
    – DarthRubik
    Jul 24, 2016 at 1:18
  • /\ Not really, the nice value is still not the same as the thread scheduler priority. The way to actually stall a machine is to set a process' RTPRIO as realtime (that is a value of -99 and is different from the nice value) while running on the SCHED_FIFO scheduling policy with a realtime-enabled kernel (such as linux with the RT_Preempt patchset) and even then, only if this process uses up 100% of CPU time of all threads and never yields. (continues)
    – Marc.2377
    Dec 11, 2019 at 5:19
36

GUI

  • Alt+F2 and type sudo gnome-system-monitor

Prior to 11.04: System > Administration > System Monitor. Choose Processes.
In 11.04: Alt+A and search for system monitor.

The id's are shown in the image here:

enter image description here

And nice does not require sudo for increasing niceness if you own the task. It does if you need to decrease niceness.

0
12

Start a command with nice:

nice -n 19 your_command

Renice process:

renice 19 $(pidof your_command_name_like_for_ex_ffmpeg)

Priority could be between -20 and 19. 19 is the lowest priority.

8

Usage of "renice" in terminal is as follows:

Usage:
 renice [-n] <priority> [-p] <pid> [<pid>  ...]
 renice [-n] <priority> [-g] <pgrp> [<pgrp> ...]
 renice [-n] <priority> [-u] <user> [<user> ...]

Options:
 -g, --pgrp <id>        interpret as process group ID
 -h, --help             print help
 -n, --priority <num>   set the nice increment value
 -p, --pid <id>         force to be interpreted as process ID
 -u, --user <name|id>   interpret as username or user ID
 -v, --version          print version

Using "sudo" before command "renice" elevates user to root level and an admin/root password will be required.

So e.g. if you want to elevate process with PID (process ID) 2606 from Normal priority to High priority, you would type in terminal as follows:

sudo renice -n -5 -p 2606
5

You can also renice a process within top.

  1. Start top

    $ top
    
  2. Renice by pressing r. You will be prompted for the Process ID (PID) of the process you wish to renice. The default PID is the first process (one consuming the most resources). Confirm with Enter. Set the new nice value from -20 (higher priority) to +19 (lower priority).

    screenshot

4

htop

  1. Start htop
  2. Renice with F7/F8 (if you are inside Byobu temporary disable shortcuts with Shift + F12). Keep in mind you need root privileges to reduce niceness.

screenhot

0

You can add capability CAP_SYS_NICE to user using Linux capabilities system if you don't want to grant full root access to user/script.

Unfortunately, it still allows to renice arbitrary process, including those owned by different users.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .