Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Using Linux strace command trace / debug a program commonly used options     - [Errno 4] IOError: [Errno ftp error] with yum appears as a workaround (Linux)

- Linux tool curl and wget advanced use (Linux)

- Ubuntu uses under KVM + Qemu virtual machine build (Linux)

- Examples of safety testing system notes for RedHat Linux (Linux)

- Ubuntu 14.10 Apache installation and configuration (Server)

- Easily create RPM packages using the FPM (Linux)

- Android studio multi-channel ultra-compact version of the package (Programming)

- Linux Command Tutorial: du command to view disk space (Linux)

- Oracle 11g statistics collection - collection of multi-column statistics (Database)

- Two network security scanning tools under ubuntu (Linux)

- How to use the tab in Vim carried Python code completion (Linux)

- To use slay kill user processes (Linux)

- Python context managers (Programming)

- Ceph distributed storage system is installed on a CentOS 7.1 (Server)

- To build a private Docker registry (Server)

- error 1819 (HY000): your password does not satisfy the current policy requirements (Database)

- Hyper-V virtual hard disk how to copy files to and attached to the virtual machine (Linux)

- Rails project prepared some tips small experience (Linux)

- 20 Advanced Java interview questions summary (Programming)

- C ++ Supplements - locates the new expression (Programming)

  Using Linux strace command trace / debug a program commonly used options
  Add Date : 2018-11-21      
  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
- Linux System Getting Started Tutorial: Five image processing software (Linux)
- pscp use Detailed Windows and Linux each file transfer tool (Linux)
- C language Bubble Sort - integer sort (Programming)
- Ubuntu Series Installation Docker (Linux)
- Under Ubuntu on how to use iptables firewall (Linux)
- Share Java-based multithreading file case (Programming)
- Linux rights management (Linux)
- Use custom backup plans for Debian backupninja (Linux)
- Talk about the Linux folder permissions issue again (Linux)
- Mhddfs: multiple smaller partitions into one large virtual storage (Linux)
- Keepalived + Nginx Installation and Configuration (Server)
- Linux disk partition batch format mount script (Linux)
- CentOS 7 - use cgroups limit process resource (Linux)
- To setup Cocos2dx project under Ubuntu (Linux)
- Questions about Linux compiler u-boot (Programming)
- Linux network monitoring tools ntopng installation (Linux)
- Linux common commands MEMO (Linux)
- Memcached installation, configuration and monitoring (Server)
- Installing software on Ubuntu: apt-get and dpkg difference (Linux)
- Java abstract class instantiation (Programming)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.