renice command: Change the Priority of a Already Running Process

Q. I’d like alter / change the scheduling priority of running processes. How do I change the Priority of a already running process under CentOS Linux or any UNIX like operating systems?

A. If you run CPU-bond processes you must use nice command used to start process with modified scheduling priority / nicenesses. renice command is used to change the priority of a process that’s already running.

ADVERTISEMENTS

renice command syntax:

The renice command changes the nice value of a process already running. It’s syntax is as follows:
renice {priority} pid
The following will change nice value of process 2243 to 19, enter:
# renice 19 2243
The following will change the priority of process ID’s 1024 and all processes owned by users vivek, enter:
# renice +1 1024 -u vivek
The following will change the priority of process ID’s 1024 and 66, and all processes owned by users daemon and root.
# renice +1 1024 -u daemon root -p 66
Please note that:

  1. Users can only change the nice value of processes which they own.
  2. User cannot start processes with nice values less than 20
  3. User cannot lower the nice values of their processes after they’ve raised them.
  4. As usual root has full access to renice command

For more details and options see renice command man page:
$ man renice

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
8 comments… add one
  • Sarika Jun 13, 2008 @ 2:37

    perfect!

  • Nudge Jan 30, 2010 @ 14:11

    “2. User cannot start processes with nice values less than 20”:

    That’s not really correct. It is possible for users to go down to nice value 0, e.g. by not using the nice command when starting processes. This results in processes having *priority* 20. Prority and nice-values belong together (NI 0 => PR 20, NI 19 => PR 39, NI -20 => PR 0).

    According to the manual, renice can use delta values like +3 or -2 for changing nice values, but to me it seems unclear what happens when entering “renice -5 ” as root – does that mean a nice value of -5 or lowering the existing nice value by 5?

  • Simon Mar 15, 2010 @ 23:57

    “to me it seems unclear what happens when entering “renice -5 ” as root – does that mean a nice value of -5 or lowering the existing nice value by 5?”

    Great question. I too am still confused by the usage of this command. This also seems quite strange to me…

    “User cannot lower the nice values of their processes after they’ve raised them.” Why would that be?

  • Cameron Feb 15, 2011 @ 3:26

    I was curious about the question in the comments, so I did a little test:

    cameron$ echo “fib=lambda n: (n in (0,1) and [n] or [fib(n-1)+fib(n-2)])[0];print fib(38)” | python &
    [1] 76611
    cameron$ ps -o command,pid,pri,ni -p 76611
    COMMAND PID PRI NI
    python 76611 31 0
    cameron$ sudo renice -4 76611
    cameron$ ps -o command,pid,pri,ni -p 76611
    COMMAND PID PRI NI
    python 76611 35 -4
    cameron$ sudo renice -5 76611
    cameron$ ps -o command,pid,pri,ni -p 76611
    COMMAND PID PRI NI
    python 76611 36 -5

    so, it looks like the command sets the nice value to the given value, rather than moving it relative to what is was before.

    • jameel Aug 27, 2013 @ 10:00

      thank you sir

    • bdone Feb 6, 2014 @ 19:01

      can you explain your “little test”?

  • vaibhav Jul 23, 2013 @ 10:46

    I dunno why, but although “User cannot lower the nice values of their processes after they’ve raised them.”, root can.

    • bdone Feb 6, 2014 @ 18:57

      root can do ANYTHING in a computer, hence definition of root. user wouldn’t be able to lower the process until quit process. This is because that would be like asking a king to give up their throne willingly, for no reason; with all that power over their kingdom, only death can take away their desire to keep said power. once you give the process the power to take control of your user session to that degree, the only way to ensure that you have lowered the process again, would be to kill process and restart process.
      does that make sense?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.