这篇文章将为大家详细讲解有关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<pid>
关于“Linux查看进程栈信息的示例”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
海报
0 条评论
170
相关文章
本站已关闭游客评论,请登录或者注册后再评论吧~