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.
-
-
1Yes,
nice -20
ornice -19
ornice -99999999
means the least priority which is 19. Apr 9, 2014 at 0:31 -
1
-
2@cristi I'm confused, what is not correct? Are you confusing
nice -20
andnice -n -20
?nice -20
is equivalent tonice -n 20
. Yes, it's a bit confusing to have the-
sign switch from being an option marker to a minus sign. Nov 18, 2015 at 0:30 -
2
nice -X
is equivalent tonice -n X
, whereX
is the nice value. To have max priority, i.e. a nice-value of-20
, you can usenice --20
ornice -n -20
. Min priority, i.e. a nice-value of +19, you can achieve withnice -19
ornice -n 19
. It is confusing as long as one understands that the first-
denotes just a command line option tonice
and is not a sign for the number. The second-
, if present, is the minus sign for the number. 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
. Nov 18, 2015 at 0:30 -
@Gilles
-n
adjusts the Nice value by the amount following it, sonice -n 20
adds, just likenice -20
does (the-
denotes a parameter there, not a negative value). Apr 7, 2017 at 10:32 -
A red value in
htop
means it's negative, so either the "red 19" was green (as indicated by the Unixnice
range), OP usednice -n -20
, or MacOS Sierra has differentnice
and/orhtop
behavior (-20 to 20 nice values is one). Apr 7, 2017 at 10:38
nice -20
on it, as well as commands in the scriptnice -20 vi
shows as green 20 in htop on MacOS Sierra.