Linux 下 ps 命令

简述

  Linux中的ps命令是Process Status的缩写。ps命令用来列出系统中当前运行的那些进程。ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,动态的显示进程信息,要使用top命令。

  该命令可确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等。
  ps提供进程的一次性的查看,提供的查看结果并不动态连续。如果想对进程时间监控,应该用top工具。
  kill命令用于杀死进程。

linux上进程有5种状态: 

  1. 运行(正在运行或在运行队列中等待) 
  2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 
  3. 不可中断(收到信号不唤醒和不可运行, 进程必须等待直到有中断发生) 
  4. 僵死(进程已终止, 但进程描述符存在, 直到父进程调用wait4()系统调用后释放) 
  5. 停止(进程收到SIGSTOP, SIGSTP, SIGTIN, SIGTOU信号后停止运行运行) 

命令格式 

ps [参数]

命令功能

  用来显示当前进程的状态

命令参数

$ ps --help
********* simple selection *********  ********* selection by list *********
-A all processes                      -C by command name
-N negate selection                   -G by real group ID (supports names)
-a all w/ tty except session leaders  -U by real user ID (supports names)
-d all except session leaders         -g by session OR by effective group name
-e all processes                      -p by process ID
T  all processes on this terminal     -s processes in the sessions given
a  all w/ tty, including other users  -t by tty
g  OBSOLETE -- DO NOT USE             -u by effective user ID (supports names)
r  only running processes             U  processes for specified users
x  processes w/o controlling ttys     t  by tty
*********** output format **********  *********** long options ***********
-o,o user-defined  -f full            --Group --User --pid --cols --ppid
-j,j job control   s  signal          --group --user --sid --rows --info
-O,O preloaded -o  v  virtual memory  --cumulative --format --deselect
-l,l long          u  user-oriented   --sort --tty --forest --version
-F   extra full    X  registers       --heading --no-heading --context
                    ********* misc options *********
-V,V  show version      L  list format codes  f  ASCII art forest
-m,m,-L,-T,H  threads   S  children in sum    -y change -l format
-M,Z  security data     c  true command name  -c scheduling class
-w,w  wide output       n  numeric WCHAN,UID  -H process hierarchy

   a  显示所有进程

  -a 显示同一终端下的所有程序

  -A 显示所有进程

  c  显示进程的真实名称

  -N 反向选择

  -e 等于“-A”

  e  显示环境变量

  f  显示程序间的关系

  -H 显示树状结构

  r  显示当前终端的进程

  T  显示当前终端的所有程序

  u  指定用户的所有进程

  -au 显示较详细的资讯

  -aux 显示所有包含其他使用者的行程 

  -C <命令> 列出指定命令的状况

  --lines <行数> 每页显示的行数

  --width <字符数> 每页显示的字符数

  --help 显示帮助信息

  --version 显示版本显示

使用实例

    * 其中最常用的就是:

  ps -auxf | grep **

  显示所有进程信息

        ps -A

    显示指定用户的信息

        ps -u root

    显示所有进程信息,连同命令行

        ps -ef

    ps与grep常用组合用法,查找特定进程

        ps -ef | grep ssh

    将目前属于您自己这次登入的PID与相关信息列出来

        ps -l

原文地址:https://www.cnblogs.com/zhengbin/p/5755141.html