ps 命令组合

ps axj

主要用于查看当前系统中进程的 PPID、PID、PGID、SID、TTY 等信息。
[root@VM-0-7-centos ~]# ps -axj

 PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
    0     1     1     1 ?           -1 Ss       0  71:36 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
    0     2     0     0 ?           -1 S        0   0:01 [kthreadd]
    2     4     0     0 ?           -1 S<       0   0:00 [kworker/0:0H]
    2     6     0     0 ?           -1 S        0   6:38 [ksoftirqd/0]
    2     7     0     0 ?           -1 S        0   0:00 [migration/0]
    2     8     0     0 ?           -1 S        0   0:00 [rcu_bh]
    2     9     0     0 ?           -1 R        0  31:04 [rcu_sched]
    2    10     0     0 ?           -1 S<       0   0:00 [lru-add-drain]
    2    11     0     0 ?           -1 S        0   2:31 [watchdog/0]
    2    13     0     0 ?           -1 S        0   0:00 [kdevtmpfs]
    2    14     0     0 ?           -1 S<       0   0:00 [netns]
    2    15     0     0 ?           -1 S        0   0:07 [khungtaskd]
    2    16     0     0 ?           -1 S<       0   0:00 [writeback]
    2    17     0     0 ?           -1 S<       0   0:00 [kintegrityd]
    2    18     0     0 ?           -1 S<       0   0:00 [bioset]
    2    19     0     0 ?           -1 S<       0   0:00 [bioset]
    2    20     0     0 ?           -1 S<       0   0:00 [bioset]
    2    21     0     0 ?           -1 S<       0   0:00 [kblockd]
    2    22     0     0 ?           -1 S<       0   0:00 [md]
    2    23     0     0 ?           -1 S<       0   0:00 [edac-poller]
    2    24     0     0 ?           -1 S<       0   0:00 [watchdogd]
    2    30     0     0 ?           -1 S        0   0:07 [kswapd0]
PPID:父进程id
PID: 进程id
PGID:进程所属的Group的Leader的PID
SID :SID就是进程所属的Session Leader的PID,如果SID==PID,那么该进程是session leader
TTY:连接终端(该进程在终端运行如与终端无关则显示?若为pts/0等,则表示由网络连接主机进程。)
TPGID:控制终端进程组ID(由控制终端修改,用于指示当前前台进程组)
STAT:进程状态
D      //无法中断的休眠状态(通常 IO 的进程); 
R      //正在运行可中在队列中可过行的; 
S      //处于休眠状态; 
T      //停止或被追踪; 
W      //进入内存交换 (从内核2.6开始无效); 
X      //死掉的进程 (基本很少见); 
Z      //僵尸进程; 
<      //优先级高的进程 
N      //优先级较低的进程 
L      //有些页被锁进内存; 
s      //进程的领导者(在它之下有子进程); 
l      //多线程,克隆线程(使用 CLONE_THREAD, 类似 NPTL pthreads); 
+      //位于后台的进程组
UID:用户id(每个用户必需指定UID。UID 0是保留给root用户的,UID 1~99是保留给其它预定义用户的, UID 100~999是保留给系统用户的;)
TIME :该进程实际使用cpu运行的时间
COMMAND:命令名称和参数

ps axm

显示进程的详细信息,PID 列下面的减号(-)是这个进程中的线程。

