I executed some commands with
nice -20 but in
htop the NI appears in red and as 19, why is this?
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.
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