![如何定位死循环或高CPU利用率linux,第1张 如何定位死循环或高CPU利用率linux,第1张](/aiimages/%E5%A6%82%E4%BD%95%E5%AE%9A%E4%BD%8D%E6%AD%BB%E5%BE%AA%E7%8E%AF%E6%88%96%E9%AB%98CPU%E5%88%A9%E7%94%A8%E7%8E%87linux.png)
找出调用栈使用gdb attach nmsagent所在的进程,在gdb中使用 info threads显示所有
线程gdb gdb>attach 2907gdb>info threads得到如下结果,可以发现2909线程的编号是1213 Thread 0xad5f2b70 (LWP 2908) 0x004ef0d7 in mq_timedreceive () from /lib/tls/i686/cmov/librt.so.112 Thread 0xad58eb70 (LWP 2909) 0x006e0422 in __kernel_vsyscall ()11 Thread 0xad52ab70 (LWP 2910) 0x006e0422 in __kernel_vsyscall ()10 Thread 0xad4f8b70 (LWP 2911) 0x006e0422 in __kernel_vsyscall ()9 Thread 0xad4c6b70 (LWP 2912) 0x006e0422 in __kernel_vsyscall ()8 Thread 0xad3feb70 (LWP 2913) 0x004ef0d7 in mq_timedreceive () from /lib/tls/i686/cmov/librt.so.17 Thread 0xace08b70 (LWP 2914) 0x004ef0d7 in mq_timedreceive () from /lib/tls/i686/cmov/librt.so.16 Thread 0xac607b70 (LWP 2915) 0x006e0422 in __kernel_vsyscall ()5 Thread 0xac5e6b70 (LWP 2916) 0x006e0422 in __kernel_vsyscall ()4 Thread 0xac361b70 (LWP 2917) 0x006e0422 in __kernel_vsyscall ()3 Thread 0xac2fdb70 (LWP 2918) 0x006e0422 in __kernel_vsyscall ()2 Thread 0xac1fcb70 (LWP 2919) 0x004ef0d7 in mq_timedreceive () from /lib/tls/i686/cmov/librt.so.1* 1 Thread 0xb78496d0 (LWP 2907) 0x006e0422 in __kernel_vsyscall ()使用thread 切换线程,使用bt显示线程栈gdb>thread 12 gdb>bt得到如下线程栈#0 0x006e0422 in __kernel_vsyscall ()#1 0x001cca26 in nanosleep () from /lib/tls/i686/cmov/libc.so.6#2 0x001fc2dc in usleep () from /lib/tls/i686/cmov/libc.so.6#3 0x0806b510 in OspTaskDelay ()#4 0x0805c710 in CDispatchTask::NodeMsgSendToSock() ()#5 0x0805cc74 in DispatchTaskEntry ()#6 0x0806a8e9 in OspTaskTemplateFunc(void*) ()#7 0x00d4780e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0#8 0x002027ee in clone () from /lib/tls/i686/cmov/libc.so.6 ps + strace 得到进程ID 21465 ps -e grep cmu 4996 ? 00:00:25 cmu_fjga_sp3 21465 pts/5 00:08:10 cmu得到线程时间, 其中最占CPU的是 EpollRecvTask 21581ps -eL grep 2146521465 21579 pts/5 00:00:00 CamApp21465 21580 pts/5 00:00:00 TimerMan Task21465 21581 pts/5 00:09:02 EpollRecvTask21465 21582 pts/5 00:00:00使用 strace -p 21581 得到线程栈linux系统处理vbs死
循环脚本方法如下。
1、指定循环次数,使用计数器重复运行语句。
2、对于集合中的每项或数组中的每个元素,重复执行一组语句。
3、循环执行某段代码直到条件变为true。
评论列表(0条)