In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "introduction to the usage of strace command in Linux system". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "introduction to the usage of strace command in Linux system".
When debugging, strace can help you trace the system calls executed by a program. This is extremely convenient when you want to know how the program interacts with the operating system, such as which system calls are executed and in what order.
This simple and powerful tool is available on almost all Linux operating systems and can be used to debug a large number of programs.
Command usage
Let's see how the strace command tracks the execution of a program.
In the simplest form, strace can be followed by any command. It will list a lot of system calls. At first, we don't understand all the output, but if you're looking for something special, you should be able to find it in the output.
Let's take a look at the system call trace for the simple command ls.
The code is as follows:
Raghu@raghu-Linoxide ~ $strace ls
These are the first few lines of the strace command output. The rest of the output was intercepted.
The output section above shows the write system call, which outputs a list of the current directory to standard output.
The following picture shows the contents of the directory listed using the ls command (without using strace).
The code is as follows:
Raghu@raghu-Linoxide ~ $ls
Option 1 looks for the configuration file read by the program
One of the uses of Strace (except for debugging some problems) is that you can find configuration files that are read by a program. For example,
The code is as follows:
Raghu@raghu-Linoxide ~ $strace php 2 > & 1 | grep php.ini
Option 2 tracks the specified system call
The-e option of the strace command is only used to show specific system calls (for example, open,write, etc.)
Let's trace the 'open' system call' of the cat command.
The code is as follows:
Raghu@raghu-Linoxide ~ $strace-e open cat dead.letter
Option 3 tracking progress
Strace can be used not only on commands, but also on running processes by using the-p option.
The code is as follows:
Raghu@raghu-Linoxide ~ $sudo strace-p 1846
Option 4 Statistical summary of strace
It includes a summary of system calls, execution time, errors, and so on. Use the-c option to display in a neat manner:
The code is as follows:
Raghu@raghu-Linoxide ~ $strace-c ls
Option 5 Save the output
You can save the output of the strace command to a file by using the-o option.
The code is as follows:
Raghu@raghu-Linoxide ~ $sudo strace-o process_strace-p 3229
The above command is run with sudo to prevent a mismatch between the user ID and the owner ID of the process being viewed.
Option 6 displays the timestamp
Using the-t option, you can add a timestamp before the output of each line.
The code is as follows:
Raghu@raghu-Linoxide ~ $strace-t ls
Option 7 finer timestamps
The-tt option displays a microsecond timestamp.
The code is as follows:
Raghu@raghu-Linoxide ~ $strace-tt ls
-ttt can also display a microsecond timestamp as above, but instead of printing the current time, it shows the number of seconds that have elapsed since epoch 00:00:00 UTC.
The code is as follows:
Raghu@raghu-Linoxide ~ $strace-ttt ls
Option 8 relative time
The-r option shows the relative timestamp between system calls.
The code is as follows:
Raghu@raghu-Linoxide ~ $strace-r ls
Thank you for your reading. the above is the content of "introduction to the usage of strace command in Linux system". After the study of this article, I believe you have a deeper understanding of the introduction of strace command in Linux system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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: 210
*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.