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

What are the methods for analyzing Linux processes

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Xiaobian to share with you what methods of analyzing Linux processes, I believe most people do not know how, so share this article for your reference, I hope you have a lot of harvest after reading this article, let us go to understand it together!

1、strace

trace system calls and signals trace system calls and signals inside a process

What is a system call? A system call is a request from a program running in "user mode" to the operating system in "kernel mode" for a service that requires higher privileges to run. A system call provides an interface between a user program and the operating system.

strace followed by the start of a process, you can track the system calls and signals after the start process, this command can see which system calls are called when the process is executed, by specifying different options can output the system call occurred time, precision can be accurate to microseconds, and even statistical analysis of the system "call time", which is very useful in troubleshooting the process of suspended animation, can help you find out which system call the process stuck on. Processes that are already running can also be attached to trace by specifying the-p parameter plus pid, like gdb attach.

2、pstack

print a stack trace of a running process Prints stack information for a running program.

Execute the command pstack pid You can see the stack information in the current thread running, where pid can be obtained from the previous ps command, pstack can see the thread number started in the process, and the "stack" content of each thread in the process can also be seen.

3、pstree

display a tree of processes pstree Print the structure information of the running process according to the tree structure, you can visually view the relationship between the process and the thread it starts, and can display the process identifier.

4、gdb

gdb is GNU development gcc suite Linux program debugging tools, you can view the program stack, set breakpoints, print program runtime information, and even debug multithreaded programs, very powerful. It's a bit overkill to think of gdb as a command here.

To debug a C/C++ program with gdb, add the-g option when compiling first, g++ -g test.cpp -o test. The generated program can be debugged with gdb.

You can start debugging programs directly with gdb command: gdb prog

It is also possible to debug by attaching gdb to an already started process. Command: gdb prog pid

After the program crash parameters corefile can also be used gdb debugging, to see what the program died before leaving a message (stack information) to you. Command: gdb prog corefile, there is a point to note, some Linux

The default program crashes do not generate corefiles, so you need ulimit -c unlimited to generate corefiles.

The above is "What are the ways to analyze Linux processes?" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

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

Development

Wechat

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

12
Report