Understanding Linux
Understanding Linux
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!
Table of Contents
- Prologue
-
Introduction
- 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
- Processes
- 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 revisited
- 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
-
Memory management
- Background
- 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
- (chapter in writing)
-
Filesystems
- Background
- Block device layer
- (chapter in writing)
-
Networking
- Background
- The TCP/IP protocol
- Transport layer packets
- Network layer packets
- Domain Name Service (DNS)
- Kernel networking stack overview
- Netfilter
- (chapter in writing)
-
Appendix 1: Kernel process descriptor
- The source code for struct task_struct
-
Appendix 2: The story of Linux
- What, Unix culture?
- Open Source
- The history of Unix
- Research Unix: the origins
- Berkeley Unix (BSD)
- Research Unix: the late years
- The story of vi
- VAX Unix
- The Unix wars
- Unix and Microsoft
- Linux is the evolution of Unix
- FreeBSD: Linux’s lesser-known relative
- The POSIX standard
- The architecture of a Unix system
- The Unix environment
- The bash shell
- About this book
- Notes
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.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $13 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.
Learn more about Leanpub's ebook formats and where to read them