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

Use the strace command of linux to trace system calls

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Editor to share with you the use of linux strace command tracking system calls, I believe that most people do not know much, so share this article for you to learn, I hope you will learn a lot after reading this article, let's go to learn the method!

Strace command is a tool that integrates diagnosis, debugging, statistics and integration. We can use strace to analyze the tracking results of system calls and signal transmission of the application, in order to solve problems or understand the working process of the application.

Strace is often used to track system calls and received signals when a process is executing. In the Linux world, processes cannot access hardware devices directly. When processes need to access hardware devices (such as reading disk files, receiving network data, etc.), they must switch from user mode to kernel mode and access hardware devices through system calls. Strace can track system calls generated by a process, including parameters, return values, and execution time.

Syntax format: strace [parameters]

Common parameters:

-c counts the execution time, times and errors of each system call-d outputs strace debugging information about standard error-f tracks child processes generated by fork calls-F attempts to trace vfork calls. At-f, vfork is not tracked-a sets the output position of the return value. The default is 40murr to print out the relative time about each system call-t adds time information before each line in the output

Reference example

General and complete usage, track all system calls of the 28979 process (- e trace=all), and count the time spent by the system calls, as well as the start time (and displayed in a visual time-minute-second format), and finally store the recording results in the output.txt file:

[root@linuxcool] # strace-o output.txt-T-tt-e trace=all-p 28979

Track the process from fork and vfork at the same time, write all the strace output to ~ / dcop-strace.txt, and start debugging dcopserver:

[root@linuxcool] # strace-f-F-o ~ / dcop-strace.txt dcopserver

Sets the output location of the return value. The default is 40:

[root@linuxcool] # strace-a column

Output when tracking whoami:

[root@linuxcool] # strace-o whoami-strace.txt whoami

Restrict strace to trace only specific system calls:

[root@linuxcool] # strace-f-o configure-strace.txt-e execve. / configure above is to use the strace command of linux to track all the contents of the system call, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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

Servers

Wechat

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

12
Report