strace Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

In the world of Linux, understanding what is happening under the hood is vital. The strace command in Linux is a powerful tool that aids in this journey of discovery. The command is primarily used for debugging and tracing system calls and signals made by a process. With strace, you can peek into the interactions between user-space programs and the Linux kernel, which can be beneficial in many troubleshooting scenarios.

Syntax of strace Command in Linux

The basic syntax of the strace command in Linux is as follows:

Where:

  • option: These are optional flags that modify the behavior of strace.
  • command: This is the command or program that you want to trace.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Options in strace Command in Linux

  1. -c: This option makes strace print a summary of system calls instead of a step-by-step trace.

    For example -

    Output:

    The '-c' option triggers strace to provide statistical data about the system calls.

  2. -o: The '-o' option followed by a file name directs strace to write the output into a file instead of standard output.

    For example -

    Output:

    This option is useful when tracing a process that generates a lot of output or when the output needs to be analyzed at a later stage.

  3. -p: The '-p' option is followed by a process ID (PID). This allows strace to attach to a running process and trace its system calls.

    For example -

    Output:

    This is particularly useful when you need to debug a running process or program.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Basic usage of strace:

    Output:

    Explanation: This is the simplest way to use strace command in Linux to view the system calls made by a command.

  • Tracing specific system calls:

    Output:

    Explanation: With the '-e' option, you can specify the system calls you are interested in. This helps to filter out the noise when tracing a process.

Tips

  • It's often useful to redirect strace's output to a file using '-o' option for later analysis.

  • Remember to use the '-c' option if you are interested in the statistical summary of system calls.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of strace Command in Linux

  • Tracing a running process:

    Output:

    Explanation: With the '-p' option, strace becomes a powerful tool to trace a running process. This is especially useful in debugging scenarios.

  • Trace child processes:

    Output:

    Explanation: The '-f' option allows strace to follow child processes spawned by the main process. This gives a comprehensive view of the entire process tree.

  • Limit strace output to errors:

    Output:

    Explanation: This is useful when you're interested in knowing the system calls which failed during the execution of a program.

Conclusion

  • The strace command in Linux is an incredibly versatile tool for tracing and debugging processes.

  • The options like '-c', '-o', and '-p' provide flexibility in terms of output and process selection.

  • Advanced usage with options like '-f' and '-e trace=error' offer more targeted and insightful system call tracing.