查看线程的方法:
ps -efL, 其中的LWP是线程ID(why是这个), nlwp是线程数.
UID PID PPID LWP C NLWP STIME TTY TIME CMD
也就是第四位,是它的线程ID,而第二位则是进程的PID,第三位是子进程号:
ps -T -p 9613
PID SPID TTY TIME CMD
9613 9613 pts/1 00:00:00 thread01
9613 9712 pts/1 00:00:00 thread01
9613 9795 pts/1 00:00:00 thread01
9613 9853 pts/1 00:00:00 thread01
看线程PID:
ps -efL|grep logstash|awk '{print $4}'|wc
148 148 888
查看进程28740是主进程,28741是子进程,28265则是程序的主进程来自:
[root@iZ25dcp92ckZ ~]# ps aux|grep 28265
root 28265 0.0 0.3 116648 3412 pts/0 Ss 21:29 0:00 -bash:
也就是bash终端~
列名分别是:
UID PID PPID LWP C NLWP STIME TTY TIME CMD
其中
UID为User ID.
PID为processid,进程标识符
PPID为 parent processid,父进程标识符2,
LWP为light weight process orthread, 轻量级进程,即线程标识符
NLWP为,number oflwps(threads) in the process, 线程的数量
摘自:http://blog.csdn.net/jiafu1115/article/details/19070015
——————————————————————————————————————————————————————
48属于www用户的id,这儿我这个没有添加,所以没有显示www,对上面这些线程进行跟踪:
————————————————————————————————
1、 cat /proc/${pid}/status
Threads: 2 //这个是核心,2个线程!如下:
[root@test multepoolserver]# cat /proc/26202/status
Name: multipepollserv
State: S (sleeping)
SleepAVG: 58%
Tgid: 26202
Pid: 26202
PPid: 18260
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 256
Groups: 0 1 2 3 4 6 10
VmPeak: 26036 kB
VmSize: 26036 kB
VmLck: 0 kB
VmHWM: 1144 kB
VmRSS: 1144 kB
VmData: 10508 kB
VmStk: 84 kB
VmExe: 16 kB
VmLib: 3052 kB
VmPTE: 80 kB
StaBrk: 03103000 kB
Brk: 03124000 kB
StaStk: 7fff73219100 kB
Threads: 2
SigQ: 1/70656
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000001000
SigCgt: 0000000180004407
CapInh: 0000000000000000
CapPrm: 00000000fffffeff
CapEff: 00000000fffffeff
Cpus_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,000000ff
Mems_allowed: 00000000,00000003
2、pstree -p ${pid}
[root@test multepoolserver]# pstree -p 26202
multipepollserv(26202)─┬─multipepollserv(26203)
└─{multipepollserv}(26204)
26204 就是一个线程。
[root@test multepoolserver]# ps aux|grep httpmut
root 26202 0.0 0.0 26036 1144 pts/10 Sl+ 17:35 0:00 [httpmut: master process] H?????5r%
www 26203 0.0 0.0 15840 468 pts/10 S+ 17:35 0:00 [httpmut: worker process] H?????5r%
3、top -p ${pid} 再按H 或者直接输入 top -bH -d 3 -p ${pid}
[root@test multepoolserver]# top -p 26202
按大写的H(shift+h),就能看到有几个线程:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
26202 root 18 0 26036 1144 984 S 0.0 0.0 0:00.00 multipepollserv
26204 root 20 0 26036 1144 984 S 0.0 0.0 0:00.00 multipepollserv
top -bH -d 3 -p 26202 //3秒刷新一次
[root@test multepoolserver]# top -bH -d 3 -p 26202
top - 17:39:34 up 650 days, 3:35, 10 users, load average: 1.04, 1.01, 1.01
Tasks: 2 total, 0 running, 2 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.9%us, 0.3%sy, 0.0%ni, 97.8%id, 0.9%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 8180460k total, 7648040k used, 532420k free, 1269016k buffers
Swap: 8385920k total, 218976k used, 8166944k free, 4855668k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
26202 root 18 0 26036 1144 984 S 0.0 0.0 0:00.00 multipepollserv
26204 root 20 0 26036 1144 984 S 0.0 0.0 0:00.00 multipepollserv
top -H
手册中说:-H : Threads toggle
加上这个选项启动top,top一行显示一个线程。否则,它一行显示一个进程。
4、ps xH
手册中说:H Show threads as if they were processes
这样可以查看所有存在的线程。
5、ps -mp <PID>
手册中说:m Show threads after processes
这样可以查看一个进程起的线程数。
http://liulinxia02.blog.163.com/blog/static/268687720111129103740947/
[root@test multepoolserver]# ps aux|grep httpmut
root 26202 0.0 0.0 26036 1144 pts/10 Sl+ 17:35 0:00 [httpmut: master process] H?????5r%
www 26203 0.0 0.0 15840 468 pts/10 S+ 17:35 0:00 [httpmut: worker process] H?????5r%
root 26206 0.0 0.0 61172 748 pts/14 S+ 17:35 0:00 grep httpmut
[root@test multepoolserver]# ps -mp 26202
PID TTY TIME CMD
26202 pts/10 00:00:00 multipepollserv
- - 00:00:00 -
- - 00:00:00 -
[root@test multepoolserver]# ps -mp 26203
PID TTY TIME CMD
26203 pts/10 00:00:00 multipepollserv
- - 00:00:00 -
——————————————————————————————————————————
在linux中查看线程数的三种方法
在linux中查看线程数的三种方法
www.2cto.com
1、top -H
手册中说:-H : Threads toggle
加上这个选项启动top,top一行显示一个线程。否则,它一行显示一个进程。
2、ps xH
手册中说:H Show threads as if they were processes
这样可以查看所有存在的线程。
3、ps -mp <PID>
手册中说:m Show threads after processes
这样可以查看一个进程起的线程数。
来源:http://www.2cto.com/os/201212/177103.html
更多:http://www.360doc.com/content/13/0512/13/9085503_284797175.shtml
ps -efL, 其中的LWP是线程ID(why是这个), nlwp是线程数.
UID PID PPID LWP C NLWP STIME TTY TIME CMD
也就是第四位,是它的线程ID,而第二位则是进程的PID,第三位是子进程号:
ps -T -p 9613
PID SPID TTY TIME CMD
9613 9613 pts/1 00:00:00 thread01
9613 9712 pts/1 00:00:00 thread01
9613 9795 pts/1 00:00:00 thread01
9613 9853 pts/1 00:00:00 thread01
看线程PID:
ps -efL|grep logstash|awk '{print $4}'|wc
148 148 888
查看进程28740是主进程,28741是子进程,28265则是程序的主进程来自:
[root@iZ25dcp92ckZ ~]# ps aux|grep 28265
root 28265 0.0 0.3 116648 3412 pts/0 Ss 21:29 0:00 -bash:
也就是bash终端~
列名分别是:
UID PID PPID LWP C NLWP STIME TTY TIME CMD
其中
UID为User ID.
PID为processid,进程标识符
PPID为 parent processid,父进程标识符2,
LWP为light weight process orthread, 轻量级进程,即线程标识符
NLWP为,number oflwps(threads) in the process, 线程的数量
摘自:http://blog.csdn.net/jiafu1115/article/details/19070015
——————————————————————————————————————————————————————
48属于www用户的id,这儿我这个没有添加,所以没有显示www,对上面这些线程进行跟踪:
————————————————————————————————
1、 cat /proc/${pid}/status
Threads: 2 //这个是核心,2个线程!如下:
[root@test multepoolserver]# cat /proc/26202/status
Name: multipepollserv
State: S (sleeping)
SleepAVG: 58%
Tgid: 26202
Pid: 26202
PPid: 18260
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 256
Groups: 0 1 2 3 4 6 10
VmPeak: 26036 kB
VmSize: 26036 kB
VmLck: 0 kB
VmHWM: 1144 kB
VmRSS: 1144 kB
VmData: 10508 kB
VmStk: 84 kB
VmExe: 16 kB
VmLib: 3052 kB
VmPTE: 80 kB
StaBrk: 03103000 kB
Brk: 03124000 kB
StaStk: 7fff73219100 kB
Threads: 2
SigQ: 1/70656
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000001000
SigCgt: 0000000180004407
CapInh: 0000000000000000
CapPrm: 00000000fffffeff
CapEff: 00000000fffffeff
Cpus_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,000000ff
Mems_allowed: 00000000,00000003
2、pstree -p ${pid}
[root@test multepoolserver]# pstree -p 26202
multipepollserv(26202)─┬─multipepollserv(26203)
└─{multipepollserv}(26204)
26204 就是一个线程。
[root@test multepoolserver]# ps aux|grep httpmut
root 26202 0.0 0.0 26036 1144 pts/10 Sl+ 17:35 0:00 [httpmut: master process] H?????5r%
www 26203 0.0 0.0 15840 468 pts/10 S+ 17:35 0:00 [httpmut: worker process] H?????5r%
3、top -p ${pid} 再按H 或者直接输入 top -bH -d 3 -p ${pid}
[root@test multepoolserver]# top -p 26202
按大写的H(shift+h),就能看到有几个线程:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
26202 root 18 0 26036 1144 984 S 0.0 0.0 0:00.00 multipepollserv
26204 root 20 0 26036 1144 984 S 0.0 0.0 0:00.00 multipepollserv
top -bH -d 3 -p 26202 //3秒刷新一次
[root@test multepoolserver]# top -bH -d 3 -p 26202
top - 17:39:34 up 650 days, 3:35, 10 users, load average: 1.04, 1.01, 1.01
Tasks: 2 total, 0 running, 2 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.9%us, 0.3%sy, 0.0%ni, 97.8%id, 0.9%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 8180460k total, 7648040k used, 532420k free, 1269016k buffers
Swap: 8385920k total, 218976k used, 8166944k free, 4855668k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
26202 root 18 0 26036 1144 984 S 0.0 0.0 0:00.00 multipepollserv
26204 root 20 0 26036 1144 984 S 0.0 0.0 0:00.00 multipepollserv
top -H
手册中说:-H : Threads toggle
加上这个选项启动top,top一行显示一个线程。否则,它一行显示一个进程。
4、ps xH
手册中说:H Show threads as if they were processes
这样可以查看所有存在的线程。
5、ps -mp <PID>
手册中说:m Show threads after processes
这样可以查看一个进程起的线程数。
http://liulinxia02.blog.163.com/blog/static/268687720111129103740947/
[root@test multepoolserver]# ps aux|grep httpmut
root 26202 0.0 0.0 26036 1144 pts/10 Sl+ 17:35 0:00 [httpmut: master process] H?????5r%
www 26203 0.0 0.0 15840 468 pts/10 S+ 17:35 0:00 [httpmut: worker process] H?????5r%
root 26206 0.0 0.0 61172 748 pts/14 S+ 17:35 0:00 grep httpmut
[root@test multepoolserver]# ps -mp 26202
PID TTY TIME CMD
26202 pts/10 00:00:00 multipepollserv
- - 00:00:00 -
- - 00:00:00 -
[root@test multepoolserver]# ps -mp 26203
PID TTY TIME CMD
26203 pts/10 00:00:00 multipepollserv
- - 00:00:00 -
——————————————————————————————————————————
在linux中查看线程数的三种方法
在linux中查看线程数的三种方法
www.2cto.com
1、top -H
手册中说:-H : Threads toggle
加上这个选项启动top,top一行显示一个线程。否则,它一行显示一个进程。
2、ps xH
手册中说:H Show threads as if they were processes
这样可以查看所有存在的线程。
3、ps -mp <PID>
手册中说:m Show threads after processes
这样可以查看一个进程起的线程数。
来源:http://www.2cto.com/os/201212/177103.html
更多:http://www.360doc.com/content/13/0512/13/9085503_284797175.shtml
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/6514/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2019-10-8 17:27
评论列表