Process Priority value is different in procfs

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












For example, let's examine the value of PRI of firefox with ps, and then see what is the value stored in procfs.



$ ps -o pid,comm,pri,ni 7000
PID COMMAND PRI NI
7000 firefox 19 0

$ cat /proc/7000/stat
7000 (firefox) S 1 6447 6447 0 -1 4194304 3162595 624998 158 10 30467 6903 3360 488 20 0 63 0 464836 9472659456 123045 18446744073709551615 94866409246720 94866409429052 140727418541056 0 0 0 0 4096 33572095 0 0 0 17 2 0 0 342 0 0 94866411526576 94866411528296 94866422095872 140727418542495 140727418542520 140727418542520 140727418544095 0


According to man proc, we will find the value of PRI in the 18th value (counting from 1), so in this case PRI = 20



I want to know why there is such difference between the output of the ps command and the value stored in the /proc stat file?







share|improve this question


























    up vote
    2
    down vote

    favorite












    For example, let's examine the value of PRI of firefox with ps, and then see what is the value stored in procfs.



    $ ps -o pid,comm,pri,ni 7000
    PID COMMAND PRI NI
    7000 firefox 19 0

    $ cat /proc/7000/stat
    7000 (firefox) S 1 6447 6447 0 -1 4194304 3162595 624998 158 10 30467 6903 3360 488 20 0 63 0 464836 9472659456 123045 18446744073709551615 94866409246720 94866409429052 140727418541056 0 0 0 0 4096 33572095 0 0 0 17 2 0 0 342 0 0 94866411526576 94866411528296 94866422095872 140727418542495 140727418542520 140727418542520 140727418544095 0


    According to man proc, we will find the value of PRI in the 18th value (counting from 1), so in this case PRI = 20



    I want to know why there is such difference between the output of the ps command and the value stored in the /proc stat file?







    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      For example, let's examine the value of PRI of firefox with ps, and then see what is the value stored in procfs.



      $ ps -o pid,comm,pri,ni 7000
      PID COMMAND PRI NI
      7000 firefox 19 0

      $ cat /proc/7000/stat
      7000 (firefox) S 1 6447 6447 0 -1 4194304 3162595 624998 158 10 30467 6903 3360 488 20 0 63 0 464836 9472659456 123045 18446744073709551615 94866409246720 94866409429052 140727418541056 0 0 0 0 4096 33572095 0 0 0 17 2 0 0 342 0 0 94866411526576 94866411528296 94866422095872 140727418542495 140727418542520 140727418542520 140727418544095 0


      According to man proc, we will find the value of PRI in the 18th value (counting from 1), so in this case PRI = 20



      I want to know why there is such difference between the output of the ps command and the value stored in the /proc stat file?







      share|improve this question














      For example, let's examine the value of PRI of firefox with ps, and then see what is the value stored in procfs.



      $ ps -o pid,comm,pri,ni 7000
      PID COMMAND PRI NI
      7000 firefox 19 0

      $ cat /proc/7000/stat
      7000 (firefox) S 1 6447 6447 0 -1 4194304 3162595 624998 158 10 30467 6903 3360 488 20 0 63 0 464836 9472659456 123045 18446744073709551615 94866409246720 94866409429052 140727418541056 0 0 0 0 4096 33572095 0 0 0 17 2 0 0 342 0 0 94866411526576 94866411528296 94866422095872 140727418542495 140727418542520 140727418542520 140727418544095 0


      According to man proc, we will find the value of PRI in the 18th value (counting from 1), so in this case PRI = 20



      I want to know why there is such difference between the output of the ps command and the value stored in the /proc stat file?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 17 '17 at 13:51









      Jeff Schaller

      31.9k848109




      31.9k848109










      asked Dec 14 '17 at 16:29









      Amine Marzouki

      132




      132




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Uh, apparently the pri field is exactly 39 minus the value that is visible in /proc/$pid/stat (so 39 - 20 = 19). It's also commented as 'not legal as UNIX "PRI"', since




          Unix98 only specifies that a high "PRI" is low priority.




          And that doesn't apply there.



          But! There are no less than six other output formats for the priority, all of which have the raw value either negated or not, plus some constant.
          Take a pick. Here's three cats with different nice values:



          $ ps -o pid,rtprio,pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api,ni,args -Ccat
          PID RTPRIO PRI PRI PRI FOO BAR BAZ API NI COMMAND
          18418 - 0 99 39 19 40 139 -40 19 cat /dev/zero
          18419 - 19 80 20 0 21 120 -21 0 cat /dev/zero
          18420 - 39 60 0 -20 1 100 -1 -20 cat /dev/zero


          The comments in the code say that




          Sun and SCO add the -c behavior. Sun defines "pri" and "opri".




          So there's probably some historical reason to fix the output range to match. ps -c uses the pri valu here. priority is the raw value as the kernel presents it.



          The relevant source code file is ps/output.c:
          https://gitlab.com/procps-ng/procps/blob/master/ps/output.c#L585



          Also: https://superuser.com/questions/286752/unix-ps-l-priority/286761

          and https://stackoverflow.com/questions/18829350/linux-thread-priority-value






          share|improve this answer




















          • Thank you for your answer, however I still didn't get some details here. Would you mind telling me why there are so much different priority values? (pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api) what is the use of all of this? Do we actually need all those different values? @ilkkachu
            – Amine Marzouki
            Dec 14 '17 at 17:55











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f410912%2fprocess-priority-value-is-different-in-procfs%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          Uh, apparently the pri field is exactly 39 minus the value that is visible in /proc/$pid/stat (so 39 - 20 = 19). It's also commented as 'not legal as UNIX "PRI"', since




          Unix98 only specifies that a high "PRI" is low priority.




          And that doesn't apply there.



          But! There are no less than six other output formats for the priority, all of which have the raw value either negated or not, plus some constant.
          Take a pick. Here's three cats with different nice values:



          $ ps -o pid,rtprio,pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api,ni,args -Ccat
          PID RTPRIO PRI PRI PRI FOO BAR BAZ API NI COMMAND
          18418 - 0 99 39 19 40 139 -40 19 cat /dev/zero
          18419 - 19 80 20 0 21 120 -21 0 cat /dev/zero
          18420 - 39 60 0 -20 1 100 -1 -20 cat /dev/zero


          The comments in the code say that




          Sun and SCO add the -c behavior. Sun defines "pri" and "opri".




          So there's probably some historical reason to fix the output range to match. ps -c uses the pri valu here. priority is the raw value as the kernel presents it.



          The relevant source code file is ps/output.c:
          https://gitlab.com/procps-ng/procps/blob/master/ps/output.c#L585



          Also: https://superuser.com/questions/286752/unix-ps-l-priority/286761

          and https://stackoverflow.com/questions/18829350/linux-thread-priority-value






          share|improve this answer




















          • Thank you for your answer, however I still didn't get some details here. Would you mind telling me why there are so much different priority values? (pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api) what is the use of all of this? Do we actually need all those different values? @ilkkachu
            – Amine Marzouki
            Dec 14 '17 at 17:55















          up vote
          3
          down vote



          accepted










          Uh, apparently the pri field is exactly 39 minus the value that is visible in /proc/$pid/stat (so 39 - 20 = 19). It's also commented as 'not legal as UNIX "PRI"', since




          Unix98 only specifies that a high "PRI" is low priority.




          And that doesn't apply there.



          But! There are no less than six other output formats for the priority, all of which have the raw value either negated or not, plus some constant.
          Take a pick. Here's three cats with different nice values:



          $ ps -o pid,rtprio,pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api,ni,args -Ccat
          PID RTPRIO PRI PRI PRI FOO BAR BAZ API NI COMMAND
          18418 - 0 99 39 19 40 139 -40 19 cat /dev/zero
          18419 - 19 80 20 0 21 120 -21 0 cat /dev/zero
          18420 - 39 60 0 -20 1 100 -1 -20 cat /dev/zero


          The comments in the code say that




          Sun and SCO add the -c behavior. Sun defines "pri" and "opri".




          So there's probably some historical reason to fix the output range to match. ps -c uses the pri valu here. priority is the raw value as the kernel presents it.



          The relevant source code file is ps/output.c:
          https://gitlab.com/procps-ng/procps/blob/master/ps/output.c#L585



          Also: https://superuser.com/questions/286752/unix-ps-l-priority/286761

          and https://stackoverflow.com/questions/18829350/linux-thread-priority-value






          share|improve this answer




















          • Thank you for your answer, however I still didn't get some details here. Would you mind telling me why there are so much different priority values? (pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api) what is the use of all of this? Do we actually need all those different values? @ilkkachu
            – Amine Marzouki
            Dec 14 '17 at 17:55













          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          Uh, apparently the pri field is exactly 39 minus the value that is visible in /proc/$pid/stat (so 39 - 20 = 19). It's also commented as 'not legal as UNIX "PRI"', since




          Unix98 only specifies that a high "PRI" is low priority.




          And that doesn't apply there.



          But! There are no less than six other output formats for the priority, all of which have the raw value either negated or not, plus some constant.
          Take a pick. Here's three cats with different nice values:



          $ ps -o pid,rtprio,pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api,ni,args -Ccat
          PID RTPRIO PRI PRI PRI FOO BAR BAZ API NI COMMAND
          18418 - 0 99 39 19 40 139 -40 19 cat /dev/zero
          18419 - 19 80 20 0 21 120 -21 0 cat /dev/zero
          18420 - 39 60 0 -20 1 100 -1 -20 cat /dev/zero


          The comments in the code say that




          Sun and SCO add the -c behavior. Sun defines "pri" and "opri".




          So there's probably some historical reason to fix the output range to match. ps -c uses the pri valu here. priority is the raw value as the kernel presents it.



          The relevant source code file is ps/output.c:
          https://gitlab.com/procps-ng/procps/blob/master/ps/output.c#L585



          Also: https://superuser.com/questions/286752/unix-ps-l-priority/286761

          and https://stackoverflow.com/questions/18829350/linux-thread-priority-value






          share|improve this answer












          Uh, apparently the pri field is exactly 39 minus the value that is visible in /proc/$pid/stat (so 39 - 20 = 19). It's also commented as 'not legal as UNIX "PRI"', since




          Unix98 only specifies that a high "PRI" is low priority.




          And that doesn't apply there.



          But! There are no less than six other output formats for the priority, all of which have the raw value either negated or not, plus some constant.
          Take a pick. Here's three cats with different nice values:



          $ ps -o pid,rtprio,pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api,ni,args -Ccat
          PID RTPRIO PRI PRI PRI FOO BAR BAZ API NI COMMAND
          18418 - 0 99 39 19 40 139 -40 19 cat /dev/zero
          18419 - 19 80 20 0 21 120 -21 0 cat /dev/zero
          18420 - 39 60 0 -20 1 100 -1 -20 cat /dev/zero


          The comments in the code say that




          Sun and SCO add the -c behavior. Sun defines "pri" and "opri".




          So there's probably some historical reason to fix the output range to match. ps -c uses the pri valu here. priority is the raw value as the kernel presents it.



          The relevant source code file is ps/output.c:
          https://gitlab.com/procps-ng/procps/blob/master/ps/output.c#L585



          Also: https://superuser.com/questions/286752/unix-ps-l-priority/286761

          and https://stackoverflow.com/questions/18829350/linux-thread-priority-value







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 14 '17 at 17:18









          ilkkachu

          49.9k674137




          49.9k674137











          • Thank you for your answer, however I still didn't get some details here. Would you mind telling me why there are so much different priority values? (pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api) what is the use of all of this? Do we actually need all those different values? @ilkkachu
            – Amine Marzouki
            Dec 14 '17 at 17:55

















          • Thank you for your answer, however I still didn't get some details here. Would you mind telling me why there are so much different priority values? (pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api) what is the use of all of this? Do we actually need all those different values? @ilkkachu
            – Amine Marzouki
            Dec 14 '17 at 17:55
















          Thank you for your answer, however I still didn't get some details here. Would you mind telling me why there are so much different priority values? (pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api) what is the use of all of this? Do we actually need all those different values? @ilkkachu
          – Amine Marzouki
          Dec 14 '17 at 17:55





          Thank you for your answer, however I still didn't get some details here. Would you mind telling me why there are so much different priority values? (pri,opri,priority,pri_foo,pri_bar,pri_baz,pri_api) what is the use of all of this? Do we actually need all those different values? @ilkkachu
          – Amine Marzouki
          Dec 14 '17 at 17:55













           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f410912%2fprocess-priority-value-is-different-in-procfs%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay