|
When debugging, strace can help you track the system calls a program executed. When you want to know how to interact with programs and the operating system, which is extremely convenient, for example, you want to know what the implementation of system calls, and in what sequence.
This simple yet powerful tool for almost all of the Linux operating system is available, and can be used to debug a lot of programs.
Command Usage
Let's see how strace command to track the implementation of a program.
In its simplest form, the back strace can follow any commands. It lists many system calls. At first, we did not understand all of the output, but if you're looking for something special, then you should find it from the output.
Let's look at a simple command ls system call tracking situation.
raghu @ raghu-Linoxide ~ $ strace ls
This is the first few lines of strace command output. Other outputs are truncated.
Output section shows the write system call, it is the current directory listing to standard output.
The image below shows the use ls command to list the contents of a directory (not used strace).
raghu @ raghu-Linoxide ~ $ ls
Option 1 to find the configuration file is read program
One usage Strace (except for debugging certain problems outside) is that you can find the configuration file is read by a program. E.g,
raghu @ raghu-Linoxide ~ $ strace php 2> & 1 | grep php.ini
Option 2 tracking system call specified
strace -e option command is used to display only certain system calls (for example, open, write, etc.)
Let's trace what 'open' system call cat command.
raghu @ raghu-Linoxide ~ $ strace -e open cat dead.letter
Option 3 tracing process
strace can be used only on the command, and by using the -p option can be used in the process running.
raghu @ raghu-Linoxide ~ $ sudo strace -p 1846
Statistical summary of option 4 strace
It includes a summary of system calls, the execution time, errors, etc. Use the -c option to be able to show it in an orderly way:
raghu @ raghu-Linoxide ~ $ strace -c ls
5 Save the output options
You can save the output of strace command by using the -o option to a file.
raghu @ raghu-Linoxide ~ $ sudo strace -o process_strace -p 3229
The reason to sudo to run the above command, in order to prevent the owner of the ID and the user ID does not match the viewing process.
6 shows the timestamp option
Using the -t option, you can add a timestamp before the output of each line.
raghu @ raghu-Linoxide ~ $ strace -t ls
Option 7 finer timestamp
-tt option can show microsecond timestamp.
raghu @ raghu-Linoxide ~ $ strace -tt ls
-ttt can also demonstrate to the above as microsecond timestamps, but it is not to print the current time, but show since epoch (Annotation: January 1, 1970 00:00:00 UTC) since elapsed seconds number.
raghu @ raghu-Linoxide ~ $ strace -ttt ls
Option 8 relative time
A relative time stamp between calls to the -r option display system.
raghu @ raghu-Linoxide ~ $ strace -r ls |
|
|
|