renice command: Change the Priority of a Already Running Process

by on February 26, 2008 · 8 comments· LAST UPDATED February 26, 2008

in , ,

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.

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 8 comments… read them below or add one }

1 Sarika June 13, 2008 at 2:37 am

perfect!

Reply

2 Nudge January 30, 2010 at 2:11 pm

“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?

Reply

3 Simon March 15, 2010 at 11:57 pm

“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?

Reply

4 Cameron February 15, 2011 at 3:26 am

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.

Reply

5 jameel August 27, 2013 at 10:00 am

thank you sir

Reply

6 bdone February 6, 2014 at 7:01 pm

can you explain your “little test”?

Reply

7 vaibhav July 23, 2013 at 10:46 am

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

Reply

8 bdone February 6, 2014 at 6:57 pm

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?

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , ,

Previous Faq:

Next Faq: