您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關Linux查看進程棧信息的示例,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
示例:
先準備一段程序,為了簡單起見這里使用python來寫,其中創建了兩個線程來執行各自的任務。
import threading import time def test1(): while(True): time.sleep(1) print 'test1' def test2(): 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)
然后運行這個程序
$ python test.py
先使用 “pstree -apl ” 查看進程結構
$ pstree -apl 26855 python,26855 test.py |-{python},26858 |-{python},26859
然后使用 “ps -Lf ” 查看線程信息
$ ps -Lf 26855 UID PID PPID LWP C NLWP STIME TTY STAT TIME CMD jhadmin 26855 25902 26855 0 3 15:15 pts/5 Sl+ 0:00 python test.py jhadmin 26855 25902 26858 0 3 15:15 pts/5 Sl+ 0:00 python test.py jhadmin 26855 25902 26859 0 3 15:15 pts/5 Sl+ 0:00 python test.py
最后,可以使用 “pstack ” 查看線程的詳細信息,如下:
$ pstack 26855 Thread 3 (Thread 0x7f8a344f2700 (LWP 26858)): #0 0x00007f8a3b5387a3 in select () from /lib64/libc.so.6 #1 0x00007f8a344f5070 in time_sleep () from /usr/lib64/python2.7/lib-dynload/timemodule.so #2 0x00007f8a3c215af0 in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #3 0x00007f8a3c217e3d in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0 #4 0x00007f8a3c1a188d in function_call () from /lib64/libpython2.7.so.1.0 #5 0x00007f8a3c17c8e3 in PyObject_Call () from /lib64/libpython2.7.so.1.0 #6 0x00007f8a3c2104fd in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #7 0x00007f8a3c2154bd in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #8 0x00007f8a3c2154bd in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #9 0x00007f8a3c217e3d in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0 #10 0x00007f8a3c1a1798 in function_call () from /lib64/libpython2.7.so.1.0 #11 0x00007f8a3c17c8e3 in PyObject_Call () from /lib64/libpython2.7.so.1.0 #12 0x00007f8a3c18b8d5 in instancemethod_call () from /lib64/libpython2.7.so.1.0 #13 0x00007f8a3c17c8e3 in PyObject_Call () from /lib64/libpython2.7.so.1.0 #14 0x00007f8a3c20e6f7 in PyEval_CallObjectWithKeywords () from /lib64/libpython2.7.so.1.0 #15 0x00007f8a3c2465c2 in t_bootstrap () from /lib64/libpython2.7.so.1.0 #16 0x00007f8a3bf1ce25 in start_thread () from /lib64/libpthread.so.0 #17 0x00007f8a3b54134d in clone () from /lib64/libc.so.6 Thread 2 (Thread 0x7f8a33cf1700 (LWP 26859)): #0 0x00007f8a3b5387a3 in select () from /lib64/libc.so.6 #1 0x00007f8a344f5070 in time_sleep () from /usr/lib64/python2.7/lib-dynload/timemodule.so #2 0x00007f8a3c215af0 in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #3 0x00007f8a3c217e3d in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0 #4 0x00007f8a3c1a188d in function_call () from /lib64/libpython2.7.so.1.0 #5 0x00007f8a3c17c8e3 in PyObject_Call () from /lib64/libpython2.7.so.1.0 #6 0x00007f8a3c2104fd in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #7 0x00007f8a3c2154bd in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #8 0x00007f8a3c2154bd in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #9 0x00007f8a3c217e3d in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0 #10 0x00007f8a3c1a1798 in function_call () from /lib64/libpython2.7.so.1.0 #11 0x00007f8a3c17c8e3 in PyObject_Call () from /lib64/libpython2.7.so.1.0 #12 0x00007f8a3c18b8d5 in instancemethod_call () from /lib64/libpython2.7.so.1.0 #13 0x00007f8a3c17c8e3 in PyObject_Call () from /lib64/libpython2.7.so.1.0 #14 0x00007f8a3c20e6f7 in PyEval_CallObjectWithKeywords () from /lib64/libpython2.7.so.1.0 #15 0x00007f8a3c2465c2 in t_bootstrap () from /lib64/libpython2.7.so.1.0 #16 0x00007f8a3bf1ce25 in start_thread () from /lib64/libpthread.so.0 #17 0x00007f8a3b54134d in clone () from /lib64/libc.so.6 Thread 1 (Thread 0x7f8a3c6f3740 (LWP 26855)): #0 0x00007f8a3bf22a0b in do_futex_wait.constprop.1 () from /lib64/libpthread.so.0 #1 0x00007f8a3bf22a9f in __new_sem_wait_slow.constprop.0 () from /lib64/libpthread.so.0 #2 0x00007f8a3bf22b3b in sem_wait@@GLIBC_2.2.5 () from /lib64/libpthread.so.0 #3 0x00007f8a3c242535 in PyThread_acquire_lock () from /lib64/libpython2.7.so.1.0 #4 0x00007f8a3c2461c2 in lock_PyThread_acquire_lock () from /lib64/libpython2.7.so.1.0 #5 0x00007f8a3c215af0 in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #6 0x00007f8a3c217e3d in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0 #7 0x00007f8a3c21533c in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #8 0x00007f8a3c217e3d in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0 #9 0x00007f8a3c21533c in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #10 0x00007f8a3c217e3d in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0 #11 0x00007f8a3c1a1798 in function_call () from /lib64/libpython2.7.so.1.0 #12 0x00007f8a3c17c8e3 in PyObject_Call () from /lib64/libpython2.7.so.1.0 #13 0x00007f8a3c18b8d5 in instancemethod_call () from /lib64/libpython2.7.so.1.0 #14 0x00007f8a3c17c8e3 in PyObject_Call () from /lib64/libpython2.7.so.1.0 #15 0x00007f8a3c17c9c5 in call_function_tail () from /lib64/libpython2.7.so.1.0 #16 0x00007f8a3c17ccfb in PyObject_CallMethod () from /lib64/libpython2.7.so.1.0 #17 0x00007f8a3c232f29 in Py_Finalize () from /lib64/libpython2.7.so.1.0 #18 0x00007f8a3c244325 in Py_Main () from /lib64/libpython2.7.so.1.0 #19 0x00007f8a3b46ac05 in __libc_start_main () from /lib64/libc.so.6 #20 0x000000000040071e in _start ()
這里多說一句,如果要看java程序的棧信息,可以使用 “kill -3 ” 來查看,比如:
$ nohub java Test > test.out & $ kill -3 <pid>
關于“Linux查看進程棧信息的示例”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。