Linux下显示系统进程的命令ps,最常用的有 ps -ef 和 ps aux。这两个到底有什么区别呢?两者没太大差别,讨论这个问题,要追溯到Unix系统中的两种风格,System V风格 和 BSD 风格,ps aux最初用到Unix Style中,而ps -ef被用在System V Style中,两者输出略有不同。现在的大部分Linux系统都是可以同时使用这两种方式的。
ps -ef 是用标准的格式显示进程的、其格式如下:
UID PID PPID C STIME TTY TIME CMD
......
root 604 1 7 2月23 ? 2-12:45:35 /usr/bin/python3 /app/exporter/docker_exporter/docker_exporter.py
libstor+ 606 1 0 2月23 ? 00:00:11 /usr/bin/lsmd -d
kmsuat 607 1 0 2月23 ? 03:06:25 /app/jdk-17/bin/java -jar /app/jenkins/bin/jenkins-2.361.3.war --httpPort=8080 -Djava.awt.headless=true
root 687 1 0 2月23 ? 00:12:54 /usr/bin/python3 /app/exporter/oracle_exporter/oracle_exporter.py
kmsuat 688 1 16 2月23 ? 5-05:29:26 /app/prometheus/prometheus --config.file=/app/prometheus/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/app/prometheus/data --web.external-url=http:
root 1208 1 0 2月23 ? 00:00:00 /usr/sbin/sshd -D
kmsuat 1209 1 0 2月23 ? 01:00:02 /app/grafana-8.3.3/bin/grafana-server web --config=/app/grafana-8.3.3/conf/defaults.ini
root 1210 1 0 2月23 ? 00:46:25 /usr/sbin/snmpd -LS0-6d -f
root 1212 1 0 2月23 ? 02:28:52 /usr/bin/dockerd --config-file=/app/docker/etc/daemon.json
root 1216 1 0 2月23 ? 01:45:02 /usr/sbin/rsyslogd -n
root 1405 1212 0 2月23 ? 01:38:16 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd
......
kmsuat 32052 31996 0 15:06 ? 00:00:00 /usr/libexec/openssh/sftp-server
kmsuat 32065 31996 0 15:06 pts/1 00:00:00 -bash
kmsuat 32214 32065 0 15:06 pts/1 00:00:00 top
root 32215 2 0 10:20 ? 00:00:00 [kworker/5:2]
其中各列的内容意思如下:
UID //用户ID、但输出的是用户名
PID //进程的ID
PPID //父进程ID
C //进程占用CPU的百分比
STIME //进程启动到现在的时间
TTY //该进程在哪个终端上运行,若与终端无关,则显示? ;若为pts/0等,则表示由网络连接主机进程。
CMD //命令的名称和参数
ps aux 是用BSD的格式来显示、其格式如下:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
......
root 604 7.8 6.3 5529556 1033368 ? Ssl 2月23 3646:19 /usr/bin/python3 /app/exporter/docker_exporter/docker_exporter.py
polkitd 605 0.0 0.0 540556 12128 ? Ssl 2月23 0:34 /usr/lib/polkit-1/polkitd --no-debug
libstor+ 606 0.0 0.0 8580 832 ? Ss 2月23 0:11 /usr/bin/lsmd -d
kmsuat 607 0.4 27.7 10142016 4520112 ? Ssl 2月23 186:28 /app/jdk-17/bin/java -jar /app/jenkins/bin/jenkins-2.361.3.war --httpPort=8080 -Djava.awt.headless=true
root 626 0.1 0.0 225096 6116 ? Ss 2月23 63:51 /usr/bin/vmtoolsd
root 627 0.0 0.0 223928 5760 ? Ss 2月23 0:00 /usr/sbin/abrtd -d -s
root 632 0.0 0.0 26380 1784 ? Ss 2月23 0:52 /usr/lib/systemd/systemd-logind
root 635 0.6 0.2 716244 42284 ? Ssl 2月23 300:56 /usr/local/7xops-agent/LinuxDisruptor
root 636 0.0 0.1 305864 20392 ? Ss 2月23 20:52 /usr/bin/python3 /app/exporter/polardb_exporter/polardb_exporter.py
dbus 640 0.0 0.0 60160 2428 ? Ss 2月23 1:33 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
ntp 656 0.0 0.0 27804 2044 ? Ss 2月23 0:08 /usr/sbin/ntpd -u ntp:ntp -g
root 680 0.0 0.0 296184 14624 ? Ss 2月23 34:46 /usr/bin/python3 /app/exporter/otter_exporter/otter_exporter.py
......
同ps -ef 不同的有列有:
USER //用户名
%CPU //进程占用的CPU百分比
%MEM //占用内存的百分比
VSZ //该进程使用的虚拟內存量(KB)
RSS //该进程占用的固定內存量(KB)(驻留中页的数量)
STAT //进程的状态
START //该进程被触发启动时间
TIME //该进程实际使用CPU运行的时间
其中STAT状态位常见的状态字符有:
D //无法中断的休眠状态(通常 IO 的进程);
R //正在运行可中在队列中可过行的;
S //处于休眠状态;
T //停止或被追踪;
W //进入内存交换 (从内核2.6开始无效);
X //死掉的进程 (基本很少见);
Z //僵尸进程;
< //优先级高的进程
N //优先级较低的进程
L //有些页被锁进内存;
s //进程的领导者(在它之下有子进程);
l //多线程,克隆线程(使用 CLONE_THREAD, 类似 NPTL pthreads);
+ //位于后台的进程组;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)