Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the strace command of linux to trace system calls

Shulou Source: shulou.com Published: 2022-06-02 14:44:47 10月04日 Update

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!

Tags: Tracking system process time output command parameter hardware device learning application statistics location signal information content file format mode times Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Linux MySQL macOS OPPO Reno