How to do it...

Let's see how strace can be used in various ways to trace the execution of any program, from start to end:

  1. To trace the execution of any executable command in Linux, simply run the strace command followed by the executable command. If we use strace for the ls command, we get the following output:

  1. In the preceding screenshot, the output displayed has been truncated. If we check the last few lines of the output, we can see that the write system calls where the listing of the current directory is displayed:

  1. To check the listing, we can run ls alone in the same directory, and we will see the same listing as we saw in the previous screenshot:

  1. If we want to have a statistical summary of the strace command displayed in a neat manner, we can use -c option, as follows:
    strace -c ls

  1. We can also display the timestamp at the start of each output line by using the -t option, as follows:

  1. The default strace command displays all the system calls made by the executable program. If we wish to show only a specific call, we can use the -e option. So, if we want to see the open system call of the ls command, we have to run the following command:
    strace -e open ls

  1. If we wish to save the output of the strace command in a file for viewing it later, we can do so by using the -o option, as follows:
    strace -o output.txt ls

Here, output.txt is the name of the file which will be created to save the output of the strace command.

  1. If we want to use strace on any process which is currently running, we can do so by using the process ID of the process. In our example, we are using the process of Firefox process , whose ID is 16301.

We can run the following command and also save the output of the command in the firefox_output.txt file using the -o option:

  1. We can then check the content of the output file by using the tail command or any text editor of our choice.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.196.184