In order to search for a process you can use ps
with grep
.
For example to search for firefox
ps aux | grep firefox
How to get the same answer without using grep
?
In order to search for a process you can use ps
with grep
.
For example to search for firefox
ps aux | grep firefox
How to get the same answer without using grep
?
The
pgrep
command, and its siblingpkill
, exists precisely for this purpose:pgrep firefox
will list all processes whose commands matchfirefox
pgrep -f firefox
will list all processes whose entire command lines matchfirefox
pgrep -x firefox
will list all processes whose commands exactly matchfirefox
And naturally,
pgrep
will exclude itself from the match, so none of thegrep
rituals associated withps | grep
are needed.The other set of tools for this are the
pidof
andkillall
commands. These aren't as flexible aspgrep
andpkill
.pidof firefox
will list processes whose command isfirefox
example:
from
man ps
top
allows you to search for string when you hit uppercaseL
; the process will be highlighted, and use up and down arrow keys to scroll through list of processes. Similarly,htop
command allows highlighting a particular process when you hit/
. And\
will filter all the processes with a particular string in the name.For those who like awk, here's an awk oneliner:
ps -eF | awk '/process-name/ {print $11}'
. Withps -eF
process name is always in 11th column. Alternatively if you dops -eF | awk '{print $11}' | sort
you get a sorted list of processes names, sorted alphabetically. Pipe it intoless
command just to view the long list of files easier.A cool trick
You will get all the processes with names
Redirect or so copy the output to a file and then open
nano
, press Ctrl+W and you can search for the name you want.You can also use
htop
and then hit F4 to filter the results with a matching user-defined string. You also have a custom search feature available by hitting F3.If two processes is the problem, you can use only grep:
If the reason you don't want to use
ps | grep
is because it loses the first line (the column headers), you can do:This is grepping for a line that contains
firefox
or a line that starts withUSER
(the first line of header line on my distro).I just read this ps alias on the Lennart Poettering Blog. The output is according to the systemd control group parenting: