首页 首页 >  文章资讯

ubuntu下使用ps查看进程信息

发布时间:2023-08-12 09:31:27 浏览次数:79次

一、ps常用命令组合

  1. ps 查看当前终端下运行的所有进程信息
  2. ps aux 查看linux下所有的进程信息
  3. ps -aux 查看linux下用户名为x所拥有的进程信息,如ps -auname表示查看linux下用户名为name所拥有的进程信息
  4. 其它选项
  • a 列出所有含有终端的进程
  • u 列出当前用户的所有含有终端的进程,并显示进程的用户信息
  • x 列出当前用户的所有进程信息
  • e 显示环境变量
  • -L显示当前用户的线程信息,如ps -L

二、在进程中搜索某个特定进程

  • 格式:ps [选项] | grep [条件]
  • 示例1:ps aux | grep 3495 在所有进程中查找并显示进程号为3495或者包含3495的进程
  • 示例2:ps aux | grep tcp_server 在所有进程中查找并显示包含mylinux字段的所有进程

三、进程信息名词解释

在shell终端输入ps aux会打印如下内容:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MxbTLbUS-1597411319820)(23ACE84AC87B42F7AD692115A775AC49)]

  1. USER 进程所有者,root表示管理员
  2. pid 进程pid
  3. %CPU 进程的cpu占用率
  4. VSZ 进程占用的虚拟内存大小
  5. RSS 进程占用的实际内存大小
  6. TTY 设备终端号,?表示当前进程没有终端
  7. STAT 进程的状态
  8. START 进程的运行时间,使用ps aux的时间格式为HH:MM,图中的TIME为0:00表示进程的运行时间不足一分钟
  9. COMMAND 执行程序的参数和命令?

四、程序运行状态STAT的值和含义

在上图中我们知道STAT表示程序的运行状态,其中Ss表示该进程处于休眠状态并且拥有子进程,S<表示该进程处于休眠状态并且优先级较高。具体值锁代表的含义如下:

   Here are the different values that the s, stat and state outputspecifiers (header "STAT" or "S") will display to describe the state ofa process:D    uninterruptible sleep (usually IO)R    running or runnable (on run queue)S    interruptible sleep (waiting for an event to complete)T    stopped by job control signalt    stopped by debugger during the tracingW    paging (not valid since the 2.6.xx kernel)X    dead (should never be seen)Z    defunct ("zombie") process, terminated but not reaped byits parentFor BSD formats and when the stat keyword is used, additionalcharacters may be displayed:<    high-priority (not nice to other users)N    low-priority (nice to other users)L    has pages locked into memory (for real-time and custom IO)s    is a session leaderl    is multi-threaded (using CLONE_THREAD, like NPTL pthreadsdo)+    is in the foreground process group

D uninterruptible sleep

进程处于不可打断的睡眠状态,处于该状态的进程不能被外部信号唤醒,通常是等待某些IO操作完成

R running or runnable (on run queue)

运行或者可运行状态

S interruptible sleep (waiting for an event to complete)
可打断的睡眠装填,进程可被外部中断或信号唤醒

T stopped by job control signal

进程终止,在终端中使用Ctrl^Z会使得正在运行的进程进入后台

t stopped by debugger during the tracing
处于调试状态的进程

W paging (not valid since the 2.6.xx kernel)
从linux2.6内核之后不再使用该状态

X dead (should never be seen)

进程已经死亡

Z defunct (“zombie”) process, terminated but not reaped by its parent

僵尸进程

< high-priority (not nice to other users)

高优先级进程

N low-priority (nice to other users)

低优先级进程

L has pages locked into memory (for real-time and custom IO)

进程要求内核讲自己的部分内存维持在内存中,不要cache out到磁盘中

s is a session leader

session leader,可以简单理解为该进程下拥有子进程

l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)

该进程包含多个线程

+ is in the foreground process group

运行在前台的进程,比如你在shell中输入ps aux,然后查找ps的进程状态即可看到+


【版权与免责声明】如发现内容存在版权问题,烦请提供相关信息发邮件至 lnkj@3173.top ,我们将及时沟通与处理。 本站内容除了3117站长服务平台( www.3117.cn )原创外,其它均为网友转载内容,涉及言论、版权与本站无关。