linux查看进程栈信息的示例-mile米乐体育
linux
2021年02月23日 07:37
0
这篇文章将为大家详细讲解有关linux查看进程栈信息的示例,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
示例:
先准备一段程序,为了简单起见这里使用python来写,其中创建了两个线程来执行各自的任务。
importthreading importtime deftest1(): while(true): time.sleep(1) print'test1' deftest2(): while(true): time.sleep(1) print'test2' t1=threading.thread(target=test1,args=()) t2=threading.thread(target=test2,args=()) t1.start() t2.start() time.sleep(12345)
然后运行这个程序
$pythontest.py
先使用 “pstree -apl ” 查看进程结构
$pstree-apl26855 python,26855test.py |-{python},26858 |-{python},26859
然后使用 “ps -lf ” 查看线程信息
$ps-lf26855 uidpidppidlwpcnlwpstimettystattimecmd jhadmin2685525902268550315:15pts/5sl 0:00pythontest.py jhadmin2685525902268580315:15pts/5sl 0:00pythontest.py jhadmin2685525902268590315:15pts/5sl 0:00pythontest.py
最后,可以使用 “pstack ” 查看线程的详细信息,如下:
$pstack26855 thread3(thread0x7f8a344f2700(lwp26858)): #00x00007f8a3b5387a3inselect()from/lib64/libc.so.6 #10x00007f8a344f5070intime_sleep()from/usr/lib64/python2.7/lib-dynload/timemodule.so #20x00007f8a3c215af0inpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #30x00007f8a3c217e3dinpyeval_evalcodeex()from/lib64/libpython2.7.so.1.0 #40x00007f8a3c1a188dinfunction_call()from/lib64/libpython2.7.so.1.0 #50x00007f8a3c17c8e3inpyobject_call()from/lib64/libpython2.7.so.1.0 #60x00007f8a3c2104fdinpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #70x00007f8a3c2154bdinpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #80x00007f8a3c2154bdinpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #90x00007f8a3c217e3dinpyeval_evalcodeex()from/lib64/libpython2.7.so.1.0 #100x00007f8a3c1a1798infunction_call()from/lib64/libpython2.7.so.1.0 #110x00007f8a3c17c8e3inpyobject_call()from/lib64/libpython2.7.so.1.0 #120x00007f8a3c18b8d5ininstancemethod_call()from/lib64/libpython2.7.so.1.0 #130x00007f8a3c17c8e3inpyobject_call()from/lib64/libpython2.7.so.1.0 #140x00007f8a3c20e6f7inpyeval_callobjectwithkeywords()from/lib64/libpython2.7.so.1.0 #150x00007f8a3c2465c2int_bootstrap()from/lib64/libpython2.7.so.1.0 #160x00007f8a3bf1ce25instart_thread()from/lib64/libpthread.so.0 #170x00007f8a3b54134dinclone()from/lib64/libc.so.6 thread2(thread0x7f8a33cf1700(lwp26859)): #00x00007f8a3b5387a3inselect()from/lib64/libc.so.6 #10x00007f8a344f5070intime_sleep()from/usr/lib64/python2.7/lib-dynload/timemodule.so #20x00007f8a3c215af0inpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #30x00007f8a3c217e3dinpyeval_evalcodeex()from/lib64/libpython2.7.so.1.0 #40x00007f8a3c1a188dinfunction_call()from/lib64/libpython2.7.so.1.0 #50x00007f8a3c17c8e3inpyobject_call()from/lib64/libpython2.7.so.1.0 #60x00007f8a3c2104fdinpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #70x00007f8a3c2154bdinpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #80x00007f8a3c2154bdinpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #90x00007f8a3c217e3dinpyeval_evalcodeex()from/lib64/libpython2.7.so.1.0 #100x00007f8a3c1a1798infunction_call()from/lib64/libpython2.7.so.1.0 #110x00007f8a3c17c8e3inpyobject_call()from/lib64/libpython2.7.so.1.0 #120x00007f8a3c18b8d5ininstancemethod_call()from/lib64/libpython2.7.so.1.0 #130x00007f8a3c17c8e3inpyobject_call()from/lib64/libpython2.7.so.1.0 #140x00007f8a3c20e6f7inpyeval_callobjectwithkeywords()from/lib64/libpython2.7.so.1.0 #150x00007f8a3c2465c2int_bootstrap()from/lib64/libpython2.7.so.1.0 #160x00007f8a3bf1ce25instart_thread()from/lib64/libpthread.so.0 #170x00007f8a3b54134dinclone()from/lib64/libc.so.6 thread1(thread0x7f8a3c6f3740(lwp26855)): #00x00007f8a3bf22a0bindo_futex_wait.constprop.1()from/lib64/libpthread.so.0 #10x00007f8a3bf22a9fin__new_sem_wait_slow.constprop.0()from/lib64/libpthread.so.0 #20x00007f8a3bf22b3binsem_wait@@glibc_2.2.5()from/lib64/libpthread.so.0 #30x00007f8a3c242535inpythread_acquire_lock()from/lib64/libpython2.7.so.1.0 #40x00007f8a3c2461c2inlock_pythread_acquire_lock()from/lib64/libpython2.7.so.1.0 #50x00007f8a3c215af0inpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #60x00007f8a3c217e3dinpyeval_evalcodeex()from/lib64/libpython2.7.so.1.0 #70x00007f8a3c21533cinpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #80x00007f8a3c217e3dinpyeval_evalcodeex()from/lib64/libpython2.7.so.1.0 #90x00007f8a3c21533cinpyeval_evalframeex()from/lib64/libpython2.7.so.1.0 #100x00007f8a3c217e3dinpyeval_evalcodeex()from/lib64/libpython2.7.so.1.0 #110x00007f8a3c1a1798infunction_call()from/lib64/libpython2.7.so.1.0 #120x00007f8a3c17c8e3inpyobject_call()from/lib64/libpython2.7.so.1.0 #130x00007f8a3c18b8d5ininstancemethod_call()from/lib64/libpython2.7.so.1.0 #140x00007f8a3c17c8e3inpyobject_call()from/lib64/libpython2.7.so.1.0 #150x00007f8a3c17c9c5incall_function_tail()from/lib64/libpython2.7.so.1.0 #160x00007f8a3c17ccfbinpyobject_callmethod()from/lib64/libpython2.7.so.1.0 #170x00007f8a3c232f29inpy_finalize()from/lib64/libpython2.7.so.1.0 #180x00007f8a3c244325inpy_main()from/lib64/libpython2.7.so.1.0 #190x00007f8a3b46ac05in__libc_start_main()from/lib64/libc.so.6 #200x000000000040071ein_start()
这里多说一句,如果要看java程序的栈信息,可以使用 “kill -3 ” 来查看,比如:
$nohubjavatest>test.out& $kill-3
关于“linux查看进程栈信息的示例”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
展开全文