9

I executed some commands with nice -20 but in htop the NI appears in red and as 19, why is this?

screenshot

3
  • Note that I executed a script with parallel and I also used nice -20 on it, as well as commands in the script Commented Apr 9, 2014 at 0:21
  • what was the command you used to set niceness? Commented Nov 17, 2015 at 14:43
  • nice -20 vi shows as green 20 in htop on MacOS Sierra. Commented Apr 7, 2017 at 10:12

2 Answers 2

10

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.

8
  • So since I used nice -20 it defaulted to least priority? Commented Apr 9, 2014 at 0:26
  • 2
    Yes, nice -20 or nice -19 or nice -99999999 means the least priority which is 19. Commented Apr 9, 2014 at 0:31
  • 1
    Only root can increase the priority of a process. Commented Nov 17, 2015 at 13:55
  • 2
    @cristi I'm confused, what is not correct? Are you confusing nice -20 and nice -n -20? nice -20 is equivalent to nice -n 20. Yes, it's a bit confusing to have the - sign switch from being an option marker to a minus sign. Commented Nov 18, 2015 at 0:30
  • 2
    nice -X is equivalent to nice -n X, where X is the nice value. To have max priority, i.e. a nice-value of -20, you can use nice --20 or nice -n -20. Min priority, i.e. a nice-value of +19, you can achieve with nice -19 or nice -n 19. It is confusing as long as one understands that the first - denotes just a command line option to nice and is not a sign for the number. The second -, if present, is the minus sign for the number. Commented Apr 19, 2016 at 11:09
0

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
3
  • The question stated nice -20, which is the opposite of nice -n 20. Commented Nov 18, 2015 at 0:30
  • @Gilles -n adjusts the Nice value by the amount following it, so nice -n 20 adds, just like nice -20 does (the - denotes a parameter there, not a negative value). Commented 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 Unix nice range), OP used nice -n -20, or MacOS Sierra has different nice and/or htop behavior (-20 to 20 nice values is one). Commented Apr 7, 2017 at 10:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.