Write software that draws directly on services offered by the Linux kernel and core system libraries. With this comprehensive book, Linux kernel contributor Robert Love provides you with a tutorial on Linux system programming, a reference manual on Linux system calls, and an insider’s guide to writing smarter, faster code.
Love clearly distinguishes between POSIX standard functions and special services offered only by Linux. With a new chapter on multithreading, this updated and expanded edition provides an in-depth look at Linux from both a theoretical and applied perspective over a wide range of programming topics, including:
• A Linux kernel, C library, and C compiler overview
• Basic I/O operations, such as reading from and writing to files
• Advanced I/O interfaces, memory mappings, and optimization techniques
• The family of system calls for basic process management
• Advanced process management, including real-time processes
• Thread concepts, multithreaded programming, and Pthreads
• File and directory management
• Interfaces for allocating memory and optimizing memory access
• Basic and advanced signal interfaces, and their role on the system
• Clock management, including POSIX clocks and high-resolution timers
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
# Linux System Programming: Talking Directly to the Kernel and C Library
## 【One-Line Pitch】
A comprehensive, insider's guide to Linux system programming that bridges the gap between POSIX standards and Linux-specific extensions, teaching you how to write efficient, correct code that talks directly to the kernel. Essential reading for C programmers, systems engineers, and anyone building performance-critical applications on Linux.
## 【Book Arc】
- **Opening (~0%–9%)**: Lays the foundation with essential concepts—the Linux kernel, C library, and compiler toolchain, plus the critical distinction between APIs and ABIs, and how system calls work under the hood.
- **Early (~9%–25%)**: Covers basic file I/O operations (open, read, write, close), error handling via errno, file permissions and ownership semantics, and the everything-is-a-file paradigm including special files and device access.
- **Early (~25%–38%)**: Dives into advanced file I/O—scatter/gather I/O with readv()/writev(), event polling with epoll, and the performance implications of synchronized I/O flags like O_SYNC, O_DSYNC, and O_RSYNC.
- **Middle (~38%–53%)**: Explores buffered I/O through the standard C library, demonstrating why block size matters dramatically for performance, and introduces multiplexed I/O as the solution to concurrent file descriptor monitoring.
- **Late (~53%–100%)**: Extends into process management, threading with Pthreads, memory allocation and optimization, signal handling, and clock/timer management—the full toolkit for production-grade system programming.
## 【Key Takeaways】
- **ABI vs. API distinction matters** (Early): While APIs ensure source compatibility, ABIs guarantee binary compatibility—understanding this difference helps you write code that survives across systems and architectures without recompilation.
- **errno is your error compass** (Early): The errno variable, valid only immediately after a failed call, maps numeric codes to human-readable errors like EACCES for "permission denied"—check it right after any system call returns -1.
- **File ownership has subtle rules** (Early): Linux defaults to System V behavior (new files inherit the creating process's gid), but BSD behavior (inheriting parent directory's gid) kicks in with setgid directories—code that cares must call fchown() explicitly.
- **Block size dramatically impacts I/O performance** (Middle): The dd benchmark shows 18.7 seconds for 1-byte blocks versus 0.025 seconds for 1,024-byte blocks—but unaligned sizes like 1,130 bytes can actually degrade performance despite fewer system calls.
- **O_SYNC is expensive—use it sparingly** (Early): Synchronized I/O can increase elapsed time by one or two orders of magnitude; prefer fsync()/fdatasync() for critical operations rather than forcing sync on every write.
- **Multiplexed I/O solves the blocking problem** (Middle): Instead of busy-polling or blocking on single descriptors, epoll and poll let you sleep efficiently and wake only when any of multiple file descriptors become ready.
- **Symbolic links cost more than hard links** (Early): Resolving a symlink involves resolving two files, and they require special system calls—hard links are transparent and incur no additional overhead.
## 【Reading Tips】
- **Skim Chapter 1's ABI discussion** unless you're writing assembly or toolchain code—the key insight is that the toolchain enforces ABI, so you rarely need to memorize it.
- **Deep-read the buffered I/O chapter** (Chapter 3): The dd benchmark table is worth studying carefully—it teaches the real-world impact of block size selection better than any theory.
- **Pay special attention to the errno table** in Chapter 1—it's a reference you'll return to constantly when debugging system calls.
- **Treat the O_SYNC/O_DSYNC/O_RSYNC discussion** as a decision framework: understand when you truly need synchronized I/O versus when fsync() at critical points suffices.
- **The multiplexed I/O section** (poll/epoll) is where the book shifts from basics to production-grade patterns—read it twice if you're building servers or event-driven applications.
## 【Coverage Limits】
This guide covers the opening through middle sections (roughly 0–53% of the book), focusing on foundational concepts, file I/O, buffered I/O, and multiplexed I/O. The later chapters on process management, threading, memory, signals, and clocks are not covered in the source excerpts.
##
amming). 6 | Chapter 1: Introduction and Essential Concepts Symbolic links incur more overhead than hard links because resolving a symbolic link effectively...
he same effect on any system you are likely to come across. Nonetheless, to compensate for the nonportability of bit positions in the mode, POSIX introduced...
conds 1,130 bytes 0.035 seconds 0.002 seconds 0.027 seconds Using 1,024 byte chunks results in an enormous performance improvement compared to the single byt...
x kernel 2.6.27 and glibc 2.9. A typical call is: int epfd; epfd = epoll_create1 (0); if (epfd < 0) perror ("epoll_create1"); The file descriptor returned fr...
ained relatively unchanged since the earliest days of Unix. It is here, in the subject of process management, that the longevity and forward thinking of Unix...
l Single UNIX Specification, but it has since been removed. 160 | Chapter 5: Process Management groups exist so long as they have one remaining member. Even...
l metric, and such instrumentation is probably quite useful. Nevertheless, we must call a duck a duck! Hard real-time systems often exhibit very low jitter b...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
Linux system programming talking directly to the kernel and C library (Robert Love)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
Linux system programming talking directly to the kernel and C library (Robert Love)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment