Find a Process PID by Name with pgrep

Use pgrep -fl to instantly look up the PID of any running macOS process by matching its name or command line.

macOSProcessesTerminalLow risk
Run pgrep -fl "Safari" in Terminal to list the PIDs and names of every matching process.

01Command

Command
$ pgrep -fl "<name>"

02What it does

pgrep scans the process table and prints only the process IDs that match your pattern, without the noise of a full ps listing. The -f flag matches against the full command line, which helps when the binary name differs from what you see in Activity Monitor, and -l prints the process name alongside each PID so you can confirm you have the right one.

03Risk

RiskLow risk
!Warning: pgrep treats your pattern as a regular expression and also matches substrings; "vim" will match "vimhelper" too. Use -x to require an exact process-name match.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • PKILL(1) / pgrep — macOS man page
    KEITH · technical · 2026-09-17
    Evidence: The macOS man page for pgrep/pkill documents -l (long format, printing the process name next to the PID) and -f (match against full command line rather than just the process name).
  • pgrep(1) man page
    manpagez.com · technical · 2026-09-17
    Evidence: The page documents pgrep's -l option ("Long output. For pgrep, print the process name in addition to the process ID for each matching process") and the -f flag for matching against the full argument list.

Last verified: 2026-09-19 · Category: System & Settings

06Related solutions