[root@VM-0-7-centos ~]# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  51760  3288 ?        Ss    2022  71:36 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root         2  0.0  0.0      0     0 ?        S     2022   0:01 [kthreadd]
root         4  0.0  0.0      0     0 ?        S<    2022   0:00 [kworker/0:0H]
root         6  0.0  0.0      0     0 ?        S     2022   6:38 [ksoftirqd/0]
root         7  0.0  0.0      0     0 ?        S     2022   0:00 [migration/0]
root         8  0.0  0.0      0     0 ?        S     2022   0:00 [rcu_bh]
root         9  0.0  0.0      0     0 ?        R     2022  31:04 [rcu_sched]
root        10  0.0  0.0      0     0 ?        S<    2022   0:00 [lru-add-drain]
root        11  0.0  0.0      0     0 ?        S     2022   2:31 [watchdog/0]
root        13  0.0  0.0      0     0 ?        S     2022   0:00 [kdevtmpfs]
root        14  0.0  0.0      0     0 ?        S<    2022   0:00 [netns]
root        15  0.0  0.0      0     0 ?        S     2022   0:07 [khungtaskd]
root        16  0.0  0.0      0     0 ?        S<    2022   0:00 [writeback]
root        17  0.0  0.0      0     0 ?        S<    2022   0:00 [kintegrityd]
root        18  0.0  0.0      0     0 ?        S<    2022   0:00 [bioset]
root        19  0.0  0.0      0     0 ?        S<    2022   0:00 [bioset]
root        20  0.0  0.0      0     0 ?        S<    2022   0:00 [bioset]
root        21  0.0  0.0      0     0 ?        S<    2022   0:00 [kblockd]
root        22  0.0  0.0      0     0 ?        S<    2022   0:00 [md]
root        23  0.0  0.0      0     0 ?        S<    2022   0:00 [edac-poller]
root        24  0.0  0.0      0     0 ?        S<    2022   0:00 [watchdogd]
USER:用户名
PID :同上
%CPU :进程占用cpu%
%MEM:进程占用内存%
VSZ:进程使用虚拟内存量(KB)
RSS:进程使用固定内存量(KB)(驻留中页的数量)
TTY:同上
STAT:同上
START:同上
TIME :同上
COMMAND:同上

ps -eo pid,lstart,etime,cmd |grep XXXX

查看svnserver运行了多久

[root@VM-0-7-centos ~]# ps -eo pid,lstart,etime,cmd |grep svn
 1065 Fri Oct 28 13:38:04 2022 384-20:21:04 svnserve -dr /svn/
19648 Fri Nov 17 09:59:08 2023       00:00 grep --color=auto svn
pid:1065
svnserver 运行开始时间:Fri Oct 28 13:38:04 2022
运行共计时间:384-20:21:04
进程名称 :svnserve -dr /svn/

ps -ef TH | grep xxxxx

查看进程中的线程数量

root@fort:~# ps -ef TH | grep guacd
root     3983335 3965581  0 10:16 pts/2    Sl+    0:00 guacd -b 0.0.0.0 -L debug -f
root     3983335 3965581  0 10:51 pts/2    Sl+    0:00 guacd -b 0.0.0.0 -L debug -f
root     3983335 3965581  0 10:51 pts/2    Sl+    0:00 guacd -b 0.0.0.0 -L debug -f
root     3983335 3965581  0 10:51 pts/2    Sl+    0:00 guacd -b 0.0.0.0 -L debug -f
root     4011232 3983335  0 10:51 pts/2    Sl     0:00 guacd -b 0.0.0.0 -L debug -f
root     4011232 3983335  0 10:51 pts/2    Sl     0:00 guacd -b 0.0.0.0 -L debug -f
root     4011232 3983335  0 10:51 pts/2    Sl     0:00 guacd -b 0.0.0.0 -L debug -f
root     4011232 3983335  0 10:51 pts/2    Sl     0:00 guacd -b 0.0.0.0 -L debug -f
root     4011232 3983335  0 10:51 pts/2    Sl     0:00 guacd -b 0.0.0.0 -L debug -f
root     4011232 3983335  0 10:51 pts/2    Sl     0:00 guacd -b 0.0.0.0 -L debug -f
root     4011232 3983335  0 10:51 pts/2    Sl     0:00 guacd -b 0.0.0.0 -L debug -f
root     4011232 3983335  0 10:51 pts/2    Sl     0:00 guacd -b 0.0.0.0 -L debug -f
root     4011232 3983335  0 10:51 pts/2    Sl     0:00 guacd -b 0.0.0.0 -L debug -f
root     4013139 4007363  0 10:52 pts/4    S+     0:00 grep guacd

ps -eo pid,pmem,args --sort=-pmem |head -n 5

查看机器中内存占用最高的前5个进程

[root@VM-0-7-centos ~]#  ps -eo pid,pmem,args --sort=-pmem |head -n 5
  PID %MEM COMMAND
  353  6.1 /usr/lib/systemd/systemd-journald
27443  5.7 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
 1175  3.7 /usr/sbin/rsyslogd -n
  568  1.3 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值