การติดตามการเรียกระบบด้วย strace และ ltrace
เจาะลึกการแก้ไขปัญหาด้วยการติดตามการเรียกระบบและไลบรารีที่โพรเซสใช้งาน เพื่อดูได้อย่างชัดเจนว่าโพรเซสหยุดทำงานหรือล้มเหลวที่จุดใด
การติดตามการเรียกระบบด้วย strace และ ltrace เป็นบทเรียน Linux Command Line Mastery ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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 /tmpAttaching to a Running Process
Use -p PID to trace something already running, such as a stuck service.
sudo strace -p 4567Filtering 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/hostnameFinding 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 ENOENTSummarizing with -c
-c prints a profile: which syscalls consumed the most time and how often each was called.
strace -c ls -R /usr/shareTiming Calls
-T shows how long each syscall took, and -t adds timestamps, pinpointing where a process blocks.
strace -T -e trace=read myappFollowing Child Processes
-f follows forks so you trace child processes too, essential for servers that spawn workers.
strace -f -p 4567Saving 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 myappltrace for Library Calls
While strace shows kernel calls, ltrace shows library calls like malloc or strcmp, useful for logic-level debugging.
ltrace ./myprogramA 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 cmdor-p PIDto attach-e trace=filters,-cprofiles,-T/-ttime-ffollows children,-osaves outputltraceshows library calls
Watch for errors like ENOENT or a syscall that never returns.
คำถามที่พบบ่อย
บทเรียน “การติดตามการเรียกระบบด้วย strace และ ltrace” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การติดตามการเรียกระบบด้วย strace และ ltrace” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Linux Command Line Mastery ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การติดตามการเรียกระบบด้วย strace และ ltrace”
เจาะลึกการแก้ไขปัญหาด้วยการติดตามการเรียกระบบและไลบรารีที่โพรเซสใช้งาน เพื่อดูได้อย่างชัดเจนว่าโพรเซสหยุดทำงานหรือล้มเหลวที่จุดใด คุณปฏิบัติ Linux Command Line Mastery ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Linux Command Line Mastery หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Linux Command Line Mastery บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การติดตามการเรียกระบบด้วย strace และ ltrace” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Linux Command Line Mastery นี้ได้ไหม
ได้ บทเรียน Linux Command Line Mastery ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การตรวจสอบดิสก์ I/O: `iostat`, `iotop`
- เครื่องมือประสิทธิภาพหน่วยความจำและ CPU
- เทคนิคการบันทึกเหตุการณ์และแก้ไขปัญหาขั้นสูง
- การติดตามการเรียกระบบด้วย strace และ ltrace