The -C option can be used with ps to display certain processes:
$ ps -C httpd PID TTY TIME CMD 726 ? 00:00:00 httpd 732 ? 00:00:00 httpd 6064 ? 00:00:00 httpd 19452 ? 00:00:00 httpd 21047 ? 00:00:00 httpd 21048 ? 00:00:00 httpd 21049 ? 00:00:00 httpd 21060 ? 00:00:00 httpd 30127 ? 00:00:00 httpd 31629 ? 00:00:00 httpd 32380 ? 00:00:00 httpd 32381 ? 00:00:00 httpd 32620 ? 00:00:00 httpd 532 ? 00:00:00 httpd 533 ? 00:00:00 httpd 544 ? 00:00:00 httpd 1699 ? 00:00:00 httpd 1774 ? 00:00:00 httpd 2686 ? 00:00:00 httpd 3427 ? 00:00:00 httpd 3429 ? 00:00:00 httpd 3430 ? 00:00:00 httpd 12571 ? 00:00:00 httpd 12573 ? 00:00:00 httpd 12574 ? 00:00:00 httpd $ |
Run this through wc to count the processes:
$ ps -C httpd h | wc -l 24 $ |
The h option doesn’t print the header, so the count is correct. The -l option for wc just prints the number of lines. Add this line to your .bashrc file to get an alias to count these processes:
alias ch="ps -C httpd h | wc -l"; |
and you can then just type ch to count the httpd processes.