How to find scheduling policy and active processes' priority?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I want to make a shell script that finds all active processes and to print to the user the scheduling policy.I want the result to be like this.
pid 3042's current scheduling policy: SCHED_OTHER
pid 3042's current scheduling priority: 0
pid 3043's current scheduling policy: SCHED_OTHER
pid 3043's current scheduling priority: 0
pid 3044's current scheduling policy: SCHED_OTHER
pid 3044's current scheduling priority: 0
I have managed to do this but only for a single process with the use of ps
and chrt
commands.
linux shell-script process real-time
add a comment |Â
up vote
0
down vote
favorite
I want to make a shell script that finds all active processes and to print to the user the scheduling policy.I want the result to be like this.
pid 3042's current scheduling policy: SCHED_OTHER
pid 3042's current scheduling priority: 0
pid 3043's current scheduling policy: SCHED_OTHER
pid 3043's current scheduling priority: 0
pid 3044's current scheduling policy: SCHED_OTHER
pid 3044's current scheduling priority: 0
I have managed to do this but only for a single process with the use of ps
and chrt
commands.
linux shell-script process real-time
For the schuduling policy, you can parse the output from /proc/pid/sched. I will try to write a script later
â Karim Manaouil
Nov 28 '17 at 19:01
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to make a shell script that finds all active processes and to print to the user the scheduling policy.I want the result to be like this.
pid 3042's current scheduling policy: SCHED_OTHER
pid 3042's current scheduling priority: 0
pid 3043's current scheduling policy: SCHED_OTHER
pid 3043's current scheduling priority: 0
pid 3044's current scheduling policy: SCHED_OTHER
pid 3044's current scheduling priority: 0
I have managed to do this but only for a single process with the use of ps
and chrt
commands.
linux shell-script process real-time
I want to make a shell script that finds all active processes and to print to the user the scheduling policy.I want the result to be like this.
pid 3042's current scheduling policy: SCHED_OTHER
pid 3042's current scheduling priority: 0
pid 3043's current scheduling policy: SCHED_OTHER
pid 3043's current scheduling priority: 0
pid 3044's current scheduling policy: SCHED_OTHER
pid 3044's current scheduling priority: 0
I have managed to do this but only for a single process with the use of ps
and chrt
commands.
linux shell-script process real-time
edited Nov 28 '17 at 13:31
Jeff Schaller
32.1k849109
32.1k849109
asked Nov 28 '17 at 12:44
Spyros
1013
1013
For the schuduling policy, you can parse the output from /proc/pid/sched. I will try to write a script later
â Karim Manaouil
Nov 28 '17 at 19:01
add a comment |Â
For the schuduling policy, you can parse the output from /proc/pid/sched. I will try to write a script later
â Karim Manaouil
Nov 28 '17 at 19:01
For the schuduling policy, you can parse the output from /proc/pid/sched. I will try to write a script later
â Karim Manaouil
Nov 28 '17 at 19:01
For the schuduling policy, you can parse the output from /proc/pid/sched. I will try to write a script later
â Karim Manaouil
Nov 28 '17 at 19:01
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
I've come up with the following command using ps
and awk
which gives very similar output with only a small difference in that it shows abbreviated names of the scheduling class. The following mapping could help you :
TS is SCHED_OTHER
RR is SCHED_RR
FF is SCHED_FIFO
The command:
ps -e -o s,pid,cls,pri | grep ^R | awk -v sq="'" 'print "pid",$2,sq,"s current scheduling policy:",$3,"npid",$2,sq,"s current priority:",$4'
Running the above command on my host gives the following output:
pid 8456 ' s current scheduling policy: TS
pid 8456 ' s current priority: 19
pid 12552 ' s current scheduling policy: TS
pid 12552 ' s current priority: 19
EDIT
Based on the comment, the following command gives an exact output using chrt
and assuming that an active process is a running or a runnable process R
:
ps -e -o s,pid | grep ^R | awk 'system("chrt -p " $2)'
In case you want to get the output for all the processes (Running, Sleeping, Stopped & Zombie), you would like to use the following command:
ls /proc | grep -e ^[0-9] | awk 'system("chrt -p " $0)'|more
1
Actually you don't have to print all that.If you just run the commandchrt -p 8456
for example it has exactly the desirable result.My struggle is when i try to use thechrt
command for 2 or more processes.If you got any other ideas i'd be grateful.
â Spyros
Nov 29 '17 at 12:06
@Spyros I edited the answer to include the update you have requested. Assuming that an active process is arunning
or arunnable
process (State =R
).
â Karim Manaouil
Nov 29 '17 at 17:56
I didin't specify that i want to do that only for the current user and just for the active processes of that user.If you want to try that scenario you are free to do so.I found a solution i dont know if its optimal but i'll post it later in case someone faces the same problem.Thank you for your answer anyway.
â Spyros
Nov 30 '17 at 10:09
@Spyros You didn't mention all those details in your original description. You can actually do minor changes on theps
command above to fit your exact needs. However, posting your solution is a valuable share with the community.
â Karim Manaouil
Dec 1 '17 at 20:47
Manaouli I think I mentioned it was about active processes but I didn't mention clearly that they had to be user's processes only. Anyway thank you again for the time you spent answering.
â Spyros
Dec 1 '17 at 23:46
add a comment |Â
up vote
0
down vote
accepted
I found two ways for doing it they may not be optimal but they get the job done.
#! /bin/bash
ps -u |grep [0-9]|awk 'print $2' > test.txt
cat test.txt |while read line
do
chrt -p $line 2 > /dev/null
done
2.
With this way you don't create unnecessary file.
ps -u|grep [0-9]|awk 'system("chrt -p" $2) 2 > /dev/null
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I've come up with the following command using ps
and awk
which gives very similar output with only a small difference in that it shows abbreviated names of the scheduling class. The following mapping could help you :
TS is SCHED_OTHER
RR is SCHED_RR
FF is SCHED_FIFO
The command:
ps -e -o s,pid,cls,pri | grep ^R | awk -v sq="'" 'print "pid",$2,sq,"s current scheduling policy:",$3,"npid",$2,sq,"s current priority:",$4'
Running the above command on my host gives the following output:
pid 8456 ' s current scheduling policy: TS
pid 8456 ' s current priority: 19
pid 12552 ' s current scheduling policy: TS
pid 12552 ' s current priority: 19
EDIT
Based on the comment, the following command gives an exact output using chrt
and assuming that an active process is a running or a runnable process R
:
ps -e -o s,pid | grep ^R | awk 'system("chrt -p " $2)'
In case you want to get the output for all the processes (Running, Sleeping, Stopped & Zombie), you would like to use the following command:
ls /proc | grep -e ^[0-9] | awk 'system("chrt -p " $0)'|more
1
Actually you don't have to print all that.If you just run the commandchrt -p 8456
for example it has exactly the desirable result.My struggle is when i try to use thechrt
command for 2 or more processes.If you got any other ideas i'd be grateful.
â Spyros
Nov 29 '17 at 12:06
@Spyros I edited the answer to include the update you have requested. Assuming that an active process is arunning
or arunnable
process (State =R
).
â Karim Manaouil
Nov 29 '17 at 17:56
I didin't specify that i want to do that only for the current user and just for the active processes of that user.If you want to try that scenario you are free to do so.I found a solution i dont know if its optimal but i'll post it later in case someone faces the same problem.Thank you for your answer anyway.
â Spyros
Nov 30 '17 at 10:09
@Spyros You didn't mention all those details in your original description. You can actually do minor changes on theps
command above to fit your exact needs. However, posting your solution is a valuable share with the community.
â Karim Manaouil
Dec 1 '17 at 20:47
Manaouli I think I mentioned it was about active processes but I didn't mention clearly that they had to be user's processes only. Anyway thank you again for the time you spent answering.
â Spyros
Dec 1 '17 at 23:46
add a comment |Â
up vote
0
down vote
I've come up with the following command using ps
and awk
which gives very similar output with only a small difference in that it shows abbreviated names of the scheduling class. The following mapping could help you :
TS is SCHED_OTHER
RR is SCHED_RR
FF is SCHED_FIFO
The command:
ps -e -o s,pid,cls,pri | grep ^R | awk -v sq="'" 'print "pid",$2,sq,"s current scheduling policy:",$3,"npid",$2,sq,"s current priority:",$4'
Running the above command on my host gives the following output:
pid 8456 ' s current scheduling policy: TS
pid 8456 ' s current priority: 19
pid 12552 ' s current scheduling policy: TS
pid 12552 ' s current priority: 19
EDIT
Based on the comment, the following command gives an exact output using chrt
and assuming that an active process is a running or a runnable process R
:
ps -e -o s,pid | grep ^R | awk 'system("chrt -p " $2)'
In case you want to get the output for all the processes (Running, Sleeping, Stopped & Zombie), you would like to use the following command:
ls /proc | grep -e ^[0-9] | awk 'system("chrt -p " $0)'|more
1
Actually you don't have to print all that.If you just run the commandchrt -p 8456
for example it has exactly the desirable result.My struggle is when i try to use thechrt
command for 2 or more processes.If you got any other ideas i'd be grateful.
â Spyros
Nov 29 '17 at 12:06
@Spyros I edited the answer to include the update you have requested. Assuming that an active process is arunning
or arunnable
process (State =R
).
â Karim Manaouil
Nov 29 '17 at 17:56
I didin't specify that i want to do that only for the current user and just for the active processes of that user.If you want to try that scenario you are free to do so.I found a solution i dont know if its optimal but i'll post it later in case someone faces the same problem.Thank you for your answer anyway.
â Spyros
Nov 30 '17 at 10:09
@Spyros You didn't mention all those details in your original description. You can actually do minor changes on theps
command above to fit your exact needs. However, posting your solution is a valuable share with the community.
â Karim Manaouil
Dec 1 '17 at 20:47
Manaouli I think I mentioned it was about active processes but I didn't mention clearly that they had to be user's processes only. Anyway thank you again for the time you spent answering.
â Spyros
Dec 1 '17 at 23:46
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I've come up with the following command using ps
and awk
which gives very similar output with only a small difference in that it shows abbreviated names of the scheduling class. The following mapping could help you :
TS is SCHED_OTHER
RR is SCHED_RR
FF is SCHED_FIFO
The command:
ps -e -o s,pid,cls,pri | grep ^R | awk -v sq="'" 'print "pid",$2,sq,"s current scheduling policy:",$3,"npid",$2,sq,"s current priority:",$4'
Running the above command on my host gives the following output:
pid 8456 ' s current scheduling policy: TS
pid 8456 ' s current priority: 19
pid 12552 ' s current scheduling policy: TS
pid 12552 ' s current priority: 19
EDIT
Based on the comment, the following command gives an exact output using chrt
and assuming that an active process is a running or a runnable process R
:
ps -e -o s,pid | grep ^R | awk 'system("chrt -p " $2)'
In case you want to get the output for all the processes (Running, Sleeping, Stopped & Zombie), you would like to use the following command:
ls /proc | grep -e ^[0-9] | awk 'system("chrt -p " $0)'|more
I've come up with the following command using ps
and awk
which gives very similar output with only a small difference in that it shows abbreviated names of the scheduling class. The following mapping could help you :
TS is SCHED_OTHER
RR is SCHED_RR
FF is SCHED_FIFO
The command:
ps -e -o s,pid,cls,pri | grep ^R | awk -v sq="'" 'print "pid",$2,sq,"s current scheduling policy:",$3,"npid",$2,sq,"s current priority:",$4'
Running the above command on my host gives the following output:
pid 8456 ' s current scheduling policy: TS
pid 8456 ' s current priority: 19
pid 12552 ' s current scheduling policy: TS
pid 12552 ' s current priority: 19
EDIT
Based on the comment, the following command gives an exact output using chrt
and assuming that an active process is a running or a runnable process R
:
ps -e -o s,pid | grep ^R | awk 'system("chrt -p " $2)'
In case you want to get the output for all the processes (Running, Sleeping, Stopped & Zombie), you would like to use the following command:
ls /proc | grep -e ^[0-9] | awk 'system("chrt -p " $0)'|more
edited Nov 29 '17 at 18:21
answered Nov 28 '17 at 23:19
Karim Manaouil
1648
1648
1
Actually you don't have to print all that.If you just run the commandchrt -p 8456
for example it has exactly the desirable result.My struggle is when i try to use thechrt
command for 2 or more processes.If you got any other ideas i'd be grateful.
â Spyros
Nov 29 '17 at 12:06
@Spyros I edited the answer to include the update you have requested. Assuming that an active process is arunning
or arunnable
process (State =R
).
â Karim Manaouil
Nov 29 '17 at 17:56
I didin't specify that i want to do that only for the current user and just for the active processes of that user.If you want to try that scenario you are free to do so.I found a solution i dont know if its optimal but i'll post it later in case someone faces the same problem.Thank you for your answer anyway.
â Spyros
Nov 30 '17 at 10:09
@Spyros You didn't mention all those details in your original description. You can actually do minor changes on theps
command above to fit your exact needs. However, posting your solution is a valuable share with the community.
â Karim Manaouil
Dec 1 '17 at 20:47
Manaouli I think I mentioned it was about active processes but I didn't mention clearly that they had to be user's processes only. Anyway thank you again for the time you spent answering.
â Spyros
Dec 1 '17 at 23:46
add a comment |Â
1
Actually you don't have to print all that.If you just run the commandchrt -p 8456
for example it has exactly the desirable result.My struggle is when i try to use thechrt
command for 2 or more processes.If you got any other ideas i'd be grateful.
â Spyros
Nov 29 '17 at 12:06
@Spyros I edited the answer to include the update you have requested. Assuming that an active process is arunning
or arunnable
process (State =R
).
â Karim Manaouil
Nov 29 '17 at 17:56
I didin't specify that i want to do that only for the current user and just for the active processes of that user.If you want to try that scenario you are free to do so.I found a solution i dont know if its optimal but i'll post it later in case someone faces the same problem.Thank you for your answer anyway.
â Spyros
Nov 30 '17 at 10:09
@Spyros You didn't mention all those details in your original description. You can actually do minor changes on theps
command above to fit your exact needs. However, posting your solution is a valuable share with the community.
â Karim Manaouil
Dec 1 '17 at 20:47
Manaouli I think I mentioned it was about active processes but I didn't mention clearly that they had to be user's processes only. Anyway thank you again for the time you spent answering.
â Spyros
Dec 1 '17 at 23:46
1
1
Actually you don't have to print all that.If you just run the command
chrt -p 8456
for example it has exactly the desirable result.My struggle is when i try to use the chrt
command for 2 or more processes.If you got any other ideas i'd be grateful.â Spyros
Nov 29 '17 at 12:06
Actually you don't have to print all that.If you just run the command
chrt -p 8456
for example it has exactly the desirable result.My struggle is when i try to use the chrt
command for 2 or more processes.If you got any other ideas i'd be grateful.â Spyros
Nov 29 '17 at 12:06
@Spyros I edited the answer to include the update you have requested. Assuming that an active process is a
running
or a runnable
process (State = R
).â Karim Manaouil
Nov 29 '17 at 17:56
@Spyros I edited the answer to include the update you have requested. Assuming that an active process is a
running
or a runnable
process (State = R
).â Karim Manaouil
Nov 29 '17 at 17:56
I didin't specify that i want to do that only for the current user and just for the active processes of that user.If you want to try that scenario you are free to do so.I found a solution i dont know if its optimal but i'll post it later in case someone faces the same problem.Thank you for your answer anyway.
â Spyros
Nov 30 '17 at 10:09
I didin't specify that i want to do that only for the current user and just for the active processes of that user.If you want to try that scenario you are free to do so.I found a solution i dont know if its optimal but i'll post it later in case someone faces the same problem.Thank you for your answer anyway.
â Spyros
Nov 30 '17 at 10:09
@Spyros You didn't mention all those details in your original description. You can actually do minor changes on the
ps
command above to fit your exact needs. However, posting your solution is a valuable share with the community.â Karim Manaouil
Dec 1 '17 at 20:47
@Spyros You didn't mention all those details in your original description. You can actually do minor changes on the
ps
command above to fit your exact needs. However, posting your solution is a valuable share with the community.â Karim Manaouil
Dec 1 '17 at 20:47
Manaouli I think I mentioned it was about active processes but I didn't mention clearly that they had to be user's processes only. Anyway thank you again for the time you spent answering.
â Spyros
Dec 1 '17 at 23:46
Manaouli I think I mentioned it was about active processes but I didn't mention clearly that they had to be user's processes only. Anyway thank you again for the time you spent answering.
â Spyros
Dec 1 '17 at 23:46
add a comment |Â
up vote
0
down vote
accepted
I found two ways for doing it they may not be optimal but they get the job done.
#! /bin/bash
ps -u |grep [0-9]|awk 'print $2' > test.txt
cat test.txt |while read line
do
chrt -p $line 2 > /dev/null
done
2.
With this way you don't create unnecessary file.
ps -u|grep [0-9]|awk 'system("chrt -p" $2) 2 > /dev/null
add a comment |Â
up vote
0
down vote
accepted
I found two ways for doing it they may not be optimal but they get the job done.
#! /bin/bash
ps -u |grep [0-9]|awk 'print $2' > test.txt
cat test.txt |while read line
do
chrt -p $line 2 > /dev/null
done
2.
With this way you don't create unnecessary file.
ps -u|grep [0-9]|awk 'system("chrt -p" $2) 2 > /dev/null
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I found two ways for doing it they may not be optimal but they get the job done.
#! /bin/bash
ps -u |grep [0-9]|awk 'print $2' > test.txt
cat test.txt |while read line
do
chrt -p $line 2 > /dev/null
done
2.
With this way you don't create unnecessary file.
ps -u|grep [0-9]|awk 'system("chrt -p" $2) 2 > /dev/null
I found two ways for doing it they may not be optimal but they get the job done.
#! /bin/bash
ps -u |grep [0-9]|awk 'print $2' > test.txt
cat test.txt |while read line
do
chrt -p $line 2 > /dev/null
done
2.
With this way you don't create unnecessary file.
ps -u|grep [0-9]|awk 'system("chrt -p" $2) 2 > /dev/null
edited Dec 3 '17 at 17:14
answered Dec 2 '17 at 0:52
Spyros
1013
1013
add a comment |Â
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%2f407497%2fhow-to-find-scheduling-policy-and-active-processes-priority%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
For the schuduling policy, you can parse the output from /proc/pid/sched. I will try to write a script later
â Karim Manaouil
Nov 28 '17 at 19:01