I\'ve tried top | grep skype
for example but it doesn\'t work. I\'m trying to find a specific process by name.
Now you can use pgrep skype
to find the process.
Use this instead: ps -ax | grep -i skype
On Linux, the top
command supports the -p
option to monitor specific PIDs. On MacOS, the -p
option is called -pid
instead.
# Get the PID of the process
pgrep Skype
# Then
top -pid <put PID here>
# Or more succinctly:
top -pid `pgrep Skype`
If you do this a lot, you could turn this into a function and add it to ~/.bash_profile
:
# Add this to ~/.bash_profile
function topgrep() {
if [[ $# -ne 1 ]]; then
echo "Usage: topgrep <expression>"
else
top -pid `pgrep $1`
fi
}
Now you can simply use topgrep Skype
instead, which will run like usual but it will only show the process(es) matching expression
.
Tested on MacOSX Mojave. It works a bit different than linux.
top -pid
doesn't expect a comma separated list of pids, it expects only one pid. So I had to changed it a little to work with several pids.
top -pid $(pgrep -d' -pid ' -f Python)
filter all Python process on top. It essentially becomes something like this:
top -pid 123 -pid 836 -pid 654
Use: top -l 0 | grep Skype
The 0 is for infinite samples. You can also limit the number of samples to a positive number.
if you really love top, you could try:
top -b -n 1 | grep skype
e.g.
kent$ top -b -n 1 |grep dropbox
4039 kent 20 0 184m 14m 5464 S 0 0.4 0:58.30 dropbox