Linux下查看进程线程数的方法
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
相关推荐
-
nginx检查提示“unknown directive "stream" in /etc/*/nginx.conf”
nginx检查提示“unknown directive "stream" in /etc/*/nginx.conf”2025-02-26 00:38:21 -
php之多级目录下查找文件中是否含有某个字符串功能实现2025-02-26 00:36:35
-
mysql 启动不了1067错误如何解决?2025-02-26 00:33:31
-
MySQL简单INSERT超慢原因排查2025-02-26 00:22:42
-
mysql分布式数据库的主要构架是什么?2025-02-26 00:06:23