pstree&gdb

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zslngu/article/details/88951315

pstree 查看进程的线程数

import threading                                                
import time                                                     
                                                                
def run(i):                                                     
    if i % 2 != 0:                                              
        time.sleep(10)                                          
        raise Exception("GG")                                   
    time.sleep(1000)                                            
                                                                
def main(count):                                                
    ts = []                                                     
    for i in range(count):                                      
        ts.append(threading.Thread(target=run, args=(i,)))      
    for t in ts:                                                
        t.setDaemon(True)                                       
        t.start()                                               
    time.sleep(2000)                                            
                                                                
import click                                                    
                                                                
@click.group()                                                  
def cli():                                                      
    pass                                                        
                                                                
@cli.command()                                                  
@click.option("--count", type=int)                              
def test(count):                                                
    main(count)                                                 

通过pstree 查看对应线程情况

pstree -p 31864
python3(31864)─┬─{python3}(31865)
               └─{python3}(31866)
pstree -p 31864
python3(31864)───{python3}(31865)

gdb 查看进程运行状态

gdb 
attach pid
info threads  查看所有线程
thread thread_id 选择线程调试
info stack 查看当前线程的栈信息
thread apply all bt 查看所有线程的栈信息

info stack

#0  0x00007f7226efba1d in __libc_recv (fd=3, buf=0x2bdbe00, len=8192, flags=0)
    at ../sysdeps/unix/sysv/linux/recv.c:28
#1  0x00000000005bb8f6 in ?? ()
#2  0x00000000005bdfe9 in ?? ()
#3  0x00000000005be2e4 in ?? ()
#4  0x00000000005be378 in ?? ()
#5  0x00000000005030d5 in ?? ()
#6  0x0000000000506859 in _PyEval_EvalFrameDefault ()
#7  0x0000000000501945 in _PyFunction_FastCallDict ()
#8  0x0000000000591461 in ?? ()
#9  0x00000000005a337c in _PyObject_FastCallDict ()
#10 0x00000000005a3a5e in PyObject_CallMethodObjArgs ()
#11 0x00000000004c2e07 in ?? ()
#12 0x00000000004c2f3b in ?? ()
#13 0x00000000005dc390 in ?? ()
#14 0x00000000005dc705 in ?? ()
#15 0x0000000000502d6f in ?? ()
#16 0x0000000000506859 in _PyEval_EvalFrameDefault ()
#17 0x0000000000502209 in ?? ()
#18 0x0000000000502f3d in ?? ()
#19 0x0000000000506859 in _PyEval_EvalFrameDefault ()
#20 0x0000000000502209 in ?? ()
#21 0x0000000000502f3d in ?? ()
#22 0x0000000000506859 in _PyEval_EvalFrameDefault ()
#23 0x0000000000502209 in ?? ()
#24 0x0000000000502f3d in ?? ()

猜你喜欢

转载自blog.csdn.net/zslngu/article/details/88951315
GDB