Linux ps命令

发布时间:2026/10/5 14:36:59
Linux ps命令 目录一. 简介二. 示例2.1 ps -ef ⇒ 显示所有进程的详细信息2.2 ps -ef | grep nginx ⇒ 显示nginx相关的所有进程的详细信息2.3 ps -p PID ⇒ 显示指定PID的进程信息2.4 ps aux --sort-%cpu ⇒ 按CPU使用量排序2.5 ps aux --sort-%mem ⇒ 按内存使用量排序三. 过滤grep自身进程一. 简介用于显示系统中当前运行的进程信息。提供了查看进程的不同视图和选项允许用户了解系统上正在运行的进程的状态、资源使用情况等。-e显示所有进程而不仅仅是与当前终端关联的进程。-f以完整的格式显示进程信息包括进程的详细信息如进程的状态、PID进程ID、PPID父进程ID、CCPU利用率、STIME启动时间、TTY终端类型、TIME执行的累计CPU时间、CMD进程的命令等。-a显示其他用户拥有的进程。例如你当前用户是spluser如果没有-a通常只显示与当前用户相关的进程加上-a后可以看到其他用户的进程。-u以用户友好的格式显示把进程显示成比较容易阅读的形式。-u⇒user-oriented format。x显示没有终端的进程Linux 中很多后台服务没有 TTY/终端如果没有x这类进程可能不会显示。二. 示例2.1ps -ef⇒ 显示所有进程的详细信息2.2ps -ef | grep nginx⇒ 显示nginx相关的所有进程的详细信息2.3ps -p PID⇒ 显示指定PID的进程信息2.4ps aux --sort-%cpu⇒ 按CPU使用量排序apluserubuntu22-1:~$psaux--sort-%cpu|headUSERPID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDgit108211.711.22930332908112? Sl Aug1398:32 sidekiq7.3.9 queues:default,mailers[0of20busy]git2460683.811.42256424921792? Sl 08:380:19 puma: cluster worker2:719[gitlab-puma-worker]git2460593.411.62273384941492? Sl 08:380:17 puma: cluster worker0:719[gitlab-puma-worker]git2460633.411.32260456919992? Sl 08:380:17 puma: cluster worker1:719[gitlab-puma-worker]git2460723.411.42267048927324? Sl 08:380:17 puma: cluster worker3:719[gitlab-puma-worker]git2460763.411.72292136950492? Sl 08:380:17 puma: cluster worker5:719[gitlab-puma-worker]git2382031.812.32449988997188? Sl 08:110:39 puma: cluster worker4:719[gitlab-puma-worker]gitlab-11911.11.0221281282064? Ss Aug139:39 postgres: gitlab-psql gitlabhq_production[local]idle gitlab-7401.00.3207901229016? Ssl Aug139:10 /opt/gitlab/embedded/bin/postgres_exporter --no-collector.stat_user_tables--collector.postmaster--web.listen-addresslocalhost:9187 --extend.query-path/var/opt/gitlab/postgres-exporter/queries.yaml apluserubuntu22-1:~$2.5ps aux --sort-%mem⇒ 按内存使用量排序apluserubuntu22-1:~$psaux--sort-%mem|headUSERPID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDgit2382031.612.32469444994108? Sl 08:110:41 puma: cluster worker4:719[gitlab-puma-worker]git2460682.311.92332712967744? Sl 08:380:21 puma: cluster worker2:719[gitlab-puma-worker]git2460762.011.92316712966892? Sl 08:380:19 puma: cluster worker5:719[gitlab-puma-worker]git2460722.111.82311080954420? Sl 08:380:19 puma: cluster worker3:719[gitlab-puma-worker]git2460592.211.72342312949336? Sl 08:380:20 puma: cluster worker0:719[gitlab-puma-worker]git2460632.011.62286760938596? Sl 08:380:19 puma: cluster worker1:719[gitlab-puma-worker]git108211.711.22930332910068? Sl Aug1399:22 sidekiq7.3.9 queues:default,mailers[0of20busy]git7190.26.72064596548916? Ssl Aug132:18 puma7.2.0(unix:///var/opt/gitlab/gitlab-rails/sockets/gitlab.socket,tcp://127.0.0.1:8080)[gitlab-puma-worker]jenkins3200.34.17860116331548? Ssl Aug133:20 /usr/bin/java-Djava.awt.headlesstrue-jar/usr/share/java/jenkins.war--webroot/var/cache/jenkins/war--httpPort8082apluserubuntu22-1:~$三. 过滤grep自身进程⏹我们在查询进程时往往会使用grep命令进一步缩小范围但是此时往往会将grep自身的进程也显示出来grep --colorauto sshdgrep命令自身的进程apluserubuntu24-01:~$ps-ef|grepsshdroot2044510Dec28 ? 00:00:00 sshd: /usr/sbin/sshd-D[listener]0of10-100 startups root3897920445001:47 ? 00:00:00 sshd: apluser[priv]apluser3908038979001:47 ? 00:00:00 sshd: aplusernotty root3961220445005:03 ? 00:00:00 sshd: apluser[priv]apluser3971139612005:03 ? 00:00:00 sshd: apluserpts/0 apluser3980139712005:39 pts/0 00:00:00grep--colorauto sshd⏹可通过下面这两种方式过滤grep自身的进程ps -ef | grep sshd | grep -v grep从查询结果中过滤掉grep关键词。ps -ef | grep [s]shd[s]shd的正则表达式仍然匹配sshd但因为 grep 自身的命令行是grep [s]shd而不是sshd不会匹配到自身的进程。

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询