How to view a specific process in top












37















Are there any relatively strightforward options with top to track a specific process?

Ideally by identifying the process by a human readable value? e.g. chrome or java.



In other words, I want to view all the typical information top provides, but for the results to be filtered to the parameters provided i.e.. 'chrome' or 'java'










share|improve this question




















  • 1





    have you tried top | grep chrome?

    – Pandya
    Oct 31 '14 at 10:59






  • 1





    you can also use ps -x | chrome to get pid (let pid shown 2034) and then top | grep 2034

    – Pandya
    Oct 31 '14 at 11:02













  • top | grep chrome worked perfectly - thanks!

    – Michael Coleman
    Oct 31 '14 at 11:05











  • @Pandya - also, the process I was looking for only ran for a few seconds (node.js during an integration test) - which meant when I used ps -x | process_name to get the PID, when I ran the process again the PID was different and therefore the original PID wouldn't identify it.

    – Michael Coleman
    Oct 31 '14 at 11:15
















37















Are there any relatively strightforward options with top to track a specific process?

Ideally by identifying the process by a human readable value? e.g. chrome or java.



In other words, I want to view all the typical information top provides, but for the results to be filtered to the parameters provided i.e.. 'chrome' or 'java'










share|improve this question




















  • 1





    have you tried top | grep chrome?

    – Pandya
    Oct 31 '14 at 10:59






  • 1





    you can also use ps -x | chrome to get pid (let pid shown 2034) and then top | grep 2034

    – Pandya
    Oct 31 '14 at 11:02













  • top | grep chrome worked perfectly - thanks!

    – Michael Coleman
    Oct 31 '14 at 11:05











  • @Pandya - also, the process I was looking for only ran for a few seconds (node.js during an integration test) - which meant when I used ps -x | process_name to get the PID, when I ran the process again the PID was different and therefore the original PID wouldn't identify it.

    – Michael Coleman
    Oct 31 '14 at 11:15














37












37








37


9






Are there any relatively strightforward options with top to track a specific process?

Ideally by identifying the process by a human readable value? e.g. chrome or java.



In other words, I want to view all the typical information top provides, but for the results to be filtered to the parameters provided i.e.. 'chrome' or 'java'










share|improve this question
















Are there any relatively strightforward options with top to track a specific process?

Ideally by identifying the process by a human readable value? e.g. chrome or java.



In other words, I want to view all the typical information top provides, but for the results to be filtered to the parameters provided i.e.. 'chrome' or 'java'







process top






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 31 '14 at 23:12









Gilles

536k12810821600




536k12810821600










asked Oct 31 '14 at 10:43









Michael ColemanMichael Coleman

297136




297136








  • 1





    have you tried top | grep chrome?

    – Pandya
    Oct 31 '14 at 10:59






  • 1





    you can also use ps -x | chrome to get pid (let pid shown 2034) and then top | grep 2034

    – Pandya
    Oct 31 '14 at 11:02













  • top | grep chrome worked perfectly - thanks!

    – Michael Coleman
    Oct 31 '14 at 11:05











  • @Pandya - also, the process I was looking for only ran for a few seconds (node.js during an integration test) - which meant when I used ps -x | process_name to get the PID, when I ran the process again the PID was different and therefore the original PID wouldn't identify it.

    – Michael Coleman
    Oct 31 '14 at 11:15














  • 1





    have you tried top | grep chrome?

    – Pandya
    Oct 31 '14 at 10:59






  • 1





    you can also use ps -x | chrome to get pid (let pid shown 2034) and then top | grep 2034

    – Pandya
    Oct 31 '14 at 11:02













  • top | grep chrome worked perfectly - thanks!

    – Michael Coleman
    Oct 31 '14 at 11:05











  • @Pandya - also, the process I was looking for only ran for a few seconds (node.js during an integration test) - which meant when I used ps -x | process_name to get the PID, when I ran the process again the PID was different and therefore the original PID wouldn't identify it.

    – Michael Coleman
    Oct 31 '14 at 11:15








