Last Updated: February 25, 2016
·
1.764K
· kennu

Use pgrep and pkill instead of grepping ps output

Linux provides two handy commands for enumerating and signaling processes:

pgrep - look up processes by name and arguments (regexp)

pkill - send signals to processes with same criteria

So, instead of grepping and parsing the output of "ps aux", you can just type something like this to find the PID of the process you are looking for:

pgrep -f '[p]uppet agent --onetime'

And then, use the same options with pkill to send the signal.