Linux ps 命令
Linux ps 命令
快速使用
root@jdit:~# ps -aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.3 167812 13484 ? Ss Mar20 0:38 /lib/systemd/systemd noibrs --system --deserialize 49 root 2 0.0 0.0 0 0 ? S Mar20 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< Mar20 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< Mar20 0:00 [rcu_par_gp] root 5 0.0 0.0 0 0 ? I< Mar20 0:00 [slub_flushwq] root 6 0.0 0.0 0 0 ? I< Mar20 0:00 [netns] root 8 0.0 0.0 0 0 ? I< Mar20 0:00 [kworker/0:0H-events_highpri] root 10 0.0 0.0 0 0 ? I< Mar20 0:00 [mm_percpu_wq] root 11 0.0 0.0 0 0 ? S Mar20 0:00 [rcu_tasks_rude_] root 12 0.0 0.0 0 0 ? S Mar20 0:00 [rcu_tasks_trace] root 13 0.0 0.0 0 0 ? S Mar20 0:01 [ksoftirqd/0] root 14 0.0 0.0 0 0 ? I Mar20 7:17 [rcu_sched] root 15 0.0 0.0 0 0 ? S Mar20 0:04 [migration/0] root 16 0.0 0.0 0 0 ? S Mar20 0:00 [idle_inject/0] root 18 0.0 0.0 0 0 ? S Mar20 0:00 [cpuhp/0] root 19 0.0 0.0 0 0 ? S Mar20 0:00 [cpuhp/1] root 20 0.0 0.0 0 0 ? S Mar20 0:00 [idle_inject/1] root 21 0.0 0.0 0 0 ? S Mar20 0:04 [migration/1] root 22 0.0 0.0 0 0 ? S Mar20 0:01 [ksoftirqd/1] root 24 0.0 0.0 0 0 ? I< Mar20 0:00 [kworker/1:0H-events_highpri] root 25 0.0 0.0 0 0 ? S Mar20 0:00 [kdevtmpfs] root 26 0.0 0.0 0 0 ? I< Mar20 0:00 [inet_frag_wq] root 27 0.0 0.0 0 0 ? S Mar20 0:00 [kauditd] root 29 0.0 0.0 0 0 ? S Mar20 0:00 [khungtaskd] root 30 0.0 0.0 0 0 ? S Mar20 0:00 [oom_reaper] root 31 0.0 0.0 0 0 ? I< Mar20 0:00 [writeback] root 32 0.0 0.0 0 0 ? S Mar20 0:41 [kcompactd0] root 33 0.0 0.0 0 0 ? SN Mar20 0:00 [ksmd]
简介
这个是进程管理的核心命令,必须熟练掌握
Linux ps (英文全拼:process status)命令用于显示当前进程的状态,类似于 windows 的任务管理器。
语法
ps [options] [--help]
参数:
-
ps 的参数非常多, 在此仅列出几个常用的参数并大略介绍含义
-
-A 列出所有的进程
-
-w 显示加宽可以显示较多的资讯
-
-au 显示较详细的资讯
-
-aux 显示所有包含其他使用者的进程
-
au(x) 输出格式 :
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND - USER: 行程拥有者
- PID: pid
- %CPU: 占用的 CPU 使用率
- %MEM: 占用的记忆体使用率
- VSZ: 占用的虚拟记忆体大小
- RSS: 占用的记忆体大小
- TTY: 终端的次要装置号码 (minor device number of tty)
- STAT: 该行程的状态:
- D: 无法中断的休眠状态 (通常 IO 的进程)
- R: 正在执行中
- S: 静止状态
- T: 暂停执行
- Z: 不存在但暂时无法消除
- W: 没有足够的记忆体分页可分配
- <: 高优先序的行程
- N: 低优先序的行程
- L: 有记忆体分页分配并锁在记忆体内 (实时系统或捱A I/O)
- START: 行程开始时间
- TIME: 执行的时间
- COMMAND:所执行的指令
实例
查找指定进程格式:
ps -ef | grep 进程关键字
例如显示 php 的进程:
# ps -ef | grep php root 794 1 0 2020 ? 00:00:52 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf) www-data 951 794 0 2020 ? 00:24:15 php-fpm: pool www www-data 953 794 0 2020 ? 00:24:14 php-fpm: pool www www-data 954 794 0 2020 ? 00:24:29 php-fpm: pool www ...
显示进程信息:
# ps -A PID TTY TIME CMD 1 ? 00:00:02 init 2 ? 00:00:00 kthreadd 3 ? 00:00:00 migration/0 4 ? 00:00:00 ksoftirqd/0 5 ? 00:00:00 watchdog/0 6 ? 00:00:00 events/0 7 ? 00:00:00 cpuset 8 ? 00:00:00 khelper 9 ? 00:00:00 netns 10 ? 00:00:00 async/mgr 11 ? 00:00:00 pm 12 ? 00:00:00 sync_supers 13 ? 00:00:00 bdi-default 14 ? 00:00:00 kintegrityd/0 15 ? 00:00:02 kblockd/0 16 ? 00:00:00 kacpid 17 ? 00:00:00 kacpi_notify 18 ? 00:00:00 kacpi_hotplug 19 ? 00:00:27 ata/0 ……省略部分结果 30749 pts/0 00:00:15 gedit 30886 ? 00:01:10 qtcreator.bin 30894 ? 00:00:00 qtcreator.bin 31160 ? 00:00:00 dhclient 31211 ? 00:00:00 aptd 31302 ? 00:00:00 sshd 31374 pts/2 00:00:00 bash 31396 pts/2 00:00:00 ps
显示指定用户信息
# ps -u root //显示root进程用户信息 PID TTY TIME CMD 1 ? 00:00:02 init 2 ? 00:00:00 kthreadd 3 ? 00:00:00 migration/0 4 ? 00:00:00 ksoftirqd/0 5 ? 00:00:00 watchdog/0 6 ? 00:00:00 events/0 7 ? 00:00:00 cpuset 8 ? 00:00:00 khelper 9 ? 00:00:00 netns 10 ? 00:00:00 async/mgr 11 ? 00:00:00 pm 12 ? 00:00:00 sync_supers 13 ? 00:00:00 bdi-default 14 ? 00:00:00 kintegrityd/0 15 ? 00:00:02 kblockd/0 16 ? 00:00:00 kacpid ……省略部分结果 30487 ? 00:00:06 gnome-terminal 30488 ? 00:00:00 gnome-pty-helpe 30489 pts/0 00:00:00 bash 30670 ? 00:00:00 debconf-communi 30749 pts/0 00:00:15 gedit 30886 ? 00:01:10 qtcreator.bin 30894 ? 00:00:00 qtcreator.bin 31160 ? 00:00:00 dhclient 31211 ? 00:00:00 aptd 31302 ? 00:00:00 sshd 31374 pts/2 00:00:00 bash 31397 pts/2 00:00:00 ps
显示所有进程信息,连同命令行
# ps -ef //显示所有命令,连带命令行 UID PID PPID C STIME TTY TIME CMD root 1 0 0 10:22 ? 00:00:02 /sbin/init root 2 0 0 10:22 ? 00:00:00 [kthreadd] root 3 2 0 10:22 ? 00:00:00 [migration/0] root 4 2 0 10:22 ? 00:00:00 [ksoftirqd/0] root 5 2 0 10:22 ? 00:00:00 [watchdog/0] root 6 2 0 10:22 ? /usr/lib/NetworkManager ……省略部分结果 root 31302 2095 0 17:42 ? 00:00:00 sshd: root@pts/2 root 31374 31302 0 17:42 pts/2 00:00:00 -bash root 31400 1 0 17:46 ? 00:00:00 /usr/bin/python /usr/sbin/aptd root 31407 31374 0 17:48 pts/2 00:00:00 ps -ef
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· 单线程的Redis速度为什么快?
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码