5

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

screenshot

  • Note that I executed a script with parallel and I also used nice -20 on it, as well as commands in the script – Dominique Apr 9 '14 at 0:21
  • what was the command you used to set niceness? – cristi Nov 17 '15 at 14:43
  • nice -20 vi shows as green 20 in htop on MacOS Sierra. – Cees Timmerman Apr 7 '17 at 10:12
5

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 -20 it defaulted to least priority? – Dominique Apr 9 '14 at 0:26
  • 1
    Yes, nice -20 or nice -19 or nice -99999999 means the least priority which is 19. – Gilles Apr 9 '14 at 0:31
  • 1
    Only root can increase the priority of a process. – Rui F Ribeiro Nov 17 '15 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. – Gilles Nov 18 '15 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. – Golar Ramblar Apr 19 '16 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
  • The question stated nice -20, which is the opposite of nice -n 20. – Gilles Nov 18 '15 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). – Cees Timmerman Apr 7 '17 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). – Cees Timmerman Apr 7 '17 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.