Search code examples
bashpkill

Using pkill, how can I find out how many processes matched


We may not know how many processes actually died as a result of a pkill command, but is there a way to echo how many processes matched?

pkill -f "bin/ql_node_server"

is there a switch to pkill that will echo how many processes matched?

on MacOS, if I use the -c option with pkill, I get:

pkill: illegal option -- c
usage: pkill [-signal] [-ILfilnovx] [-F pidfile] [-G gid]
             [-P ppid] [-U uid] [-g pgrp]
             [-t tty] [-u euid] pattern ...

Solution

  • You can use -c flag.

    From man pkill:

    -c, --count Suppress normal output; instead print a count of matching processes. When count does not match anything, e.g. returns zero, the command will return non-zero value.