240 lines
7.3 KiB
HTML
240 lines
7.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; font-src 'self' data:; img-src 'self' data:; connect-src 'self'; base-uri 'self'; form-action 'self' https://defcon.social https://bsky.app;">
|
|
<meta http-equiv="X-Content-Type-Options" content="nosniff">
|
|
<link rel="stylesheet" href="../assets/css/style.css">
|
|
<link rel="icon" type="image/x-icon" href="../favicon.ico">
|
|
<script>
|
|
// Apply theme immediately to prevent flash
|
|
(function() {
|
|
const theme = localStorage.getItem('theme') ||
|
|
(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
})();
|
|
</script>
|
|
<title>strace Cheatsheet - Cheatsheets - Launch Pad</title>
|
|
</head>
|
|
<body>
|
|
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode">
|
|
<svg class="theme-icon theme-icon-moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
|
|
<svg class="theme-icon theme-icon-sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>
|
|
</button>
|
|
<br/><br/>
|
|
<div class="name">
|
|
__ _______________________ _________._________________________
|
|
\_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/
|
|
| __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_
|
|
| \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \
|
|
\___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ /
|
|
\/ \/ \/ \/ \/ \/ \/
|
|
</div>
|
|
<div class="blog-page-header">
|
|
<div class="blog-header-content">
|
|
<a href="/cheatsheets" class="back-link" title="Back to Cheatsheets">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="42" viewBox="0 0 24 24" class="home-icon"><path fill="currentColor" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
|
|
</a>
|
|
<h1 class="blog-page-title">strace Cheatsheet</h1>
|
|
</div>
|
|
</div>
|
|
<div class="blog-post-container">
|
|
<div class="blog-posts-container" style="max-width: 900px; margin: 0 auto;">
|
|
<div class="blog-post">
|
|
<div class="blog-post-content">
|
|
<p><a href="index.html">← Back to cheatsheets</a></p>
|
|
<p><a href="../index.html">← Home</a></p>
|
|
<hr>
|
|
<p>strace traces system calls and signals. Monitors interactions between a process and the Linux kernel, essential for debugging, performance analysis, and security auditing.</p>
|
|
<hr>
|
|
<h2>Basic Usage</h2>
|
|
<ul>
|
|
<li>strace command - Trace command execution</li>
|
|
</ul>
|
|
<ul>
|
|
<li>strace -p PID - Attach to running process</li>
|
|
</ul>
|
|
<ul>
|
|
<li>strace -e trace=open command - Trace specific calls</li>
|
|
</ul>
|
|
<ul>
|
|
<li>strace -c command - Summary statistics</li>
|
|
</ul>
|
|
<ul>
|
|
<li>strace -f command - Follow child processes</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Common Options</h2>
|
|
<ul>
|
|
<li>-p PID - Attach to process</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-f - Follow child processes</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-ff - Separate output per thread</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-c - Count calls and time</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-e trace=set - Trace specific calls</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-e trace=file - Trace file operations</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-e trace=network - Trace network calls</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-e trace=process - Trace process calls</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-e trace=signal - Trace signals</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-e trace=desc - Trace file descriptor operations</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-e trace=ipc - Trace IPC calls</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-o file - Output to file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-s size - String length limit</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-v - Verbose</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-t - Print timestamp</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-tt - Print timestamp with microseconds</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-T - Show time spent in calls</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-r - Relative timestamp</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-x - Print non-ASCII in hex</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-xx - Print all strings in hex</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-y - Print paths associated with file descriptors</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-P path - Trace only this path</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-b execve - Detach on exec</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-D - Run as separate process</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-q - Suppress attach/detach messages</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-qq - Suppress all messages</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Trace Sets</h2>
|
|
<ul>
|
|
<li>file - File operations</li>
|
|
</ul>
|
|
<ul>
|
|
<li>network - Network operations</li>
|
|
</ul>
|
|
<ul>
|
|
<li>process - Process operations</li>
|
|
</ul>
|
|
<ul>
|
|
<li>signal - Signal operations</li>
|
|
</ul>
|
|
<ul>
|
|
<li>desc - File descriptor operations</li>
|
|
</ul>
|
|
<ul>
|
|
<li>ipc - IPC operations</li>
|
|
</ul>
|
|
<ul>
|
|
<li>memory - Memory operations</li>
|
|
</ul>
|
|
<ul>
|
|
<li>all - All system calls</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Common Examples</h2>
|
|
<h3>Trace Command</h3>
|
|
<pre><code>strace ls</code></pre>
|
|
<p>Trace all system calls.</p>
|
|
<h3>Attach to Process</h3>
|
|
<pre><code>strace -p 1234</code></pre>
|
|
<p>Attach to running process.</p>
|
|
<h3>Summary Statistics</h3>
|
|
<pre><code>strace -c command</code></pre>
|
|
<p>Show call counts and timing.</p>
|
|
<h3>Trace File Operations</h3>
|
|
<pre><code>strace -e trace=file command</code></pre>
|
|
<p>Only file-related calls.</p>
|
|
<h3>Trace Network</h3>
|
|
<pre><code>strace -e trace=network command</code></pre>
|
|
<p>Only network calls.</p>
|
|
<h3>Follow Children</h3>
|
|
<pre><code>strace -f command</code></pre>
|
|
<p>Include child processes.</p>
|
|
<h3>With Timestamps</h3>
|
|
<pre><code>strace -tt command</code></pre>
|
|
<p>Show timestamps with microseconds.</p>
|
|
<h3>Show Time Spent</h3>
|
|
<pre><code>strace -T command</code></pre>
|
|
<p>Show time spent in each call.</p>
|
|
<h3>Output to File</h3>
|
|
<pre><code>strace -o trace.log command</code></pre>
|
|
<p>Save trace to file.</p>
|
|
<h3>Trace Specific Call</h3>
|
|
<pre><code>strace -e trace=open,openat command</code></pre>
|
|
<p>Trace specific system calls.</p>
|
|
<hr>
|
|
<h2>Tips</h2>
|
|
<ul>
|
|
<li>Use -c for quick performance overview</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -e trace=file for file debugging</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -e trace=network for network debugging</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -f to trace multi-process applications</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -T to see slow system calls</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -o to save traces for analysis</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Essential for debugging system issues</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Great for security auditing</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script async type="text/javascript" src="../blog/analytics.js"></script>
|
|
<script src="../theme.js"></script>
|
|
</body>
|
|
</html>
|
|
|