Welcome to the Linux Foundation Forum!

confusion about renice command

Hi,

  1. Does the renice +number command increase the niceness to "number" unit or set the niceness to that "number" ?
    For instance, I can't use the command renice +5 process if that process have a nice value set to 10, unless I use sudo. Because this command is going set the nice value to 5 and thus decrease the old value rather than increasing it!

  2. On my machine renice +5 process and renice 5 process do the same. Is that normal ? what's the difference between the two commands ?

  3. Increasing the niceness is supposed to decrease the priority (and vice-versa when decreasing). However, when the niceness is increased we see the priority increased as well in the PRI column of the ps command. What does the PRI column show exactly ?

Thanks.

Comments

  • luisviveropenaluisviveropena Posts: 576
    edited June 28

    Hi,

    Does the renice +number command increase the niceness to "number"
    unit or set the niceness to that "number" ?

    Set.

    For instance, I can't use the command renice +5 process if that process
    have a nice value set to 10, unless I use sudo. Because this command is
    going set the nice value to 5 and thus decrease the old value rather than
    increasing it!

    I didn't understand the details of your test, but if you are increasing the priority of a process, you need to be root or use sudo. You can see that in man renice(1):

    NOTES
    Users other than the superuser may only alter the priority of processes they own. Furthermore, an unprivi‐
    leged user can only increase the nice value'' (i.e., choose a lower priority) and such changes are irre‐ versible unless (since Linux 2.6.12) the user has a suitablenice'' resource limit (see ulimit(1) and getr‐
    limit(2)).

       The superuser may alter the priority of any process and set the priority to any value in the range -20 to  19.
       Useful  priorities  are: 19 (the affected processes will run only when nothing else in the system wants to), 0
       (the ``base'' scheduling priority), anything negative (to make things go very fast).
    

    On my machine renice +5 process and renice 5 process do the same.
    Is that normal ? what's the difference between the two commands ?

    That happens because the niceness of a process (started by you) starts on 0. So, if you add 5 or set to 5, the result will be the same. To help understand how it works, you can use the following:

    1.- Start a process, say gnome-clocks.
    2.- Print basic information of the processes and look at gnome-clocks (or whatever you are testing with):
    ps -eo pid,tid,ni,pri,stat,comm

    3.- See that "NI" and "PRI" indicates for the process.
    4.- Change the niceness of the process.
    5.- Print the information again, and compare. Ask yourself: what happened with the niceness and priority value when adding 7, for example?

    Regards,
    Luis.

  • Hello,
    I think there was confusion on Question 2.3. The two commands (renice 5 and renice +5 works on the same manner). I tried the following:

    [email protected]:~$ nice -n -7 sleep 3000 &
    [1] 4528

    [email protected]:~$ nice -n -7 sleep 3000 &
    [2] 4529

    [email protected]:~$ renice +5 4528
    4528 (process ID) old priority -7, new priority 5

    [email protected]:~$ renice 5 4529
    4529 (process ID) old priority -7, new priority 5

    [email protected]:~$ ps -lf
    F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
    0 S frank 3189 3036 0 80 0 - 2217 - 09:23 pts/1 00:00:00 bash
    0 S frank 4528 3189 0 85 5 - 1315 hrtime 10:17 pts/1 00:00:00 sleep 3000
    0 S frank 4529 3189 0 85 5 - 1315 hrtime 10:17 pts/1 00:00:00 sleep 3000
    0 R frank 4532 3189 0 80 0 - 2658 - 10:17 pts/1 00:00:00 ps -lf

    The new priority for the reniced process is the same: 85.

    Regards,
    Francesco

  • coopcoop Posts: 467

    you are correct. The argument to "renice" is the nice value to set to, not the increment or decrement. The text is somewhat ambiguous as it explains properly in once place and screws up in the earlier place. this will be fixed in the next update due in a month or two at the most. Thanks!

    BTW, your example has to be run as root, at least on my workstation, because only root can set the niceness to -7 :)

  • Hello Coop,

    it’s a pleasure to view your replay. Only for completion, I executed the command as user frank such as I set the permission for nice for that user in the configuration file /etc/security/limits.conf


    Thanks again

  • coopcoop Posts: 467

    Nice to see someone pay attention to details like /etc/security/limits.conf. you would be surprised how many things can slip by. I suspect the error in the renice description has been there literally for years and noone has tagged us on it before as best I can remember, as we fix these things as we notice them!

  • ddibddib Posts: 3
    edited March 7

    Hi,
    Thanks for the answers.
    Please, let's me explain with the following scenario

    1.- Start a process, say gnome-clocks.

    started sudoku

    2.- Print basic information of the processes and look at gnome-clocks (or whatever you are testing with):
    ps -eo pid,tid,ni,pri,stat,comm

    3956 3956 0 19 SL+ gnome-sodoku

    4.- Change the niceness of the process.

    renice 7 3956

    5.- Print the information again, and compare. Ask yourself: what happened with the niceness and priority value when adding 7, for example?

    3956 3956 7 12 SL+ gnome-sodoku

    4.- Change the niceness of the process. AGAIN

    renice +2 3956
    This is supposed to turn the niceness to 9 (7+2) and the priority to 10 but it fails (permission denied)

    Moreover,
    renice +9 3956
    3956 3956 9 10 SL+ gnome-sodoku
    This instruction sets the niceness to 9 rather than 16 (7+9)
    How is this explained ?

    Regards.

  • coopcoop Posts: 467

    as explained in the posts, please read more carefully. renice sets it to the value given, not as an increment. That's exactly what this thread was about so you are getting the correct behaviour (if I am understanding correctly!)

  • luisviveropenaluisviveropena Posts: 576

    Just to add my two cents to what Coop already said, you always can see the man command. As in this case, man renice(1) says the following:

    DESCRIPTION
    renice alters the scheduling priority of one or more running processes. The first argument is the priority value to be used. The other arguments are interpreted as process IDs (by default), process group IDs, user IDs, or user names. renice'ing a process group causes all processes in the process group to have their scheduling priority altered. renice'ing a user causes all processes owned by the user to have their scheduling priority altered.

    Note the following ==> The first argument is the priority value to be used.

    Regards,
    Luis.

  • ddibddib Posts: 3

    Thanks for your answers.
    I'm sorry, I didn't see the posts from coop and francesco.iennarella before my second post.
    It is clearer now.

    The confusion came from the Question 3.2 of the course.

    Which command will increase the niceness by 5 units of the process with PID = 444?

    replacing "increase" with "set" would be better.

  • coopcoop Posts: 467

    We will have to look at this, I don't have the KC in front of me.

    Note this is a confusing issue, which is why the course material had it twisted up slightly :)

  • Hello,

    Just to remind that the question 3.2 still waits the correction:
    Question 3.2
    Which command will increase the niceness by 5 units of the process with PID = 444?

    Incorrect Answer

    A. renice 5 444Correct Answer
    B. renice +5 444Your Answer
    C. nice -5 444
    D. nice +5 444Next Question

    BR
    C

  • coopcoop Posts: 467

    This error should have been fixed months ago but seems to have fallen through the cracks. It should say "set " not "increase". It will be fixed in next update.

Sign In or Register to comment.