How to view a specific process in 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
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
536k12810821600
536k12810821600
asked Oct 31 '14 at 10:43
Michael ColemanMichael Coleman
297136
297136
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 |
6 Answers
6
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
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"`
3
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
2
This is the right answer.
– j03m
Aug 8 '16 at 13:51
1
+1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.
– John M Naglick
Jan 25 '17 at 16:36
1
@loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.
– Michael Hays
Nov 25 '18 at 15:28
|
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 |
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
6 Answers
6
active
oldest
votes
6 Answers
6
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
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
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
8,7741552104
8,7741552104
1
thanks, I know other people have their preferences, but I like this answer because it is easy to understand, and therefore its easier to remember in the future too! - I would have upvoted but I dont have enough reputation...
– Michael Coleman
Nov 1 '14 at 16:11
This only works if the process is in top's displayed output. I think @Ramesh's answer should be the accepted one
– j b
Aug 11 '17 at 12:18
@JamieBullock the question deals 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
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
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"`
3
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
2
This is the right answer.
– j03m
Aug 8 '16 at 13:51
1
+1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.
– John M Naglick
Jan 25 '17 at 16:36
1
@loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.
– Michael Hays
Nov 25 '18 at 15:28
|
show 1 more comment
From my other answer here, you could do something like,
top -p `pgrep "java"`
3
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
2
This is the right answer.
– j03m
Aug 8 '16 at 13:51
1
+1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.
– John M Naglick
Jan 25 '17 at 16:36
1
@loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.
– Michael Hays
Nov 25 '18 at 15:28
|
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
23.6k34103184
23.6k34103184
3
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
2
This is the right answer.
– j03m
Aug 8 '16 at 13:51
1
+1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.
– John M Naglick
Jan 25 '17 at 16:36
1
@loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.
– Michael Hays
Nov 25 '18 at 15:28
|
show 1 more comment
3
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
2
This is the right answer.
– j03m
Aug 8 '16 at 13:51
1
+1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.
– John M Naglick
Jan 25 '17 at 16:36
1
@loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.
– Michael Hays
Nov 25 '18 at 15:28
3
3
top -p `pgrep "java"`
gives me the following error in a bash shell top: -p requires argument
. top -p pgrep -d ',' "apache2"
did work for me, but I didn't really understand what the command was doing - is it way of feeding in multiple arguments to top?– Michael Coleman
Nov 1 '14 at 8:33
top -p `pgrep "java"`
gives me the following error in a bash shell top: -p requires argument
. top -p pgrep -d ',' "apache2"
did work for me, but I didn't really understand what the command was doing - is it way of feeding in multiple arguments to top?– Michael Coleman
Nov 1 '14 at 8:33
@Ramesh you need to give the
pid
list comma separated to work.– Kannan Mohan
Nov 1 '14 at 13:33
@Ramesh you need to give the
pid
list comma separated to work.– Kannan Mohan
Nov 1 '14 at 13:33
2
2
This is the right answer.
– j03m
Aug 8 '16 at 13:51
This is the right answer.
– j03m
Aug 8 '16 at 13:51
1
1
+1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.
– John M Naglick
Jan 25 '17 at 16:36
+1 This is the correct answer. "top | grep Chrome" is rather barbaric, because it greps-away ALL OF THE OUTPUT from top not matching "Chrome," losing stuff like the header and column labels. Using a subshell with the output from pgrep is a correct application of the unix philosophy.
– John M Naglick
Jan 25 '17 at 16:36
1
1
@loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.
– Michael Hays
Nov 25 '18 at 15:28
@loretoparisi that may be because the selector you are using matches multiple processes. See this answer for a command that works with one or more matching processes.
– Michael Hays
Nov 25 '18 at 15:28
|
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
KusalanandaKusalananda
129k16243400
129k16243400
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,361816
2,361816
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 |
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