用 pgrep 按名称查找进程的 PID

使用 pgrep -fl 可以按名称或命令行快速查出 macOS 上正在运行的进程 PID。

macOS进程终端低风险
在终端运行 pgrep -fl "Safari" 即可列出所有匹配进程的 PID 和名称。

01命令

命令
$ pgrep -fl "<name>"

02作用说明

pgrep 会在进程表中搜索并只输出匹配的 PID,输出比完整的 ps 列表干净得多。-f 让匹配范围覆盖完整命令行,当二进制名称与活动监视器里看到的不一致时特别有用;-l 则在 PID 旁边显示进程名,方便确认找对了进程。

03风险

风险低风险
!注意: pgrep 把参数当作正则表达式,并且会匹配子串:输入 vim 也会匹配 vimhelper。如需精确匹配进程名,可加 -x 参数。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • PKILL(1) / pgrep — macOS man page
    KEITH · technical · 2026-09-17
    依据: 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
    依据: 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.

最后验证: 2026-09-19 · 分类: 系统与设置

06相关方案