I executed some commands with nice -20 but in htop the NI appears in red and as 19, why is this?
2 Answers
The “nice” value ranges from -20 (top priority, not nice at all to other processes) to 19 (least priority, very nice to others). When you run nice -20 (equivalent to nice -n 20) or sudo nice -n -42 (equivalent to sudo nice --42) or any other value out of bounds, the nice value is moved to the bound.
The red is simply coloring applied to negative values in that column, indicating high-priority (“not nice”) processes. Positive values are green, indicating low-priority (“nice”) processes.
-
So since I used
nice -20it defaulted to least priority?Dominique– Dominique2014-04-09 00:26:31 +00:00Commented Apr 9, 2014 at 0:26 -
2Yes,
nice -20ornice -19ornice -99999999means the least priority which is 19.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2014-04-09 00:31:24 +00:00Commented Apr 9, 2014 at 0:31 -
1Only root can increase the priority of a process.Rui F Ribeiro– Rui F Ribeiro2015-11-17 13:55:09 +00:00Commented Nov 17, 2015 at 13:55
-
2@cristi I'm confused, what is not correct? Are you confusing
nice -20andnice -n -20?nice -20is equivalent tonice -n 20. Yes, it's a bit confusing to have the-sign switch from being an option marker to a minus sign.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2015-11-18 00:30:16 +00:00Commented Nov 18, 2015 at 0:30 -
2
nice -Xis equivalent tonice -n X, whereXis the nice value. To have max priority, i.e. a nice-value of-20, you can usenice --20ornice -n -20. Min priority, i.e. a nice-value of +19, you can achieve withnice -19ornice -n 19. It is confusing as long as one understands that the first-denotes just a command line option toniceand is not a sign for the number. The second-, if present, is the minus sign for the number.Golar Ramblar– Golar Ramblar2016-04-19 11:09:56 +00:00Commented Apr 19, 2016 at 11:09
You probably are mistaken and didn't set niceness to -20.
If you executed the command as a normal user, for -x you will get 0 instead. For values >20 you will get 20.
If running as root, for values <-20, you will get -20.
Testing as normal user:
$ nice -n -20 sleep 100
nice: cannot set niceness: Permission denied
# ps ax -o pid,ni,cmd | grep "sleep 100"
26349 0 sleep 100
Testing as root:
$ sudo nice -n -200 sleep 100
# ps ax -o pid,ni,cmd | grep "sleep 100"
28118 0 sudo nice -n -200 sleep 100
28119 -20 sleep 100
-
The question stated
nice -20, which is the opposite ofnice -n 20.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2015-11-18 00:30:51 +00:00Commented Nov 18, 2015 at 0:30 -
@Gilles
-nadjusts the Nice value by the amount following it, sonice -n 20adds, just likenice -20does (the-denotes a parameter there, not a negative value).Cees Timmerman– Cees Timmerman2017-04-07 10:32:50 +00:00Commented Apr 7, 2017 at 10:32 -
A red value in
htopmeans it's negative, so either the "red 19" was green (as indicated by the Unixnicerange), OP usednice -n -20, or MacOS Sierra has differentniceand/orhtopbehavior (-20 to 20 nice values is one).Cees Timmerman– Cees Timmerman2017-04-07 10:38:41 +00:00Commented Apr 7, 2017 at 10:38

nice -20on it, as well as commands in the scriptnice -20 vishows as green 20 in htop on MacOS Sierra.