Linux下查看进程线程数的方法

阅读文本大概需要3分钟。

0x01:ps -ef只打印进程,而ps -eLf会打印所有的线程

[root@centos6 ~]# ps -ef | grep rsyslogd
root      1470     1  0  2011 ?        00:01:13 /sbin/rsyslogd -c 4
root     29865 28596  0 22:45 pts/5    00:00:00 grep rsyslogd
[root@centos6 ~]# ps -eLf | grep rsyslogd
root      1470     1  1470  0    5  2011 ?        00:00:00 /sbin/rsyslogd -c 4
root      1470     1 28631  0    5 Mar04 ?        00:00:04 /sbin/rsyslogd -c 4
root      1470     1 28632  0    5 Mar04 ?        00:00:01 /sbin/rsyslogd -c 4
root      1470     1 28633  0    5 Mar04 ?        00:00:04 /sbin/rsyslogd -c 4
root      1470     1 28636  0    5 Mar04 ?        00:00:00 /sbin/rsyslogd -c 4
root     29867 28596 29867  0    1 22:45 pts/5    00:00:00 grep rsyslogd

rsyslogd这个进程有5个线程,所以ps -ef只有一行,而ps -eLf就有5行

ps -eLf各字段含义

  • UID:用户ID

  • PID:process id 进程id

  • PPID: parent process id 父进程id

  • LWP:表示这是个线程;要么是主线程(进程),要么是线程

  • NLWP: num of light weight process 轻量级进程数量,即线程数量

  • STIME: start time 启动时间

  • TIME: 占用的CPU总时间

  • TTY:该进程是在哪个终端运行的;pts/0255代表虚拟终端,一般是远程连接的终端;tty1tty7 代表本地控制台终端

  • CMD:进程的启动命令

0x02:top -H -p ${pid} 或者 top -p ${pid} 然后 shitf + H

0x03:cat /proc/${pid}/status  或者  ls /proc/${pid}/task

其中Threads后面跟的就是线程数

0x04:pstree -p ${pid}

0x05:ps -hH -p ${pid}

[root@localhost ~]# ps -hH -p 1414
 1414 ?        Ssl    0:00 /usr/sbin/rsyslogd -n
 1414 ?        Ssl    0:00 /usr/sbin/rsyslogd -n
 1414 ?        Ssl    0:00 /usr/sbin/rsyslogd -n

推荐阅读

Spring Boot 最流行的 16 条实践

SSM框架的面试常见问题

【分布式】缓存穿透、缓存雪崩,缓存击穿解决方案

阿里P7给出的一份超详细 Spring Boot 知识清单

关注我每天进步一点点

你点的每个在看,我都认真当成了喜欢

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章