Print processes, sorted by usage of CPU

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











up vote
5
down vote

favorite












I need to print the 10 processes that are using the most CPU. Also I need to print their ID, and the command they were started with.




What I've found is that the command ps -ax -u prints all the processes and their %CPU usage. The command ps -ax -u --sort pcpu prints all the processes sorted by the %CPU usage, from the least to the most, but I need to print only 10 processes from the most to the least. I have to use something like sort -r to make a reverse sorting, but the command ps -ax -u --sort -r pcpu produces an error.




So, how can I make a reverse sorting and print only 10 of the processes?










share|improve this question



























    up vote
    5
    down vote

    favorite












    I need to print the 10 processes that are using the most CPU. Also I need to print their ID, and the command they were started with.




    What I've found is that the command ps -ax -u prints all the processes and their %CPU usage. The command ps -ax -u --sort pcpu prints all the processes sorted by the %CPU usage, from the least to the most, but I need to print only 10 processes from the most to the least. I have to use something like sort -r to make a reverse sorting, but the command ps -ax -u --sort -r pcpu produces an error.




    So, how can I make a reverse sorting and print only 10 of the processes?










    share|improve this question

























      up vote
      5
      down vote

      favorite









      up vote
      5
      down vote

      favorite











      I need to print the 10 processes that are using the most CPU. Also I need to print their ID, and the command they were started with.




      What I've found is that the command ps -ax -u prints all the processes and their %CPU usage. The command ps -ax -u --sort pcpu prints all the processes sorted by the %CPU usage, from the least to the most, but I need to print only 10 processes from the most to the least. I have to use something like sort -r to make a reverse sorting, but the command ps -ax -u --sort -r pcpu produces an error.




      So, how can I make a reverse sorting and print only 10 of the processes?










      share|improve this question















      I need to print the 10 processes that are using the most CPU. Also I need to print their ID, and the command they were started with.




      What I've found is that the command ps -ax -u prints all the processes and their %CPU usage. The command ps -ax -u --sort pcpu prints all the processes sorted by the %CPU usage, from the least to the most, but I need to print only 10 processes from the most to the least. I have to use something like sort -r to make a reverse sorting, but the command ps -ax -u --sort -r pcpu produces an error.




      So, how can I make a reverse sorting and print only 10 of the processes?







      linux process sort cpu-usage






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 3 '17 at 13:51









      psmears

      43528




      43528










      asked Oct 3 '17 at 9:43









      Николай Журба

      284




      284




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          11
          down vote



          accepted











          to print 10 processes, that use the most CPU




          ps -aux --sort -pcpu | head




          Sorting syntax is [+|-]key[,[+|-]key[,...]].
          The "+" is
          optional since default direction is increasing numerical or
          lexicographic order. Identical to k. For example: ps jax --sort=uid,-ppid,+pid





          head - will print the first/top 10 lines of file(s) or standard input (by default)






          share|improve this answer


















          • 1




            And, for example, if I need not 10, but 15 lines, I will need to write head -n 15 ?
            – ÐÐ¸ÐºÐ¾Ð»Ð°Ð¹ Журба
            Oct 3 '17 at 10:04






          • 1




            @НиколайЖурба, that's right
            – RomanPerekhrest
            Oct 3 '17 at 10:04










          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%2f395796%2fprint-processes-sorted-by-usage-of-cpu%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
          11
          down vote



          accepted











          to print 10 processes, that use the most CPU




          ps -aux --sort -pcpu | head




          Sorting syntax is [+|-]key[,[+|-]key[,...]].
          The "+" is
          optional since default direction is increasing numerical or
          lexicographic order. Identical to k. For example: ps jax --sort=uid,-ppid,+pid





          head - will print the first/top 10 lines of file(s) or standard input (by default)






          share|improve this answer


















          • 1




            And, for example, if I need not 10, but 15 lines, I will need to write head -n 15 ?
            – ÐÐ¸ÐºÐ¾Ð»Ð°Ð¹ Журба
            Oct 3 '17 at 10:04






          • 1




            @НиколайЖурба, that's right
            – RomanPerekhrest
            Oct 3 '17 at 10:04














          up vote
          11
          down vote



          accepted











          to print 10 processes, that use the most CPU




          ps -aux --sort -pcpu | head




          Sorting syntax is [+|-]key[,[+|-]key[,...]].
          The "+" is
          optional since default direction is increasing numerical or
          lexicographic order. Identical to k. For example: ps jax --sort=uid,-ppid,+pid





          head - will print the first/top 10 lines of file(s) or standard input (by default)






          share|improve this answer


















          • 1




            And, for example, if I need not 10, but 15 lines, I will need to write head -n 15 ?
            – ÐÐ¸ÐºÐ¾Ð»Ð°Ð¹ Журба
            Oct 3 '17 at 10:04






          • 1




            @НиколайЖурба, that's right
            – RomanPerekhrest
            Oct 3 '17 at 10:04












          up vote
          11
          down vote



          accepted







          up vote
          11
          down vote



          accepted







          to print 10 processes, that use the most CPU




          ps -aux --sort -pcpu | head




          Sorting syntax is [+|-]key[,[+|-]key[,...]].
          The "+" is
          optional since default direction is increasing numerical or
          lexicographic order. Identical to k. For example: ps jax --sort=uid,-ppid,+pid





          head - will print the first/top 10 lines of file(s) or standard input (by default)






          share|improve this answer















          to print 10 processes, that use the most CPU




          ps -aux --sort -pcpu | head




          Sorting syntax is [+|-]key[,[+|-]key[,...]].
          The "+" is
          optional since default direction is increasing numerical or
          lexicographic order. Identical to k. For example: ps jax --sort=uid,-ppid,+pid





          head - will print the first/top 10 lines of file(s) or standard input (by default)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Oct 3 '17 at 10:05

























          answered Oct 3 '17 at 9:51









          RomanPerekhrest

          22.5k12145




          22.5k12145







          • 1




            And, for example, if I need not 10, but 15 lines, I will need to write head -n 15 ?
            – ÐÐ¸ÐºÐ¾Ð»Ð°Ð¹ Журба
            Oct 3 '17 at 10:04






          • 1




            @НиколайЖурба, that's right
            – RomanPerekhrest
            Oct 3 '17 at 10:04












          • 1




            And, for example, if I need not 10, but 15 lines, I will need to write head -n 15 ?
            – ÐÐ¸ÐºÐ¾Ð»Ð°Ð¹ Журба
            Oct 3 '17 at 10:04






          • 1




            @НиколайЖурба, that's right
            – RomanPerekhrest
            Oct 3 '17 at 10:04







          1




          1




          And, for example, if I need not 10, but 15 lines, I will need to write head -n 15 ?
          – ÐÐ¸ÐºÐ¾Ð»Ð°Ð¹ Журба
          Oct 3 '17 at 10:04




          And, for example, if I need not 10, but 15 lines, I will need to write head -n 15 ?
          – ÐÐ¸ÐºÐ¾Ð»Ð°Ð¹ Журба
          Oct 3 '17 at 10:04




          1




          1




          @НиколайЖурба, that's right
          – RomanPerekhrest
          Oct 3 '17 at 10:04




          @НиколайЖурба, that's right
          – RomanPerekhrest
          Oct 3 '17 at 10:04

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395796%2fprint-processes-sorted-by-usage-of-cpu%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