How to view a specific process in top Announcing the arrival of Valued Associate #679: Cesar...

How can I make names more distinctive without making them longer?

What does '1 unit of lemon juice' mean in a grandma's drink recipe?

What are the pros and cons of Aerospike nosecones?

Why is black pepper both grey and black?

Stars Make Stars

Does accepting a pardon have any bearing on trying that person for the same crime in a sovereign jurisdiction?

do i need a schengen visa for a direct flight to amsterdam?

Disable hyphenation for an entire paragraph

Letter Boxed validator

How can players work together to take actions that are otherwise impossible?

Antler Helmet: Can it work?

How do I stop a creek from eroding my steep embankment?

Is there a "higher Segal conjecture"?

How widely used is the term Treppenwitz? Is it something that most Germans know?

Do I really need recursive chmod to restrict access to a folder?

How can I fade player character when he goes inside or outside of the area?

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

Why did the IBM 650 use bi-quinary?

Dominant seventh chord in the major scale contains diminished triad of the seventh?

Is the address of a local variable a constexpr?

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

Gastric acid as a weapon

Is there a concise way to say "all of the X, one of each"?

How to deal with a team lead who never gives me credit?



How to view a specific process in top



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionHow to use top with only showing CMD nameHow to select specific processes with 'top'?Queries about top commandMake top shows only server processHow can I kill the top CPU/IO process quickly?Unrealistically long process times displayed in topcpu usage is 100% but top doesn't show any process using itTracking/Monitoring Short-Lived CPU-Intensive Process on one CPUHow to use top in a shell script to track memory consumption of a process?What is the threshold for top to label a process as idleHow to kill a process in a top?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







39















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


















39















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














39












39








39


10






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

548k13011131631




548k13011131631










asked Oct 31 '14 at 10:43









Michael ColemanMichael Coleman

307137




307137








  • 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










8 Answers
8






active

oldest

votes


















15














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








  • 1





    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



















35














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



top -p `pgrep "java"`





share|improve this answer





















  • 4





    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






  • 3





    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



















12














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



















      0














      You can also use a filter in top to isolate specific processes. Press 'O' to bring up the filter prompt. Then type a filter formatted as FIELD=value. For example, to filter all tmux processes, use:



      COMMAND=tmux


      Use '=' to reset filters. See the section titled 'FILTERING' in the top man page.






      share|improve this answer































        -1














        Work for me:



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





        share|improve this answer








        New contributor




        Michael Lynn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





















        • This seems to identical to Ramesh's answer.

          – Kusalananda
          36 mins ago












        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

























        8 Answers
        8






        active

        oldest

        votes








        8 Answers
        8






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        15














        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








        • 1





          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
















        15














        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








        • 1





          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














        15












        15








        15







        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

        9,0931556107




        9,0931556107








        • 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








        • 1





          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








        • 1





          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






        1




        1





        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













        35














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



        top -p `pgrep "java"`





        share|improve this answer





















        • 4





          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






        • 3





          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
















        35














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



        top -p `pgrep "java"`





        share|improve this answer





















        • 4





          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






        • 3





          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














        35












        35








        35







        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

        24.1k34105188




        24.1k34105188








        • 4





          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






        • 3





          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














        • 4





          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






        • 3





          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








        4




        4





        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




        3




        3





        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











        12














        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




























          12














          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


























            12












            12








            12







            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

            142k18265440




            142k18265440























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




                    2,441817























                        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











                        0














                        You can also use a filter in top to isolate specific processes. Press 'O' to bring up the filter prompt. Then type a filter formatted as FIELD=value. For example, to filter all tmux processes, use:



                        COMMAND=tmux


                        Use '=' to reset filters. See the section titled 'FILTERING' in the top man page.






                        share|improve this answer




























                          0














                          You can also use a filter in top to isolate specific processes. Press 'O' to bring up the filter prompt. Then type a filter formatted as FIELD=value. For example, to filter all tmux processes, use:



                          COMMAND=tmux


                          Use '=' to reset filters. See the section titled 'FILTERING' in the top man page.






                          share|improve this answer


























                            0












                            0








                            0







                            You can also use a filter in top to isolate specific processes. Press 'O' to bring up the filter prompt. Then type a filter formatted as FIELD=value. For example, to filter all tmux processes, use:



                            COMMAND=tmux


                            Use '=' to reset filters. See the section titled 'FILTERING' in the top man page.






                            share|improve this answer













                            You can also use a filter in top to isolate specific processes. Press 'O' to bring up the filter prompt. Then type a filter formatted as FIELD=value. For example, to filter all tmux processes, use:



                            COMMAND=tmux


                            Use '=' to reset filters. See the section titled 'FILTERING' in the top man page.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Feb 28 at 20:06









                            Gearoid MurphyGearoid Murphy

                            20827




                            20827























                                -1














                                Work for me:



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





                                share|improve this answer








                                New contributor




                                Michael Lynn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.





















                                • This seems to identical to Ramesh's answer.

                                  – Kusalananda
                                  36 mins ago
















                                -1














                                Work for me:



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





                                share|improve this answer








                                New contributor




                                Michael Lynn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.





















                                • This seems to identical to Ramesh's answer.

                                  – Kusalananda
                                  36 mins ago














                                -1












                                -1








                                -1







                                Work for me:



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





                                share|improve this answer








                                New contributor




                                Michael Lynn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.










                                Work for me:



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






                                share|improve this answer








                                New contributor




                                Michael Lynn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.









                                share|improve this answer



                                share|improve this answer






                                New contributor




                                Michael Lynn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.









                                answered 2 hours ago









                                Michael LynnMichael Lynn

                                1




                                1




                                New contributor




                                Michael Lynn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.





                                New contributor





                                Michael Lynn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.






                                Michael Lynn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.













                                • This seems to identical to Ramesh's answer.

                                  – Kusalananda
                                  36 mins ago



















                                • This seems to identical to Ramesh's answer.

                                  – Kusalananda
                                  36 mins ago

















                                This seems to identical to Ramesh's answer.

                                – Kusalananda
                                36 mins ago





                                This seems to identical to Ramesh's answer.

                                – Kusalananda
                                36 mins ago


















                                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

                                Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                                Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                                Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...