Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Using Linux strace command trace / debug a program commonly used options     - Linux System Getting Started Tutorial: How to automatically set the JAVA_HOME environment variable on Linux (Linux)

- Enterprise-class GitHub warehousing environment build (Server)

- Timing task Crontab under Linux system (Linux)

- Delay for the specified IP port analog network to send and receive packets on Linux (Linux)

- Findbugs installation documentation (Linux)

- Use chattr and lsattr command to manage linux files and directory attributes (Linux)

- Java Generics (Programming)

- JDK installation notes under CentOS (Linux)

- About enhanced Linux / Unix server system security program (Linux)

- Linux LVM space expansion Demo (Linux)

- Open remote MySQL database connection managed under CentOS (Database)

- Ubuntu download install and configure Plank Dock (Linux)

- Make Windows boot disk to install USB in Ubuntu Linux (Linux)

- Java how to achieve bubble sort the problem Arraylist (Programming)

- C ++ pointer of the (error-prone model) (Programming)

- Ubuntu Eclipse configuration Gtk + 2.0 libraries (Linux)

- Performance issues under CentOS 6.5 VLAN devices (Linux)

- JavaScript common array manipulation functions and usage (Programming)

- Java string concatenation techniques (StringBuilder tips) (Programming)

- A script to make your Ubuntu 14.04 Memory screen brightness (Linux)

  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
- Fedora 22 install Adobe Flash Player (Linux)
- Linux Network Security: nmap port scanning software (Linux)
- Android Studio Getting Started Hello World (Programming)
- Use the TC flow control test under Linux (Linux)
- C # Future: Method Contract (Programming)
- RPM package management under Linux (Linux)
- Java JDK has been able to compile without warning (Programming)
- Chrome plug-in management, online-offline installation, part of the plug presentations (Linux)
- pscp use Detailed Windows and Linux each file transfer tool (Linux)
- CUDA (including GPU card driver) installation process under Ubuntu (Linux)
- Ubuntu root user profiles (Programming)
- Detailed steps - GAMIT solver (Linux)
- installation and configuration of the PHP environment (Apache2) under Linux (Server)
- HBase in MVCC implementation mechanism and its application (Database)
- CentOS7 yum install third-party source EPEL (Linux)
- VirtualBox installation enhancements let the mouse move and share CentOS 6.4 (Linux)
- Linux system security knowledge (Linux)
- C # / iOS / Android Universal Encryption and decryption (Programming)
- Linux common network tools: traceroute routing of scanned (Linux)
- Linux, Firefox unloading and installation and upgrade (Linux)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.