在 Ubuntu 下查看 Python 进程,常用方法有下面几种:
ps 命令ps aux | grep python
或更精确一点:
ps -ef | grep python
说明:
ps aux 显示所有进程grep python 过滤出 Python 相关进程grep python 自身,可加 grep -v grep 去掉示例:
ps aux | grep python | grep -v grep
pgrep 命令(推荐)pgrep -a python
或查看某个 Python 版本:
pgrep -a python3
-a 显示进程命令-atop / htoptop
然后按 Shift + M 按内存排序,或搜索 python
更友好:
htop
(如未安装:sudo apt install htop)
在 htop 中可直接搜索 python(按 F3)
ps aux | grep your_script.py
lsof(查看占用端口的 Python 进程)例如查看 8000 端口:
lsof -i:8000
cat /proc/1234/cmdline
或:
ps -p 1234 -o pid,ppid,cmd,%mem,%cpu
如果你是想:
可以告诉我具体场景,我可以给你更针对性的命令。