Saturday, August 24, 2013

[Book] Linux System Programming, 2nd edition

 I have recently finished reading the 2nd edition of Linux System Programming book by Robert Love. This post is intended to be a summary and a short review for what I believe to be a great book.

 A common issue with Unix/Linux books that cover the system API is that potential readers, rightfully ask the same question: What is the added value over the already excellent and extensive manual pages ? And this, indeed, is a very legitimate concern. In my opinion, a better approach to read a book like LSP2 is to consider it as a "tour de force", one that discusses various topics, and is more focused on breadth and introducing to new concepts and topics, without going down the rabbit hole.

 My first impression after taking a look at the table of contents is that the booked felt like a shorter, Linux specific APUE. For whatever it worths, this could be a good thing if you are mainly interested in the GNU/Linux environment and don't fancy going through a thousand pages long book. Sadly, there was no discussion of networking related interfaces. Also, for some reason, chapters from 6 and on had no conclusion, unlike the earlier ones.

 Chapter 1 is your usual introduction to the subject chapter. The files and file-system discussion as well as the error handling one were distinctively enjoyable.

 Chapters 2, 3 and 4 are about I/O. Files in unix are the most fundamental abstraction and the author spends a good amount of time (+110 pages) examining topics as simple and known as open()/read()/close() to the more advanced ones such as Linux's epoll() interface, file mapping, file advice and async I/O (though scarce for the latter.) The kernel internals part in chapter 2 and I/O schedulers in chapter 4 demonstrate the author's familiarity with the Linux kernel. Other discussed topics of interest include synchronized I/O (both fsync() and O_SYNC flag), buffering in user-space (glibc implementation, advantages, disadvantages etc,.), multiplexed I/O with select()/poll() and vectored I/O with readv()/writev().

 Chapter 5 and 6 tackle the process management subject ranging from explaining the difference between a process, thread and program, to real-time systems and resource limits, going through process creation/destruction, permissions and process scheduling.

 Chapter 7 deals marvelously with the thorny threads subject, starting with general information such as design patterns, threads implementation in the kernel, comparing with process forking approach, virtual memory, advantages/disadvantages, different models for the relations between kernel threads and user threads, race conditions and synchronization (mutexes, deadlocks...) Later on, Linux' pthreads interface is explained. This is hands-down my favorite chapter as it was for most a "not a man pages dump".

 Again with files, but this time with directories chapter 8 takes a general look at various management interfaces to deal with files metadata, xattrs, permissions, directories creation and removal, linking, copying and moving files and monitoring file events with inotify() interface (that is how your file manager updates automatically when a new file is created in the current folder by another program ;))

 Chapter 9 is about memory management, both dynamic allocations and tuning as well as stack-based allocations while also explaining concepts such as virtual/physical pages, memory locking, memory manipulation and anonymous memory mappings.

 Chapter 10 discusses the subject of signals in unix, different signals values and management (waiting, blocking, sending etc,.), the concept of reentrancy and signal sets.

 Chapter 11 examines the topic of time, ranging the different ways to measure time, the used time structures, posix clocks, sleeping and waiting to the various available timers.

 The appendix about GCC extensions to the C language was a very enjoyable read, both shedding the light about not often-used but very useful extensions to the so widely-used ones that we may take for granted.

 Overall, LSP2nd is a great book due to the author's long familiarity with both kernel-space and user-space code and experience in book authoring. Anyone with intermediate C programming skills should consider reading it. The book is clearly not targeted for C novice programmers and those with no experience using Linux.

No comments:

Post a Comment