0Pricing
Linux Command Line Mastery · レッスン

strace と ltrace でシステムコールを追跡する

プロセスが行うシステムコールやライブラリ呼び出しを追跡し、どこで停止または失敗しているのかを正確に明らかにして、トラブルシューティングをさらに深めます。

「strace と ltrace でシステムコールを追跡する」はCoddyKit上の無料Linux Command Line Masteryレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLinux Command Line Mastery学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Linux Command Line Masteryコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

When Metrics Are Not Enough

CPU, memory, and I/O tools tell you that something is slow. To learn why, you trace what a process actually asks the kernel to do. strace and ltrace open that window.

What strace Shows

strace records every system call: file opens, reads, network sends, and their return values, including errors.

strace ls /tmp

Attaching to a Running Process

Use -p PID to trace something already running, such as a stuck service.

sudo strace -p 4567

Filtering Specific Calls

-e trace= limits output to calls you care about, e.g. only file-related ones.

strace -e trace=openat,read,write cat /etc/hostname

Finding Missing Files

A classic use: see which file a program fails to open. Look for ENOENT (no such file) in the output.

strace -e trace=openat myapp 2>&1 | grep ENOENT

Summarizing with -c

-c prints a profile: which syscalls consumed the most time and how often each was called.

strace -c ls -R /usr/share

Timing Calls

-T shows how long each syscall took, and -t adds timestamps, pinpointing where a process blocks.

strace -T -e trace=read myapp

Following Child Processes

-f follows forks so you trace child processes too, essential for servers that spawn workers.

strace -f -p 4567

Saving Output to a File

Traces are noisy; -o writes them to a file you can grep later without cluttering the terminal.

strace -o trace.log -f myapp

ltrace for Library Calls

While strace shows kernel calls, ltrace shows library calls like malloc or strcmp, useful for logic-level debugging.

ltrace ./myprogram

A Troubleshooting Recipe

When a service hangs: attach with strace -f -p, watch for a syscall that never returns (often a blocked read or connect), and you have found the stall.

Quick Check

What kind of activity does strace primarily reveal?

Recap

You can now trace a process at the syscall level:

  • strace cmd or -p PID to attach
  • -e trace= filters, -c profiles, -T/-t time
  • -f follows children, -o saves output
  • ltrace shows library calls

Watch for errors like ENOENT or a syscall that never returns.

よくある質問

「strace と ltrace でシステムコールを追跡する」レッスンは無料ですか?

はい。「strace と ltrace でシステムコールを追跡する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Command Line Masteryコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Command Line Masteryコースには全4レッスンが含まれています。

「strace と ltrace でシステムコールを追跡する」で何を学びますか?

プロセスが行うシステムコールやライブラリ呼び出しを追跡し、どこで停止または失敗しているのかを正確に明らかにして、トラブルシューティングをさらに深めます。 ブラウザで直接実行するハンズオンコードでLinux Command Line Masteryを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Linux Command Line Masteryを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのLinux Command Line Masteryは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「strace と ltrace でシステムコールを追跡する」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このLinux Command Line Masteryレッスンでコードを書いて実行できますか?

はい。すべてのLinux Command Line Masteryレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ディスクI/Oの監視:`iostat`、`iotop`
  2. メモリとCPUの性能分析ツール
  3. 高度なログ分析とトラブルシューティング
  4. strace と ltrace でシステムコールを追跡する
← Linux Command Line Masteryに戻る