命令三十三: ps

ps在linux系统中用于查看系统中的进程状态,全称是process status,命令格式为ps [参数]

1. 列出本次登录的相关信息

root@iZuf6ic9ggky8ivrx52hxvZ:~# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0 30570 30544  0  80   0 -  5567 wait   pts/0    00:00:00 bash
0 R     0 30595 30570  0  80   0 -  7229 -      pts/0    00:00:00 ps

F: 代表这个程序的标志 (flag), 4 代表使用者为超级用户

S: 代表这个程序的状态 (STAT),

  • D 不可中断 uninterruptible sleep
  • R 运行 runnable 
  • S 中断 sleeping 
  • T 停止 traced or stopped 
  • Z 僵死 a defunct (”zombie”) process

UID: 用户的ID

PID: 程序的ID

PPID: 上级父程序的ID

C: CPU 使用的资源百分比

PRI: Priority (优先执行序) 的缩写,表示程序的优先级

NI: Nice 值

ADDR: 该程序在内存的位置。如果是 running的程序,一般就是 "-"

SZ: 使用掉的内存大小

WCHAN: 目前这个程序是否正在运作当中,若为 - 表示正在运作

TTY: 登入者的终端机位置

TIME: 使用掉的 CPU 时间。

CMD: 所下达的指令

2. 显示所有进程(-A)

root@iZuf6ic9ggky8ivrx52hxvZ:~# ps -A
  PID TTY          TIME CMD
    1 ?        00:00:18 systemd
    2 ?        00:00:00 kthreadd
    3 ?        00:00:10 ksoftirqd/0
    5 ?        00:00:00 kworker/0:0H
    7 ?        00:04:24 rcu_sched
    8 ?        00:00:00 rcu_bh
    9 ?        00:00:00 migration/0
   10 ?        00:00:15 watchdog/0
   11 ?        00:00:00 kdevtmpfs
   12 ?        00:00:00 netns
   13 ?        00:00:00 perf
   14 ?        00:00:00 khungtaskd
   15 ?        00:00:00 writeback
   16 ?        00:00:00 ksmd
   17 ?        00:00:00 khugepaged
   18 ?        00:00:00 crypto
   19 ?        00:00:00 kintegrityd
   20 ?        00:00:00 bioset
   21 ?        00:00:00 kblockd
   22 ?        00:00:00 ata_sff
   23 ?        00:00:00 md
   24 ?        00:00:00 devfreq_wq
   28 ?        00:41:20 kswapd0
   29 ?        00:00:00 vmstat
   30 ?        00:00:00 fsnotify_mark
   31 ?        00:00:00 ecryptfs-kthrea
   47 ?        00:00:00 kthrotld
   48 ?        00:00:00 acpi_thermal_pm
   49 ?        00:00:00 vballoon
......(省略剩余的)

3. 显示用户root的进程

root@iZuf6ic9ggky8ivrx52hxvZ:~# ps -u root
  PID TTY          TIME CMD
    1 ?        00:00:18 systemd
    2 ?        00:00:00 kthreadd
    3 ?        00:00:10 ksoftirqd/0
    5 ?        00:00:00 kworker/0:0H
    7 ?        00:04:24 rcu_sched
    8 ?        00:00:00 rcu_bh
    9 ?        00:00:00 migration/0
   10 ?        00:00:15 watchdog/0
   11 ?        00:00:00 kdevtmpfs
   12 ?        00:00:00 netns
   13 ?        00:00:00 perf
   14 ?        00:00:00 khungtaskd
   15 ?        00:00:00 writeback
   16 ?        00:00:00 ksmd
   17 ?        00:00:00 khugepaged
   18 ?        00:00:00 crypto
   19 ?        00:00:00 kintegrityd
   20 ?        00:00:00 bioset
   21 ?        00:00:00 kblockd
   22 ?        00:00:00 ata_sff
   23 ?        00:00:00 md
......(省略)

4. 查询git进程

root@iZuf6ic9ggky8ivrx52hxvZ:~# ps -ef | grep git
root     30603 30570  0 10:55 pts/0    00:00:00 grep --color=auto git

参考:https://www.cnblogs.com/peida/archive/2012/12/19/2824418.html

猜你喜欢

转载自blog.csdn.net/Ahead_J/article/details/85989530