用 pgrep 按名称查找进程 PID
使用 pgrep -a 按名称查找正在运行程序的进程号(PID),并同时显示完整命令行。
运行 pgrep -a firefox,即可列出 Firefox 所有进程的 PID 及其完整启动命令。
01命令
命令
$ pgrep -a firefox02作用说明
pgrep 会在进程表中查找名称匹配的进程,并逐行输出对应的 PID。加上 -a(--list-full)参数后还会显示每个进程的完整命令行,方便区分同名进程;如果只要 PID 和进程名,可以用 -l;用 -f 则改为匹配整条命令行而不仅是进程名。
03风险
!注意: pgrep 按名称匹配,过短的关键词可能匹配到意料之外的进程;在发送信号之前,先用 pgrep -a 确认找到的确实是目标 PID。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- pgrep, pkill, pidwait - look up, signal, or wait for processes based on name and other attributes依据: "-a, --list-full List the full command line as well as the process ID. The process ID will be separated from the command line by a single space."
- Ubuntu Manpage: pgrep, pkill, pidwait - look up, signal, or wait for processes依据: The pgrep program displays "the process IDs of the selected processes"; -a/--list-full lists the full command line together with each PID.
最后验证: 2026-09-19 · 分类: 系统与设置