温馨提示×

如何查找特定进程

小樊
42
2026-09-24 20:22:28
栏目: 编程语言

查找特定进程的方法取决于你使用的操作系统。以下是常见系统中查找进程的几种方式:


一、Linux / macOS(命令行)

1. 使用 ps + grep

ps aux | grep 进程名

例如查找 nginx:

ps aux | grep nginx

2. 使用 pgrep(最直接)

pgrep -l 进程名

例如:

pgrep -l nginx

3. 使用 pidof

pidof 进程名

例如:

pidof nginx

4. 使用 top / htop(交互式)

top
# 或
htop

在界面中可按名称排序或搜索。


二、Windows

1. 任务管理器

  • Ctrl + Shift + Esc
  • 在“进程”或“详细信息”中查找

2. 命令提示符(CMD)

tasklist | findstr 进程名

例如:

tasklist | findstr chrome

3. PowerShell

Get-Process 进程名

例如:

Get-Process chrome

三、按端口反查进程(常用)

Linux / macOS

lsof -i :端口号
# 或
netstat -tunlp | grep 端口号

Windows

netstat -ano | findstr 端口号

再用 PID 查进程:

tasklist | findstr PID

四、编程方式(示例)

Python

import psutil

for p in psutil.process_iter(['name']):
    if 'nginx' in p.info['name']:
        print(p)

如果你能说明:

  • 使用的系统
  • 已知信息(进程名 / PID / 端口 / 用户)

我可以给你更精确的命令。

0 踩