Posted: . At: 9:27 AM. This was 5 years ago. Post ID: 12936
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Search all processes for certain matches using wildcards.


The ps command lists all running processes on your Linux machine, this is how to fine-tune this and search for certain processes using wildcards.

Use this example command line to find all Apache HTTP server instances.

ps -ef | grep -i apache*

This is the output a user will get running this command.

4.4 Tue Feb 19 jason@Yog-Sothoth 0: $ ps -ef | grep -i apache*
root      1856     1  0 06:59 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  4872  1856  0 07:04 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  4873  1856  0 07:04 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  4874  1856  0 07:04 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  4875  1856  0 07:04 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  4876  1856  0 07:04 ?        00:00:00 /usr/sbin/apache2 -k start
jason     9113  5878  0 08:56 pts/0    00:00:00 grep -i apache*

To print just the process names and nothing else, use this command line.

4.4 Tue Feb 19 jason@Yog-Sothoth 0: $ ps -ef | grep -i apac* | awk '{ print $8 }'
/usr/sbin/apache2
/usr/sbin/apache2
/usr/sbin/apache2
/usr/sbin/apache2
/usr/sbin/apache2
/usr/sbin/apache2
grep

This is how to list all pid`s of the processes in question.

4.4 Tue Feb 19 jason@Yog-Sothoth 0: $ ps -ef | grep -i apac* | awk '{ print $2 }'
1856
4872
4873
4874
4875
4876
9709

Another way to do this, is by using this command.

4.4 Tue Feb 19 jason@Yog-Sothoth 0: $ pidof apache2 | tr ' ' '\n'
4876
4875
4874
4873
4872
1856

This is a very good way to get information about running processes and filter the output to find exactly what you are looking for.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.