Linux进程运行了很久,怎么能够得到某一进程所有的线程个数并且得到它们的启动时间,除了读取/proc信息之外,我们可以使用ps简单的达到目的。
ps max -o lstart,lwp,pid,nlwp,cmd
lstart STARTED time the command started.
nlwp NLWP number of lwps (threads) in the process. (alias thcount).
lwp LWP lwp (light weight process, or thread) ID of the lwp being reported.
(alias spid, tid).
BONO11-0-0-1:/root-# ps max -o %mem,lstart,lwp,pid,nlwp,cmd%MEM STARTED LWP PID NLWP CMD
0.0 Fri Nov 11 13:25:29 2011 - 1 1 init [3]
- Fri Nov 11 13:25:29 2011 1 - - -
0.0 Fri Nov 11 13:25:29 2011 - 2 1 [migration/0]
- Fri Nov 11 13:25:29 2011 2 - - -
0.0 Fri Nov 11 13:25:29 2011 - 3 1 [ksoftirqd/0]
- Fri Nov 11 13:25:29 2011 3 - - -
...
0.0 Fri Nov 11 13:50:46 2011 - 310128 /opt/proxy/bin/http_stack Http Stack benchHttp__asr_1_h - Fri Nov 11 13:50:46 2011 31012 - - -
- Fri Nov 11 13:50:46 2011 31016- - -
- Fri Nov 11 13:50:46 2011 31018- - -
- Fri Nov 11 13:50:46 2011 31019- - -
- Fri Nov 11 13:50:47 2011 31855- - -
- Fri Nov 11 13:50:47 2011 31856- - -
- Fri Nov 11 13:50:47 2011 31857- - -
- Fri Nov 11 13:50:47 2011 31926- - -
0.0 Fri Nov 11 17:14:19 2011 - 31272 1 sshd: root@notty
- Fri Nov 11 17:14:19 2011 31272 - - -
我们可以验证正好有8个task.BONO11-0-0-1:/root-# ls /proc/31012/task/
3101231016 31018 31019 31855 31856 31857 31926