1




1





have you tried top | grep chrome?

– Pandya
Oct 31 '14 at 10:59





have you tried top | grep chrome?

– Pandya
Oct 31 '14 at 10:59




1




1





you can also use ps -x | chrome to get pid (let pid shown 2034) and then top | grep 2034

– Pandya
Oct 31 '14 at 11:02







you can also use ps -x | chrome to get pid (let pid shown 2034) and then top | grep 2034

– Pandya
Oct 31 '14 at 11:02















top | grep chrome worked perfectly - thanks!

– Michael Coleman
Oct 31 '14 at 11:05





top | grep chrome worked perfectly - thanks!

– Michael Coleman
Oct 31 '14 at 11:05













@Pandya - also, the process I was looking for only ran for a few seconds (node.js during an integration test) - which meant when I used ps -x | process_name to get the PID, when I ran the process again the PID was different and therefore the original PID wouldn't identify it.

– Michael Coleman
Oct 31 '14 at 11:15





@Pandya - also, the process I was looking for only ran for a few seconds (node.js during an integration test) - which meant when I used ps -x | process_name to get the PID, when I ran the process again the PID was different and therefore the original PID wouldn't identify it.

– Michael Coleman
Oct 31 '14 at 11:15










6 Answers
6






active

oldest

votes


















12














You can simply use grep:



NAME
grep, egrep, fgrep, rgrep - print lines matching a pattern

SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

