Last active
April 13, 2023 10:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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