ps [选项]
-e 显示所有进程,
e 列出程序时,显示环境变量
-f 全格式(显示UID,PPID ,C,STIME)
f 表达程序之间的关系
h 不显示标题
-l 或l 长格式
-w或w 宽输出
a 显示终端上的所有进程,包括其他用户的进程
u 以用户为主的格式显示
r 只显示正在运行的进程
x 显示没有控制终端的进程
-m或m 显示所有线程
====================================================================
# ps 查询自己正在执行的程序
PID TTY TIME CMD
25132 pts/1 00:00:00 su
25133 pts/1 00:00:00 bash
25789 pts/1 00:00:00 ps
# ps x 查询自己正在执行的所有程序(包括所有终端)
PID TTY STAT TIME COMMAND
1 ? Ss 0:01 init [3]
2 ? S< 0:00 [migration/0]
3 ? SN 0:00 [ksoftirqd/0]
……
2890 tty1 Ss+ 0:00 /sbin/mingetty tty1
2891 tty2 Ss+ 0:00 /sbin/mingetty tty2
2892 tty3 Ss+ 0:00 /sbin/mingetty tty3
2893 tty4 Ss+ 0:00 /sbin/mingetty tty4
2894 tty5 Ss+ 0:00 /sbin/mingetty tty5
2895 tty6 Ss+ 0:00 /sbin/mingetty tty6
# ps au 列出当前终端包括其他用户所执行的程序
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2890 0.0 0.1 1660 444 tty1 Ss+ 17:12 0:00 /sbin/mingetty tty1
root 2891 0.0 0.1 1660 424 tty2 Ss+ 17:12 0:00 /sbin/mingetty tty2
root 2892 0.0 0.1 1660 420 tty3 Ss+ 17:12 0:00 /sbin/mingetty tty3
root 2893 0.0 0.1 1660 424 tty4 Ss+ 17:12 0:00 /sbin/mingetty tty4
root 2894 0.0 0.1 1660 420 tty5 Ss+ 17:12 0:00 /sbin/mingetty tty5
root 2895 0.0 0.1 1660 424 tty6 Ss+ 17:12 0:00 /sbin/mingetty tty6
# ps aux 显示所有程序的执行进程
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 2068 616 ? Ss 17:11 0:01 init [3]
root 2 0.0 0.0 0 0 ? S< 17:11 0:00 [migration/0]
root 3 0.0 0.0 0 0 ? SN 17:11 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S< 17:11 0:00 [watchdog/0]
root 5 0.0 0.0 0 0 ? S< 17:11 0:00 [events/0]
root 6 0.0 0.0 0 0 ? S< 17:11 0:00 [khelper]
root 7 0.0 0.0 0 0 ? S< 17:11 0:00 [kthread]
root 10 0.0 0.0 0 0 ? S< 17:11 0:00 [kblockd/0]
root 11 0.0 0.0 0 0 ? S< 17:11 0:00 [kacpid]
root 176 0.0 0.0 0 0 ? S< 17:11 0:00 [cqueue/0]
……
====================================================
USER: 行程拥有者
PID: pid
%CPU: 占用的 CPU 使用率
%MEM: 占用的记忆体使用率
VSZ: 占用的虚拟记忆体大小
RSS: 占用的记忆体大小
TTY: 终端的次要装置号码 (minor device number of tty)
STAT: 该行程的状态: D: 不可中断的静止 R: 正在执行中 S: 静止状态 T: 暂停执行 Z: 不存在但暂时无法消除 W: 没有
足够的记忆体分页可分配 <: 高优先序的行程 N: 低优先序的行程 L: 有记忆体分页分配并锁在记忆体内 (即时系统或
捱A I/O)
START: 行程开始时间
TIME: 执行的时间
COMMAND:所执行的指令
====================================================
# ps axm 会把线程列出来
PID TTY STAT TIME COMMAND
1 ? - 0:01 init [3]
- - Ss 0:01 -
2 ? - 0:00 [migration/0]
- - S< 0:00 -
3 ? - 0:00 [ksoftirqd/0]
- - SN 0:00 -
4 ? - 0:00 [watchdog/0]
- - S< 0:00 -
5 ? - 0:00 [events/0]
在linux下进程和线程是统一的,是轻量级进程的两种方式。
# ps o "%U|%C|%G|%P|%a%c|%g|%n|%p|%r|%t|%u|%x|%y|%z" 自定义显示栏位
USER|%CPU|GROUP | PPID|COMMAND COMMAND |RGROUP | NI|PID| PGID|ELAPSED|RUSER | TIME|TTY|VSZ
root | 0.0|root | 1|/sbin/mingetty tty1 mingetty |root | 0| 2890| 2890| 05:27:28|root |00:00:00|tty1 |
1660
root | 0.0|root | 1|/sbin/mingetty tty2 mingetty |root | 0| 2891| 2891| 05:27:28|root |00:00:00|tty2 |
1660
root | 0.0|root | 1|/sbin/mingetty tty3 mingetty |root | 0| 2892| 2892| 05:27:28|root |00:00:00|tty3 |
1660
root | 0.0|root | 1|/sbin/mingetty tty4 mingetty |root | 0| 2893| 2893| 05:27:28|root |00:00:00|tty4 |
1660