How to find scheduling policy and active processes' priority?

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this question






















  • 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














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.







share|improve this question






















  • 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












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.







share|improve this question














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.









share|improve this question













share|improve this question




share|improve this question








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
















  • 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










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





share|improve this answer


















  • 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










  • @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










  • @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

















up vote
0
down vote



accepted










I found two ways for doing it they may not be optimal but they get the job done.



  1. #! /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. 2.

With this way you don't create unnecessary file.



ps -u|grep [0-9]|awk 'system("chrt -p" $2) 2 > /dev/null






share|improve this answer






















    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%2f407497%2fhow-to-find-scheduling-policy-and-active-processes-priority%23new-answer', 'question_page');

    );

    Post as a guest






























    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





    share|improve this answer


















    • 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










    • @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










    • @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














    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





    share|improve this answer


















    • 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










    • @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










    • @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












    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





    share|improve this answer














    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






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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 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











    • 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










    • 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




      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











    • 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










    • 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












    up vote
    0
    down vote



    accepted










    I found two ways for doing it they may not be optimal but they get the job done.



    1. #! /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. 2.

    With this way you don't create unnecessary file.



    ps -u|grep [0-9]|awk 'system("chrt -p" $2) 2 > /dev/null






    share|improve this answer


























      up vote
      0
      down vote



      accepted










      I found two ways for doing it they may not be optimal but they get the job done.



      1. #! /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. 2.

      With this way you don't create unnecessary file.



      ps -u|grep [0-9]|awk 'system("chrt -p" $2) 2 > /dev/null






      share|improve this answer
























        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.



        1. #! /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. 2.

        With this way you don't create unnecessary file.



        ps -u|grep [0-9]|awk 'system("chrt -p" $2) 2 > /dev/null






        share|improve this answer














        I found two ways for doing it they may not be optimal but they get the job done.



        1. #! /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. 2.

        With this way you don't create unnecessary file.



        ps -u|grep [0-9]|awk 'system("chrt -p" $2) 2 > /dev/null







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 3 '17 at 17:14

























        answered Dec 2 '17 at 0:52









        Spyros

        1013




        1013



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            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