How would you get a count of processes with ‘named’ in the command name

ps auxw | grep named | grep -v grep | wc -l

A fairly bog standard answer. It works OK and shows some knowledge of the problem of picking up grep. The “wc” could be avoided with the “-c” flag on grep, but another pipe to do that job is the unix way.

Good answers

ps auxw | grep -cw [n]amed

A neat answer to avoid picking up the grep command, which won’t have “named” on the command line, and counting the number of processes without “wc”.

pgrep named | wc -l

Avoids a lot of the problems caused by piping things through grep. The extra flags for pgrep (such as the user the command is running as) may be useful too.