Process Priority value is different in procfs
Clash 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?
process nice procfs
add a comment |Â
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?
process nice procfs
add a comment |Â
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?
process nice procfs
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?
process nice procfs
edited Dec 17 '17 at 13:51
Jeff Schaller
31.9k848109
31.9k848109
asked Dec 14 '17 at 16:29
Amine Marzouki
132
132
add a comment |Â
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password