Welcome to the Linux Foundation Forum!

Small problems in discussion of nice/renice (Chapter on processes)

The chapter on processes introduces nice and renice. I've understood this to set the niceness of a process. The higher the niceness (max 19), the less the priority and vice versa.

In the video the instructor uses ps lf to display running processes. There is a column headed NI which contains the niceness. The column preceding this one is labelled PRI, so I suppose it contains the priority values.

First, the output of renice -n 5 does not produce the output "old niceness 0, new niceness 5" but "old priority 0, new priority 5". When the instructor reissues the command ps lf, both priority and niceness have gone up by 5.

Second, the man page for nice says that issuing renice -n alters the scheduling priority. It seems, however, that it does not increment the niceness but sets its niceness to the value given, because the instructor then issues a sudo renice -5, which does not make the niceness go down again to 0 but sets it to -5. (And again the output is "old priority 5, new priority -5" instead of "niceness".)

I'm confused here. My man page says that renice used without -n alters the priority and not the niceness. And that if used with -n the value will be considered an increment, otherwise it will set the priority. [Note: I'm on BSD.]


  • coop
    coop Posts: 913

    [Note: I'm on BSD.]

    Are you on a Linux system? I don't claim to understand any peculiarities of linux/bsd implementation differrences. In Linux, niceness and priority are directly related by mathematical formula and cannot be changed independently. i.e.,
    static priority = 120 - nice value . Not very complicated. If you are not running on a Linux distribution, this is outside the course coverage.

    If there is a word confusion in the video, I would not pay much attention to it. It's not feasible to correct a word or two in a video,
    and on long time intervals we redo them if there are important system changes or errors. (the whole video has to be redone.)
    Trust the man pages and what we see on the command line when you do things.

  • mariond
    mariond Posts: 4

    OK, thank you for the formula, that's nice :-)
    The values used in the video do not conform to this formula, btw. He has prio 20 and niceness 0. 120 - 0 is 120. Maybe you wanted to type 20 and hit the 1 accidentally.

    I understand what you're saying about correcting mistakes in the videos, it's a lot of bother.

    Still, what the instructor says contradicts what is displayed on his screen. (Not mine, his.) And as he's typing as he talks, that's really odd. So either the screen filming is fake, or the linux he uses works differently from all others.
    He types renice +5 3077 which should either increase the niceness and decrease the prio, or decrease niceness and increase prio. His next command is ps and in this BOTH prio and niceness are INcreased. This makes no sense.

    Sorry to nag, but I'm like this. A long time ago I attended a workshop on programming Objective C, and the tutor demonstrated a bit of code that was full of holes, and I said, what happens when the user does (whatever it was)? And the tutor's comment was (jokingly): "Oh god, don't be so GERMAN!"
    Sorry, I am, can't help it.

  • coop
    coop Posts: 913

    Notice i said:

    static priority = 120 - nice value

    not priority. This is the actual formula used in the kernel. The first 100 priorities (0-99) are used for "real-time" tasks and are scheduled rather differently (that's a whole other discussion) So the top program (and others) are subtracting out the 100 because it looks simpler , but technically the true internal priority is actually 100, not 0 by default. I don't have time to look at the video and see if it is messy or not, but I will at some point.


Upcoming Training