The Kernel Perspective
About the Book
This book is about Linux from the kernel perspective: we aim to learn about Linux by having a serious peek under the hood of the kernel. This book is intended for an informed Linux enthusiast, one who knows something about Linux (perhaps a great deal in some areas) but is curious about how all the pieces fit together under the control of the kernel. The kernel is highly efficient and designed to be invisible to the untrained eye, and therefore it's easy to miss. This book is intended for those who would like to know how things work "under the hood", but do not necessarily aspire to become kernel developers (so we skip many details, especially details that do not contribute to understanding the principles, for example, device drivers). We examine how the Linux environment operates, how this relates to the design principles of Unix, and why Linux works exactly the way it does. We experiment on the command line (from the Unix shell), by looking into the representative sections of the kernel source code, and by kernel programming (by writing kernel-loadable modules). Specially prepared Kernel Exercises use kernel modules to play with internal kernel structures and illustrate specific points. The exercises involve writing actual kernel modules, inserting them into a running kernel, and observing the effects or outputs. This book is designed so that anyone with a basic knowledge of programming and a working Linux system should be able to follow examples and execute Kernel Exercises. This book is a work in progress (currently ~80% complete). Finally, to those who already bought the book, thank you!
- What is the Linux kernel?
- Getting the kernel source code
- Kernel space, user space, and system calls
- Kernel modules
- Kernel Exercise 1.1: Building your first kernel module
- Kernel Exercise 1.2: Passing a parameter to a kernel module
- Kernel Exercise 1.3: Kernel modules and pseudo filesystems sysfs and procfs
- Chapter Summary
Executable files, processes, and system calls
- init, the first user space process
- Kernel Exercise 2.1: Find out how kernel starts /sbin/init
- Executable files
- ELF files
- ELF of a simple program
- A closer look at the ELF header
- Kernel Exercise 2.2: Process descriptor
- The user view of processes: /proc directory
- Kernel Exercise 2.3: Loop through the task list, print processes
- Kernel Exercise 2.4: Print the PID and PPID for a process
- Kernel Exercise 2.5: Find a process by its PID
- System calls
- Kernel Exercise 2.6: The execve system call in kernel
How shells execute programs
- Invoking program execution with the C function execve()
- Forking the process: the C function fork()
- excve() system call
- A closer look how bash executes programs
- A look at the bash source code
- The bash protocol for program execution
- The hash-bang directive
- A simple Unix shell in C
- Virtual memory
- A process view of memory: the heap and the stack
- Memory addresses and pages
- Virtual address space
- Virtual memory areas (VMAs)
- Virtual memory for many processes simultaneously
- The kernel memory structures
- Kernel Exercise 4.1: Print the VMA start/end address
- Kernel Exercise 4.2: Print VMAs of a process
- Kernel Exercise 4.3: Print mm pointers with VMA boundaries
- Block device layer
- (chapter in writing)
- TCP/IP protocol
- The transport layer (Layer 4)
- The network layer (Layer 3)
- Domain Name Service (DNS)
- Kernel networking stack overview
- (chapter in writing)
Appending 1: Kernel process descriptor
- The source code for struct task_struct
- About this book
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.