这篇文章主要为大家展示了“linux系统中pstack命令怎么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“linux系统中pstack命令怎么用”这篇文章吧。

pstack用来跟踪进程栈,这个命令在排查进程问题时非常有用,比如我们发现一个服务一直处于work状态(如假死状态,好似死循环),使用这个命令就能轻松定位问题所在。

实例

pstree以树结构显示进程

pstree-pwork|grepadsshd(22669)---bash(22670)---ad_preprocess(4551)-+-{ad_preprocess}(4552)|-{ad_preprocess}(4553)|-{ad_preprocess}(4554)|-{ad_preprocess}(4555)|-{ad_preprocess}(4556)`-{ad_preprocess}(4557)

work为工作用户,-p为显示进程识别码,ad_preprocess共启动了6个子线程,加上主线程共7个线程。

ps-Lf4551UIDPIDPPIDLWPCNLWPSTIMETTYstattimeCMDwork45512267045512716:30pts/2Sl+0:02./ad_preprocesswork45512267045520716:30pts/2Sl+0:00./ad_preprocesswork45512267045530716:30pts/2Sl+0:00./ad_preprocesswork45512267045540716:30pts/2Sl+0:00./ad_preprocesswork45512267045550716:30pts/2Sl+0:00./ad_preprocesswork45512267045560716:30pts/2Sl+0:00./ad_preprocesswork45512267045570716:30pts/2Sl+0:00./ad_preprocess

进程共启动了7个线程

pstack显示每个进程的栈跟踪:

pstack4551Thread7(Thread1084229984(LWP4552)):#00x000000302afc63dcinepoll_wait()from/lib64/tls/libc.so.6#10x00000000006f0730inub::EPollEx::poll()#20x00000000006f172ainub::NetReactor::callback()#30x00000000006fbbbbinub::UBTask::CALLBACK()#40x000000302b80610ainstart_thread()from/lib64/tls/libpthread.so.0#50x000000302afc6003inclone()from/lib64/tls/libc.so.6#60x0000000000000000in??()Thread6(Thread1094719840(LWP4553)):#00x000000302afc63dcinepoll_wait()from/lib64/tls/libc.so.6#10x00000000006f0730inub::EPollEx::poll()#20x00000000006f172ainub::NetReactor::callback()#30x00000000006fbbbbinub::UBTask::CALLBACK()#40x000000302b80610ainstart_thread()from/lib64/tls/libpthread.so.0#50x000000302afc6003inclone()from/lib64/tls/libc.so.6#60x0000000000000000in??()Thread5(Thread1105209696(LWP4554)):#00x000000302b80baa5in__nanosleep_nocancel()#10x000000000079e758incomcm::ms_sleep()#20x00000000006c8581inub::UbClientManager::healthyCheck()#30x00000000006c8471inub::UbClientManager::start_healthy_check()#40x000000302b80610ainstart_thread()from/lib64/tls/libpthread.so.0#50x000000302afc6003inclone()from/lib64/tls/libc.so.6#60x0000000000000000in??()Thread4(Thread1115699552(LWP4555)):#00x000000302b80baa5in__nanosleep_nocancel()#10x0000000000482b0einarmor::armor_check_thread()#20x000000302b80610ainstart_thread()from/lib64/tls/libpthread.so.0#30x000000302afc6003inclone()from/lib64/tls/libc.so.6#40x0000000000000000in??()Thread3(Thread1126189408(LWP4556)):#00x000000302af8f1a5in__nanosleep_nocancel()from/lib64/tls/libc.so.6#10x000000302af8f010insleep()from/lib64/tls/libc.so.6#20x000000000044c972inBusiness_config_manager::run()#30x0000000000457b83inThread::run_thread()#40x000000302b80610ainstart_thread()from/lib64/tls/libpthread.so.0#50x000000302afc6003inclone()from/lib64/tls/libc.so.6#60x0000000000000000in??()Thread2(Thread1136679264(LWP4557)):#00x000000302af8f1a5in__nanosleep_nocancel()from/lib64/tls/libc.so.6#10x000000302af8f010insleep()from/lib64/tls/libc.so.6#20x00000000004524bbinProcess_thread::sleep_period()#30x0000000000452641inProcess_thread::run()#40x0000000000457b83inThread::run_thread()#50x000000302b80610ainstart_thread()from/lib64/tls/libpthread.so.0#60x000000302afc6003inclone()from/lib64/tls/libc.so.6#70x0000000000000000in??()Thread1(Thread182894129792(LWP4551)):#00x000000302af8f1a5in__nanosleep_nocancel()from/lib64/tls/libc.so.6#10x000000302af8f010insleep()from/lib64/tls/libc.so.6#20x0000000000420d79inAd_preprocess::run()#30x0000000000450ad0inmain()

以上是“linux系统中pstack命令怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!