Module 05 · How Computers Work · Talking to the kernel · with code: Go · about 19 min to read
Continue where you left off ×
The tap on the shoulder
IO Interrupts and the Bus · Open board
A device ringing for the processor’s attention instead of being checked on. This lesson is the same idea one floor up: the kernel ringing for the attention of a running program.
Before you start. A process is one running program, and the kernel is the program underneath all of them, which hands out turns and does the risky jobs for them (Processes, Threads & the Kernel ). The lesson ends on a server that gives work to a fixed crew of workers, built later in Build a thread pool .
The idea in 30 seconds
A signal is a small numbered message that interrupts a running program between any two instructions. It comes from a key, the kernel, or another program.
SIGINT asks a program to stop, SIGTERM asks it to finish and go, SIGKILL cannot be answered or ignored, SIGSEGV is the kernel reporting a bad memory access, and SIGCHLD says a child changed state.
A handler is a function the program prepares to run when a signal arrives. It should do almost nothing, usually set a flag that the main loop checks.
A signal that lands during a system call can make it fail with EINTR, “interrupted, ask again”. A flag can ask the kernel to restart the call instead.
A graceful shutdown on SIGTERM stops accepting, finishes the accepted work, and exits 0. Measured here, SIGTERM lost no jobs and SIGKILL lost all five.
A zombie is a child that has ended but whose parent has not yet called wait. PID 1 adopts orphans and has to wait for them.
Read the story
Lesson 29 of 41 in How Computers Work
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson 1974: a key that stops a program from outside SIGINT, SIGTERM, SIGKILL, SIGSEGV, SIGCHLD: what each tap says The handler: answering the tap, and why it can say almost nothing EINTR: a tap while you wait SIGTERM, then drain: a graceful shutdown The zombie: ended, but not yet signed for Terms it explains: signal, default action, handler, flag-and-check, EINTR, graceful shutdown, zombie, blocking I/O, bootloader (GRUB), bus, device driver, DMA, event loop, firmware (BIOS/UEFI), I/O-bound vs CPU-bound, init / systemd, interrupt, ISR / interrupt handler, memory-mapped I/O, non-blocking / async I/O, polling, timer interrupt.
Review How Computers Work
Mark as read Saved in this browser, and to your account when you sign in.