Linux 如何查看进程的各线程的CPU占用

1 先用ps + grep找出该死的进程pid,比如 30420
2 top -H -p 30420,(top然后shift+H可以看出某个线程)所有该进程的线程都列出来了。看看哪个线程pid占用最多,然后将这个pid转换为16进制,如 44bf,注意要小写
3 jstack 30420 | less,然后查找 nid=0x44bf,哦,找到了
Shell代码  
  1. "main" prio=10 tid=0x0000000053911400 nid=0x44bf runnable [0x0000000040f5c000..0x0000000040f5ced0]    
  2.    java.lang.Thread.State: RUNNABLE    
  3.         at java.net.SocketInputStream.socketRead0(Native Method)    
  4.         at java.net.SocketInputStream.read(SocketInputStream.java:129)    
  5.         at java.net.SocketInputStream.read(SocketInputStream.java:182)    
  6.         at com.caucho.server.resin.Resin.waitForExit(Resin.java:524)    
  7.         at com.caucho.server.resin.Resin.main(Resin.java:614)  

p.s 严重提示:jstack操作有风险,使用虚谨慎,俺不止一次执行jstack操作导致jvm退出,不知为啥,rp啊rp。。。本来使用JMX会安全一些的,但是翻遍ThreadInfo的doc,没有找到有关的方法

========= 博主的分割线 ========

  1. 只有sun的jdk才有
  2. log中标记“BLOCKED”是重点

"1331634416@qtp-85142763-192" prio=10 tid=0x00002ae9fc0b6000 nid=0x3e0f waiting for monitor entry [0x00002ae9a2825000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:362)
	- waiting to lock <0x00000006c8015e80> (a org.apache.ibatis.datasource.pooled.PoolState)
	at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:82)
	at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:131)
	at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:58)
	at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:271)
	at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:69)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:56)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:114)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
	at com.sun.proxy.$Proxy12.findPropertyPoolWithConstraintTypeByClassId(Unknown Source)




你可能感兴趣的:(Linux 如何查看进程的各线程的CPU占用)