Перейти к содержимому

System calls: Following printf Into the Kernel

HeapSmith

0:00 / 0:00

System calls: Following printf Into the Kernel

220 просмотров · 4 дн. назад
HeapSmith
105 подписчиков
220 просмотров · 4 дн. назад
One printf, then fork: a terminal shows hello once, a file gets it twice. To see why, we follow that printf all the way down. It only fills a buffer inside your program, and the bytes leave when the C library calls write, which puts the number 1 in a register and runs syscall, the one instruction that switches the CPU into kernel mode. We watch the kernel save your registers, pick its write handler, check your pointer and hand back the answer, then measure what that round trip costs on a real machine. Related Videos ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ Debuggers: What Happens When You Set a Breakpoint:    • Debuggers: What Happens When You Set a Bre...   What Happens When Your Program Segfaults:    • What Happens When Your Program Segfaults   How Unix Pipes Work:    • How Unix Pipes Work   How Virtual Memory Works:    • How Virtual Memory Works   How a CPU Runs Your Code:    • How a CPU Runs Your Code   Contents ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ 00:00 - One printf, Two Hellos 00:31 - Where printf Puts Your Bytes 01:31 - Why Your Program Has to Ask 02:43 - A Number in a Register 04:08 - One Instruction, One Door 05:20 - The Kernel Takes a Snapshot 06:21 - What write Does With Your Bytes 07:20 - The Way Back Out 08:42 - What a System Call Costs 09:57 - Two Hellos, Explained #operatingsystems #computerscience #programming