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;
}
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
add a comment |
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
1
have you triedtop | grep chrome
?
– Pandya
Oct 31 '14 at 10:59
1
you can also useps -x | chrome
to get pid (let pid shown2034
) and thentop | 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 usedps -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
add a comment |
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
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
process top
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 triedtop | grep chrome
?
– Pandya
Oct 31 '14 at 10:59
1
you can also useps -x | chrome
to get pid (let pid shown2034
) and thentop | 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 usedps -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
add a comment |
1
have you triedtop | grep chrome
?
– Pandya
Oct 31 '14 at 10:59
1
you can also useps -x | chrome
to get pid (let pid shown2034
) and thentop | 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 usedps -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
add a comment |
8 Answers
8
active
oldest
votes
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.
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 withtop
only and OP want to filter process based ontop
.
– 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. withsleep 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
|
show 1 more comment
From my other answer here, you could do something like,
top -p `pgrep "java"`
4
top -p `pgrep "java"`
gives me the following error in a bash shelltop: -p requires argument
. top -ppgrep -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 thepid
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
|
show 1 more comment
top -p `pgrep -d "," java`
Explanation:
top -p pid1,pid2
: show multiple process information, the pid should be separated by,
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.
1
This solution works better than usingtop -p
pgrep "java"`` only. thank you.
– loretoparisi
Sep 24 '18 at 8:26
1
Prevent the error by checkingpgrep
's exit code :pids="$(pgrep -d, java)" && top -p "$pids"
– syme
Nov 30 '18 at 16:42
add a comment |
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.
add a comment |
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.
add a comment |
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.
This ^ because RTFM people!man top | less +/5d
– cprn
Oct 26 '18 at 14:09
add a comment |
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.
add a comment |
Work for me:
top -p `pgrep -d ',' "java"`
New contributor
This seems to identical to Ramesh's answer.
– Kusalananda♦
36 mins ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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 withtop
only and OP want to filter process based ontop
.
– 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. withsleep 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
|
show 1 more comment
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.
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 withtop
only and OP want to filter process based ontop
.
– 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. withsleep 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
|
show 1 more comment
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.
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.
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 withtop
only and OP want to filter process based ontop
.
– 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. withsleep 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
|
show 1 more comment
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 withtop
only and OP want to filter process based ontop
.
– 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. withsleep 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
|
show 1 more comment
From my other answer here, you could do something like,
top -p `pgrep "java"`
4
top -p `pgrep "java"`
gives me the following error in a bash shelltop: -p requires argument
. top -ppgrep -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 thepid
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
|
show 1 more comment
From my other answer here, you could do something like,
top -p `pgrep "java"`
4
top -p `pgrep "java"`
gives me the following error in a bash shelltop: -p requires argument
. top -ppgrep -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 thepid
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
|
show 1 more comment
From my other answer here, you could do something like,
top -p `pgrep "java"`
From my other answer here, you could do something like,
top -p `pgrep "java"`
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 shelltop: -p requires argument
. top -ppgrep -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 thepid
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
|
show 1 more comment
4
top -p `pgrep "java"`
gives me the following error in a bash shelltop: -p requires argument
. top -ppgrep -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 thepid
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
|
show 1 more comment
top -p `pgrep -d "," java`
Explanation:
top -p pid1,pid2
: show multiple process information, the pid should be separated by,
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.
1
This solution works better than usingtop -p
pgrep "java"`` only. thank you.
– loretoparisi
Sep 24 '18 at 8:26
1
Prevent the error by checkingpgrep
's exit code :pids="$(pgrep -d, java)" && top -p "$pids"
– syme
Nov 30 '18 at 16:42
add a comment |
top -p `pgrep -d "," java`
Explanation:
top -p pid1,pid2
: show multiple process information, the pid should be separated by,
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.
1
This solution works better than usingtop -p
pgrep "java"`` only. thank you.
– loretoparisi
Sep 24 '18 at 8:26
1
Prevent the error by checkingpgrep
's exit code :pids="$(pgrep -d, java)" && top -p "$pids"
– syme
Nov 30 '18 at 16:42
add a comment |
top -p `pgrep -d "," java`
Explanation:
top -p pid1,pid2
: show multiple process information, the pid should be separated by,
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.
top -p `pgrep -d "," java`
Explanation:
top -p pid1,pid2
: show multiple process information, the pid should be separated by,
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.
edited Jan 30 at 6:52
answered Feb 25 '17 at 16:03
Mingjiang ShiMingjiang Shi
26924
26924
1
This solution works better than usingtop -p
pgrep "java"`` only. thank you.
– loretoparisi
Sep 24 '18 at 8:26
1
Prevent the error by checkingpgrep
's exit code :pids="$(pgrep -d, java)" && top -p "$pids"
– syme
Nov 30 '18 at 16:42
add a comment |
1
This solution works better than usingtop -p
pgrep "java"`` only. thank you.
– loretoparisi
Sep 24 '18 at 8:26
1
Prevent the error by checkingpgrep
'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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Oct 8 '17 at 6:48
Kusalananda♦Kusalananda
142k18265440
142k18265440
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Mar 12 '17 at 23:13
answered Nov 1 '14 at 10:20
MarceloMarcelo
2,441817
2,441817
add a comment |
add a comment |
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.
This ^ because RTFM people!man top | less +/5d
– cprn
Oct 26 '18 at 14:09
add a comment |
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.
This ^ because RTFM people!man top | less +/5d
– cprn
Oct 26 '18 at 14:09
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Feb 28 at 20:06
Gearoid MurphyGearoid Murphy
20827
20827
add a comment |
add a comment |
Work for me:
top -p `pgrep -d ',' "java"`
New contributor
This seems to identical to Ramesh's answer.
– Kusalananda♦
36 mins ago
add a comment |
Work for me:
top -p `pgrep -d ',' "java"`
New contributor
This seems to identical to Ramesh's answer.
– Kusalananda♦
36 mins ago
add a comment |
Work for me:
top -p `pgrep -d ',' "java"`
New contributor
Work for me:
top -p `pgrep -d ',' "java"`
New contributor
New contributor
answered 2 hours ago
Michael LynnMichael Lynn
1
1
New contributor
New contributor
This seems to identical to Ramesh's answer.
– Kusalananda♦
36 mins ago
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 shown2034
) and thentop | 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