1. top 命令找到占用cpu最高的进程
top - 14:37:14 up 34 days, 13:27, 2 users, load average: 0.21, 0.29, 0.29
Tasks: 151 total, 1 running, 150 sleeping, 0 stopped, 0 zombie
Cpu(s): 4.4%us, 2.7%sy, 0.0%ni, 90.9%id, 0.5%wa, 0.0%hi, 0.2%si, 1.3%st
Mem: 16334064k total, 16171240k used, 162824k free, 16716k buffers
Swap: 16383996k total, 4470816k used, 11913180k free, 539788k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1818 tomcat 20 0 3643m 983m 7548 S 0.7 24.8 190:40.13 java
字段解释:
top - 时间 运行时间 用户 系统负载
Tasks: 进程相关信息
Cpu(s): cpu相关信息
Mem: 内存相关
Swap: 交换区相关信息
进程相关信息
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2. 使用top -H -p 查看该进程内所有线程
top -H -p 1818
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
6656 tomcat 20 0 4193m 608m 11m R 21.0 3.8 1419:44 java
3. printf “%x\n” 将10进制线程号转换为16进制结果
[liuzhihang@test08 ~]$ printf "%x\n" 1876
754
[liuzhihang@test08 ~]$
4. jstack |grep
jstack 1818 | grep 754 -A 30
pid 为第一次执行top命令时的 pid
tid 为将第二次的pid进行十六进制转换后的结果
"catalina-8180-89" #1842 daemon prio=5 os_prio=0 tid=0x00007f4ec4096000 nid=0x5d96 waiting on condition [0x00007f4e87545000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000f418f898> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"catalina-8180-88" #1841 daemon prio=5 os_prio=0 tid=0x00007f4eb848e800 nid=0x5d94 waiting on condition [0x00007f4e8bd8b000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)