Skip to content

Instantly share code, notes, and snippets.

@BigOokie
Last active April 13, 2023 10:58
Show Gist options
  • Save BigOokie/fea128a063e6e4e870cb4a246967a419 to your computer and use it in GitHub Desktop.
Save BigOokie/fea128a063e6e4e870cb4a246967a419 to your computer and use it in GitHub Desktop.
Use pgrep with regex patterns to identify specific processes and command line flags
Use the following pattern for `pgrep` to identify a running process that contains specific commandline parameters
Note the following pgrep options are needed:
-a, --list-full list PID and full command line
-f, --full use full process name to match
-c, --count count of matching processes
To find a specific process with a specific commandline parameter use the following:
pgrep -a -f "{processname}.*{commandline param}"
For example:
# This will likely return a number of results
pgrep -a -f "systemd"
# This will identify any instances of systemd where the --user commandline parameter was passed
pgrep -a -f "systemd.*user"
12207 /lib/systemd/systemd --user
To return the count of the number of running processes that match the pattern, add the -c option
For example:
pgrep -a -f -c "systemd.*user"
1
pgrep -a -f "you-wont-find-this-process"
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment