Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example of Linux viewing process stack information

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the example of viewing process stack information on Linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Example:

First prepare a program, which is written here using python for simplicity, in which two threads are created to perform their respective tasks.

Import threadingimport timedef 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)

Then run the program.

$python test.py

First use "pstree-apl" to view the process structure

$pstree-apl 26855 pythonauthor26855 test.py |-{python}, 26858 |-{python}, 26859

Then use "ps-Lf" to view thread information

$ps-Lf 26855UID PID PPID LWP C NLWP STIME TTY STAT TIME CMDjhadmin 26855 25902 26855 0 3 15:15 pts/5 Sl+ 0:00 python test.pyjhadmin 26855 25902 26858 0 3 15:15 pts/5 Sl+ 0:00 python test.pyjhadmin 26855 25902 26859 0 3 15:15 pts/5 Sl+ 0:00 python test.py

Finally, you can use "pstack" to view the details of the thread, as follows:

$pstack 26855Thread 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. 09.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.6Thread 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 to 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.6Thread 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 .032 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 ()

One more thing here, if you want to see the stack information of the java program, you can use "kill-3" to view it, such as:

This is the end of the article $nohub java Test > test.out & $kill-3 on "an example of Linux viewing process stack information". I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report