In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
1. Use the 'print' statement
This is a basic way to debug problems. We insert print statements where there are doubts in the program to understand the running flow of the program, control flow and changes in variable values.
Its disadvantage is that you need to edit the program, add 'print' statements, and must recompile and rerun to get the output. If the program you need to debug is relatively large, this will be a time-consuming and laborious method.
2. Use query
In some cases, we need to figure out the state and memory mapping of a process running in the kernel. In order to get this information, we don't need to insert any code into the kernel. Instead, you can use the / proc file system. In the pseudo file system of / proc, keep the running information (cpu information, memory capacity, etc.) collected when the system starts up.
The output of ls-l / proc, by having an entry named process id in the / proc file system for each process running on the system. The details of each process can be obtained in the file in the directory corresponding to the process id. You can also use the output of'ls / proc/pid'.
3. Use tracking
Strace and ltrace are two tracking tools used in Linux to track the execution details of a program.
Strace:
Strace intercepts and records system calls and the signals they receive. For users, it displays system calls, parameters passed to them, and return values. Strace can be attached to an already running process or to a new process. It is very useful as a diagnostic and debugging tool for developers and system administrators.
It can also be used as a tool to understand the system by tracking different program calls. The advantage of this tool is that no source code is required and the program does not need to be recompiled.
The basic syntax for using strace is:
Strace command
The output of strace is so long that we are not usually interested in every line displayed. We can use the'- e expr' option to filter unwanted data.
Use the'- p pid' option to bind to the running process.
With the'- o 'option, the output of the command can be redirected to a file.
The strace is filtered to output with only system calls.
Ltrace:
Ltrace tracks and records calls to a process's dynamic (runtime) library and the signals it receives. It can also track system calls made by a process. Its usage is similar to strace.
Ltrace command
The'- i' option prints the instruction pointer when the library is called.
The'- S 'option is used for real-world system calls and library calls.
Trace captures the output of the 'STRCMP' library call.
The above are the details of the methods of program debugging in linux, please pay more attention to other related articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.