DESCRIPTION
grep searches the named input FILEs (or standard input if no files are named, or if a single
hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By
default, grep prints the matching lines.


Run following command to get output which you want (ex-chrome):



top | grep chrome


Here we are using grep with pipelines | so top & grep run parallel ; top output given to grep (as input) and grep chrome filters matching lines chrome until top stopped.






share|improve this answer



















  • 1





    thanks, I know other people have their preferences, but I like this answer because it is easy to understand, and therefore its easier to remember in the future too! - I would have upvoted but I dont have enough reputation...

    – Michael Coleman
    Nov 1 '14 at 16:11













  • This only works if the process is in top's displayed output. I think @Ramesh's answer should be the accepted one

    – j b
    Aug 11 '17 at 12:18











  • @JamieBullock the question deals with top only and OP want to filter process based on top.

    – Pandya
    Aug 11 '17 at 13:26











  • @Pandya actually, I withdraw my previous comment as it was based on a mistake in my code. Still I think @Ramesh's answer is better (and also filters process based on top). I can easily break yours e.g. with sleep 10 & top | grep sleep

    – j b
    Aug 11 '17 at 13:41











  • I like unix.stackexchange.com/a/165343/48973 better because it shows the headers.

    – Ryan
    Jul 14 '18 at 17:12



















34














From my other answer here, you could do something like,



top -p `pgrep "java"`





share|improve this answer





















  • 3





    top -p `pgrep "java"` gives me the following error in a bash shell top: -p requires argument . top -p pgrep -d ',' "apache2" did work for me, but I didn't really understand what the command was doing - is it way of feeding in multiple arguments to top?

    – Michael Coleman
    Nov 1 '14 at 8:33













  • @Ramesh you need to give the pid list comma separated to work.

    – Kannan Mohan
    Nov 1 '14 at 13:33






  • 2





    This is the right answer.

    – j03m
    Aug 8 '16 at 13:51






  • 1





    +1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.

    – John M Naglick
    Jan 25 '17 at 16:36








  • 1





    @loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.

    – Michael Hays
    Nov 25 '18 at 15:28



















16














top -p `pgrep -d "," java`


Explanation:





  1. top -p pid1,pid2: show multiple process information, the pid should be separated by ,


  2. pgrep -d "," java: print the pids of all java program, the pids are separated by a newline by default. use the -d "," to separate it by , as required by the top.


If you see error like top: -p argument missing, it means no java program is running, i.e. the pgrep has no output.






share|improve this answer





















  • 1





    This solution works better than using top -p pgrep "java"`` only. thank you.

    – loretoparisi
    Sep 24 '18 at 8:26






  • 1





    Prevent the error by checking pgrep's exit code : pids="$(pgrep -d, java)" && top -p "$pids"

    – syme
    Nov 30 '18 at 16:42



















9














In OpenBSD top, just press g and enter the command name you'd like to filter on.



In top on e.g. Ubuntu, press o and enter e.g. COMMAND=chrome to only show entries from the COMMAND column that are equal to chrome.



On Linuxes that uses the same top implementation as Ubuntu, read the FILTERING in a Window section in the top manual.






share|improve this answer































    7














    Other good answers have been provided, but I made a script some time ago, which I named ptop, that serves me well:



    #!/bin/sh
    top -p $(pidof "$@" |sed s# #,#g) 2>/dev/null
    if [ $? -ne 0 ]; then
    echo No processes with the specified name(s) were found
    fi


    This supports multiple process names to be specified (like ptop bash chrome) and provides a nicer error message in case there is/are no processes with any of the specified names running.






    share|improve this answer

































      2














      If you want to stay in top and keep all other processes in view for context, you can press L to search for your process:



      Locate string chrome


      This will highlight any process with chrome in the name, and bring it into view. Use & to go to the next match.



      You can press c to switch between showing the process name and the full command.






      share|improve this answer


























      • This ^ because RTFM people! man top | less +/5d

        – cprn
        Oct 26 '18 at 14:09











      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      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%2f165214%2fhow-to-view-a-specific-process-in-top%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      12














      You can simply use grep:



      NAME
      grep, egrep, fgrep, rgrep - print lines matching a pattern

      SYNOPSIS
      grep [OPTIONS] PATTERN [FILE...]
      grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

      DESCRIPTION
      grep searches the named input FILEs (or standard input if no files are named, or if a single
      hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By
      default, grep prints the matching lines.


      Run following command to get output which you want (ex-chrome):



      top | grep chrome


      Here we are using grep with pipelines | so top & grep run parallel ; top output given to grep (as input) and grep chrome filters matching lines chrome until top stopped.






      share|improve this answer



















      • 1





        thanks, I know other people have their preferences, but I like this answer because it is easy to understand, and therefore its easier to remember in the future too! - I would have upvoted but I dont have enough reputation...

        – Michael Coleman
        Nov 1 '14 at 16:11













      • This only works if the process is in top's displayed output. I think @Ramesh's answer should be the accepted one

        – j b
        Aug 11 '17 at 12:18











      • @JamieBullock the question deals with top only and OP want to filter process based on top.

        – Pandya
        Aug 11 '17 at 13:26











      • @Pandya actually, I withdraw my previous comment as it was based on a mistake in my code. Still I think @Ramesh's answer is better (and also filters process based on top). I can easily break yours e.g. with sleep 10 & top | grep sleep

        – j b
        Aug 11 '17 at 13:41











      • I like unix.stackexchange.com/a/165343/48973 better because it shows the headers.

        – Ryan
        Jul 14 '18 at 17:12
















      12














      You can simply use grep:



      NAME
      grep, egrep, fgrep, rgrep - print lines matching a pattern

      SYNOPSIS
      grep [OPTIONS] PATTERN [FILE...]
      grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

      DESCRIPTION
      grep searches the named input FILEs (or standard input if no files are named, or if a single
      hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By
      default, grep prints the matching lines.


      Run following command to get output which you want (ex-chrome):



      top | grep chrome


      Here we are using grep with pipelines | so top & grep run parallel ; top output given to grep (as input) and grep chrome filters matching lines chrome until top stopped.






      share|improve this answer



















      • 1





        thanks, I know other people have their preferences, but I like this answer because it is easy to understand, and therefore its easier to remember in the future too! - I would have upvoted but I dont have enough reputation...

        – Michael Coleman
        Nov 1 '14 at 16:11













      • This only works if the process is in top's displayed output. I think @Ramesh's answer should be the accepted one

        – j b
        Aug 11 '17 at 12:18











      • @JamieBullock the question deals with top only and OP want to filter process based on top.

        – Pandya
        Aug 11 '17 at 13:26











      • @Pandya actually, I withdraw my previous comment as it was based on a mistake in my code. Still I think @Ramesh's answer is better (and also filters process based on top). I can easily break yours e.g. with sleep 10 & top | grep sleep

        – j b
        Aug 11 '17 at 13:41











      • I like unix.stackexchange.com/a/165343/48973 better because it shows the headers.

        – Ryan
        Jul 14 '18 at 17:12














      12












      12








      12







      You can simply use grep:



      NAME
      grep, egrep, fgrep, rgrep - print lines matching a pattern

      SYNOPSIS
      grep [OPTIONS] PATTERN [FILE...]
      grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

      DESCRIPTION
      grep searches the named input FILEs (or standard input if no files are named, or if a single
      hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By
      default, grep prints the matching lines.


      Run following command to get output which you want (ex-chrome):



      top | grep chrome


      Here we are using grep with pipelines | so top & grep run parallel ; top output given to grep (as input) and grep chrome filters matching lines chrome until top stopped.






      share|improve this answer













      You can simply use grep:



      NAME
      grep, egrep, fgrep, rgrep - print lines matching a pattern

      SYNOPSIS
      grep [OPTIONS] PATTERN [FILE...]
      grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

      DESCRIPTION
      grep searches the named input FILEs (or standard input if no files are named, or if a single
      hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By
      default, grep prints the matching lines.


      Run following command to get output which you want (ex-chrome):



      top | grep chrome


      Here we are using grep with pipelines | so top & grep run parallel ; top output given to grep (as input) and grep chrome filters matching lines chrome until top stopped.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 1 '14 at 9:57









      PandyaPandya

      8,7741552104




      8,7741552104








      • 1





        thanks, I know other people have their preferences, but I like this answer because it is easy to understand, and therefore its easier to remember in the future too! - I would have upvoted but I dont have enough reputation...

        – Michael Coleman
        Nov 1 '14 at 16:11













      • This only works if the process is in top's displayed output. I think @Ramesh's answer should be the accepted one

        – j b
        Aug 11 '17 at 12:18











      • @JamieBullock the question deals with top only and OP want to filter process based on top.

        – Pandya
        Aug 11 '17 at 13:26











      • @Pandya actually, I withdraw my previous comment as it was based on a mistake in my code. Still I think @Ramesh's answer is better (and also filters process based on top). I can easily break yours e.g. with sleep 10 & top | grep sleep

        – j b
        Aug 11 '17 at 13:41











      • I like unix.stackexchange.com/a/165343/48973 better because it shows the headers.

        – Ryan
        Jul 14 '18 at 17:12














      • 1





        thanks, I know other people have their preferences, but I like this answer because it is easy to understand, and therefore its easier to remember in the future too! - I would have upvoted but I dont have enough reputation...

        – Michael Coleman
        Nov 1 '14 at 16:11













      • This only works if the process is in top's displayed output. I think @Ramesh's answer should be the accepted one

        – j b
        Aug 11 '17 at 12:18











      • @JamieBullock the question deals with top only and OP want to filter process based on top.

        – Pandya
        Aug 11 '17 at 13:26











      • @Pandya actually, I withdraw my previous comment as it was based on a mistake in my code. Still I think @Ramesh's answer is better (and also filters process based on top). I can easily break yours e.g. with sleep 10 & top | grep sleep

        – j b
        Aug 11 '17 at 13:41











      • I like unix.stackexchange.com/a/165343/48973 better because it shows the headers.

        – Ryan
        Jul 14 '18 at 17:12








      1




      1





      thanks, I know other people have their preferences, but I like this answer because it is easy to understand, and therefore its easier to remember in the future too! - I would have upvoted but I dont have enough reputation...

      – Michael Coleman
      Nov 1 '14 at 16:11







      thanks, I know other people have their preferences, but I like this answer because it is easy to understand, and therefore its easier to remember in the future too! - I would have upvoted but I dont have enough reputation...

      – Michael Coleman
      Nov 1 '14 at 16:11















      This only works if the process is in top's displayed output. I think @Ramesh's answer should be the accepted one

      – j b
      Aug 11 '17 at 12:18





      This only works if the process is in top's displayed output. I think @Ramesh's answer should be the accepted one

      – j b
      Aug 11 '17 at 12:18













      @JamieBullock the question deals with top only and OP want to filter process based on top.

      – Pandya
      Aug 11 '17 at 13:26





      @JamieBullock the question deals with top only and OP want to filter process based on top.

      – Pandya
      Aug 11 '17 at 13:26













      @Pandya actually, I withdraw my previous comment as it was based on a mistake in my code. Still I think @Ramesh's answer is better (and also filters process based on top). I can easily break yours e.g. with sleep 10 & top | grep sleep

      – j b
      Aug 11 '17 at 13:41





      @Pandya actually, I withdraw my previous comment as it was based on a mistake in my code. Still I think @Ramesh's answer is better (and also filters process based on top). I can easily break yours e.g. with sleep 10 & top | grep sleep

      – j b
      Aug 11 '17 at 13:41













      I like unix.stackexchange.com/a/165343/48973 better because it shows the headers.

      – Ryan
      Jul 14 '18 at 17:12





      I like unix.stackexchange.com/a/165343/48973 better because it shows the headers.

      – Ryan
      Jul 14 '18 at 17:12













      34














      From my other answer here, you could do something like,



      top -p `pgrep "java"`





      share|improve this answer





















      • 3





        top -p `pgrep "java"` gives me the following error in a bash shell top: -p requires argument . top -p pgrep -d ',' "apache2" did work for me, but I didn't really understand what the command was doing - is it way of feeding in multiple arguments to top?

        – Michael Coleman
        Nov 1 '14 at 8:33













      • @Ramesh you need to give the pid list comma separated to work.

        – Kannan Mohan
        Nov 1 '14 at 13:33






      • 2





        This is the right answer.

        – j03m
        Aug 8 '16 at 13:51






      • 1





        +1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.

        – John M Naglick
        Jan 25 '17 at 16:36








      • 1





        @loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.

        – Michael Hays
        Nov 25 '18 at 15:28
















      34














      From my other answer here, you could do something like,



      top -p `pgrep "java"`





      share|improve this answer





















      • 3





        top -p `pgrep "java"` gives me the following error in a bash shell top: -p requires argument . top -p pgrep -d ',' "apache2" did work for me, but I didn't really understand what the command was doing - is it way of feeding in multiple arguments to top?

        – Michael Coleman
        Nov 1 '14 at 8:33













      • @Ramesh you need to give the pid list comma separated to work.

        – Kannan Mohan
        Nov 1 '14 at 13:33






      • 2





        This is the right answer.

        – j03m
        Aug 8 '16 at 13:51






      • 1





        +1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.

        – John M Naglick
        Jan 25 '17 at 16:36








      • 1





        @loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.

        – Michael Hays
        Nov 25 '18 at 15:28














      34












      34








      34







      From my other answer here, you could do something like,



      top -p `pgrep "java"`





      share|improve this answer















      From my other answer here, you could do something like,



      top -p `pgrep "java"`






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Apr 13 '17 at 12:36









      Community

      1




      1










      answered Oct 31 '14 at 23:20









      RameshRamesh

      23.6k34103184




      23.6k34103184








      • 3





        top -p `pgrep "java"` gives me the following error in a bash shell top: -p requires argument . top -p pgrep -d ',' "apache2" did work for me, but I didn't really understand what the command was doing - is it way of feeding in multiple arguments to top?

        – Michael Coleman
        Nov 1 '14 at 8:33













      • @Ramesh you need to give the pid list comma separated to work.

        – Kannan Mohan
        Nov 1 '14 at 13:33






      • 2





        This is the right answer.

        – j03m
        Aug 8 '16 at 13:51






      • 1





        +1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.

        – John M Naglick
        Jan 25 '17 at 16:36








      • 1





        @loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.

        – Michael Hays
        Nov 25 '18 at 15:28














      • 3





        top -p `pgrep "java"` gives me the following error in a bash shell top: -p requires argument . top -p pgrep -d ',' "apache2" did work for me, but I didn't really understand what the command was doing - is it way of feeding in multiple arguments to top?

        – Michael Coleman
        Nov 1 '14 at 8:33













      • @Ramesh you need to give the pid list comma separated to work.

        – Kannan Mohan
        Nov 1 '14 at 13:33






      • 2





        This is the right answer.

        – j03m
        Aug 8 '16 at 13:51






      • 1





        +1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.

        – John M Naglick
        Jan 25 '17 at 16:36








      • 1





        @loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.

        – Michael Hays
        Nov 25 '18 at 15:28








      3




      3





      top -p `pgrep "java"` gives me the following error in a bash shell top: -p requires argument . top -p pgrep -d ',' "apache2" did work for me, but I didn't really understand what the command was doing - is it way of feeding in multiple arguments to top?

      – Michael Coleman
      Nov 1 '14 at 8:33







      top -p `pgrep "java"` gives me the following error in a bash shell top: -p requires argument . top -p pgrep -d ',' "apache2" did work for me, but I didn't really understand what the command was doing - is it way of feeding in multiple arguments to top?

      – Michael Coleman
      Nov 1 '14 at 8:33















      @Ramesh you need to give the pid list comma separated to work.

      – Kannan Mohan
      Nov 1 '14 at 13:33





      @Ramesh you need to give the pid list comma separated to work.

      – Kannan Mohan
      Nov 1 '14 at 13:33




      2




      2





      This is the right answer.

      – j03m
      Aug 8 '16 at 13:51





      This is the right answer.

      – j03m
      Aug 8 '16 at 13:51




      1




      1





      +1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.

      – John M Naglick
      Jan 25 '17 at 16:36







      +1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.

      – John M Naglick
      Jan 25 '17 at 16:36






      1




      1





      @loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.

      – Michael Hays
      Nov 25 '18 at 15:28





      @loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.

      – Michael Hays
      Nov 25 '18 at 15:28











      16














      top -p `pgrep -d "," java`


      Explanation:





      1. top -p pid1,pid2: show multiple process information, the pid should be separated by ,


      2. pgrep -d "," java: print the pids of all java program, the pids are separated by a newline by default. use the -d "," to separate it by , as required by the top.


      If you see error like top: -p argument missing, it means no java program is running, i.e. the pgrep has no output.






      share|improve this answer





















      • 1





        This solution works better than using top -p pgrep "java"`` only. thank you.

        – loretoparisi
        Sep 24 '18 at 8:26






      • 1





        Prevent the error by checking pgrep's exit code : pids="$(pgrep -d, java)" && top -p "$pids"

        – syme
        Nov 30 '18 at 16:42
















      16














      top -p `pgrep -d "," java`


      Explanation:





      1. top -p pid1,pid2: show multiple process information, the pid should be separated by ,


      2. pgrep -d "," java: print the pids of all java program, the pids are separated by a newline by default. use the -d "," to separate it by , as required by the top.


      If you see error like top: -p argument missing, it means no java program is running, i.e. the pgrep has no output.






      share|improve this answer





















      • 1





        This solution works better than using top -p pgrep "java"`` only. thank you.

        – loretoparisi
        Sep 24 '18 at 8:26






      • 1





        Prevent the error by checking pgrep's exit code : pids="$(pgrep -d, java)" && top -p "$pids"

        – syme
        Nov 30 '18 at 16:42














      16












      16








      16







      top -p `pgrep -d "," java`


      Explanation:





      1. top -p pid1,pid2: show multiple process information, the pid should be separated by ,


      2. pgrep -d "," java: print the pids of all java program, the pids are separated by a newline by default. use the -d "," to separate it by , as required by the top.


      If you see error like top: -p argument missing, it means no java program is running, i.e. the pgrep has no output.






      share|improve this answer















      top -p `pgrep -d "," java`


      Explanation:





      1. top -p pid1,pid2: show multiple process information, the pid should be separated by ,


      2. pgrep -d "," java: print the pids of all java program, the pids are separated by a newline by default. use the -d "," to separate it by , as required by the top.


      If you see error like top: -p argument missing, it means no java program is running, i.e. the pgrep has no output.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jan 30 at 6:52

























      answered Feb 25 '17 at 16:03









      Mingjiang ShiMingjiang Shi

      26924




      26924








      • 1





        This solution works better than using top -p pgrep "java"`` only. thank you.

        – loretoparisi
        Sep 24 '18 at 8:26






      • 1





        Prevent the error by checking pgrep's exit code : pids="$(pgrep -d, java)" && top -p "$pids"

        – syme
        Nov 30 '18 at 16:42














      • 1





        This solution works better than using top -p pgrep "java"`` only. thank you.

        – loretoparisi
        Sep 24 '18 at 8:26






      • 1





        Prevent the error by checking pgrep's exit code : pids="$(pgrep -d, java)" && top -p "$pids"

        – syme
        Nov 30 '18 at 16:42








      1




      1





      This solution works better than using top -p pgrep "java"`` only. thank you.

      – loretoparisi
      Sep 24 '18 at 8:26





      This solution works better than using top -p pgrep "java"`` only. thank you.

      – loretoparisi
      Sep 24 '18 at 8:26




      1




      1





      Prevent the error by checking pgrep's exit code : pids="$(pgrep -d, java)" && top -p "$pids"

      – syme
      Nov 30 '18 at 16:42





      Prevent the error by checking pgrep's exit code : pids="$(pgrep -d, java)" && top -p "$pids"

      – syme
      Nov 30 '18 at 16:42











      9














      In OpenBSD top, just press g and enter the command name you'd like to filter on.



      In top on e.g. Ubuntu, press o and enter e.g. COMMAND=chrome to only show entries from the COMMAND column that are equal to chrome.



      On Linuxes that uses the same top implementation as Ubuntu, read the FILTERING in a Window section in the top manual.






      share|improve this answer




























        9














        In OpenBSD top, just press g and enter the command name you'd like to filter on.



        In top on e.g. Ubuntu, press o and enter e.g. COMMAND=chrome to only show entries from the COMMAND column that are equal to chrome.



        On Linuxes that uses the same top implementation as Ubuntu, read the FILTERING in a Window section in the top manual.






        share|improve this answer


























          9












          9








          9







          In OpenBSD top, just press g and enter the command name you'd like to filter on.



          In top on e.g. Ubuntu, press o and enter e.g. COMMAND=chrome to only show entries from the COMMAND column that are equal to chrome.



          On Linuxes that uses the same top implementation as Ubuntu, read the FILTERING in a Window section in the top manual.






          share|improve this answer













          In OpenBSD top, just press g and enter the command name you'd like to filter on.



          In top on e.g. Ubuntu, press o and enter e.g. COMMAND=chrome to only show entries from the COMMAND column that are equal to chrome.



          On Linuxes that uses the same top implementation as Ubuntu, read the FILTERING in a Window section in the top manual.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 8 '17 at 6:48









          KusalanandaKusalananda

          129k16243400




          129k16243400























              7














              Other good answers have been provided, but I made a script some time ago, which I named ptop, that serves me well:



              #!/bin/sh
              top -p $(pidof "$@" |sed s# #,#g) 2>/dev/null
              if [ $? -ne 0 ]; then
              echo No processes with the specified name(s) were found
              fi


              This supports multiple process names to be specified (like ptop bash chrome) and provides a nicer error message in case there is/are no processes with any of the specified names running.






              share|improve this answer






























                7














                Other good answers have been provided, but I made a script some time ago, which I named ptop, that serves me well:



                #!/bin/sh
                top -p $(pidof "$@" |sed s# #,#g) 2>/dev/null
                if [ $? -ne 0 ]; then
                echo No processes with the specified name(s) were found
                fi


                This supports multiple process names to be specified (like ptop bash chrome) and provides a nicer error message in case there is/are no processes with any of the specified names running.






                share|improve this answer




























                  7












                  7








                  7







                  Other good answers have been provided, but I made a script some time ago, which I named ptop, that serves me well:



                  #!/bin/sh
                  top -p $(pidof "$@" |sed s# #,#g) 2>/dev/null
                  if [ $? -ne 0 ]; then
                  echo No processes with the specified name(s) were found
                  fi


                  This supports multiple process names to be specified (like ptop bash chrome) and provides a nicer error message in case there is/are no processes with any of the specified names running.






                  share|improve this answer















                  Other good answers have been provided, but I made a script some time ago, which I named ptop, that serves me well:



                  #!/bin/sh
                  top -p $(pidof "$@" |sed s# #,#g) 2>/dev/null
                  if [ $? -ne 0 ]; then
                  echo No processes with the specified name(s) were found
                  fi


                  This supports multiple process names to be specified (like ptop bash chrome) and provides a nicer error message in case there is/are no processes with any of the specified names running.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 12 '17 at 23:13

























                  answered Nov 1 '14 at 10:20









                  MarceloMarcelo

                  2,361816




                  2,361816























                      2














                      If you want to stay in top and keep all other processes in view for context, you can press L to search for your process:



                      Locate string chrome


                      This will highlight any process with chrome in the name, and bring it into view. Use & to go to the next match.



                      You can press c to switch between showing the process name and the full command.






                      share|improve this answer


























                      • This ^ because RTFM people! man top | less +/5d

                        – cprn
                        Oct 26 '18 at 14:09
















                      2














                      If you want to stay in top and keep all other processes in view for context, you can press L to search for your process:



                      Locate string chrome


                      This will highlight any process with chrome in the name, and bring it into view. Use & to go to the next match.



                      You can press c to switch between showing the process name and the full command.






                      share|improve this answer


























                      • This ^ because RTFM people! man top | less +/5d

                        – cprn
                        Oct 26 '18 at 14:09














                      2












                      2








                      2







                      If you want to stay in top and keep all other processes in view for context, you can press L to search for your process:



                      Locate string chrome


                      This will highlight any process with chrome in the name, and bring it into view. Use & to go to the next match.



                      You can press c to switch between showing the process name and the full command.






                      share|improve this answer















                      If you want to stay in top and keep all other processes in view for context, you can press L to search for your process:



                      Locate string chrome


                      This will highlight any process with chrome in the name, and bring it into view. Use & to go to the next match.



                      You can press c to switch between showing the process name and the full command.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jun 26 '18 at 9:33

























                      answered Jun 26 '18 at 9:10









                      jonatanjonatan

                      1214




                      1214













                      • This ^ because RTFM people! man top | less +/5d

                        – cprn
                        Oct 26 '18 at 14:09



















                      • This ^ because RTFM people! man top | less +/5d

                        – cprn
                        Oct 26 '18 at 14:09

















                      This ^ because RTFM people! man top | less +/5d

                      – cprn
                      Oct 26 '18 at 14:09





                      This ^ because RTFM people! man top | less +/5d

                      – cprn
                      Oct 26 '18 at 14:09


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f165214%2fhow-to-view-a-specific-process-in-top%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                      is 'sed' thread safe

                      How to make a Squid Proxy server?