This book describes the Linux API (application programming interface)—the system calls, library functions, and other low-level interfaces provided by Linux, a widely used free implementation of the long-established Unix operating system. These interfaces are used, directly or indirectly, by every program that runs on Linux. Programs that explicitly use these interfaces are commonly called system programs, and include applications such as shells, editors, windowing systems, terminal emulators, file managers, compilers, database management systems, virtual machines, network servers, and much other software that is employed on a daily basis on Linux systems. The book is written to be used both as an introductory guide for readers new to the topic of system programming, and as a comprehensive reference for experienced system programmers.
We describe most Linux system calls, along with many related C library functions (as implemented in the GNU C library, glibc). These interfaces allow programs to perform tasks such as: low-level file I/O; creation of new processes and execution of programs; retrieval and modification of process attributes; communication and synchronization between processes and threads on the same host (computer); and communication between processes residing on different hosts connected via a TCP/IP network. We usually illustrate the use of each interface with a small program.
Although this book focuses on Linux, it gives careful attention to standards and portability issues, and clearly indicates those parts of the discussion that refer to Linux-specific details. As such, the book also provides a comprehensive description of the Unix/POSIX API and thus can be used by programmers writing applications targeted at other Unix systems or intended to be portable across multiple systems.
Intended audience and background required
This book is primarily aimed at the following readers:
- programmers and software designers building applications for Linux, other Unix systems, or other POSIX-conformant systems;
- programmers porting applications between Linux and other Unix implementations or between Linux and other operating systems;
- teachers and advanced students teaching or learning Linux or Unix system programming; and
- anyone (e.g., system managers and "power users") wishing to gain a greater understanding of the Linux/Unix API and of how various pieces of system software are implemented.
Standards and portability
Although this book describes the features of a specific Unix implementation, we take special care to consider portability issues. Frequent reference is made to relevant standards, in particular, the combined POSIX.1-2001 and Single UNIX Specification version 3 (SUSv3) standard; we also note changes in the recent revision of that standard, the combined POSIX.1-2008 and SUSv4. For features that are not standardized, we try to indicate the range of differences on other Unix implementations. We also highlight those major features of Linux that are implementation-specific, as well as pointing out various minor differences between the implementation of system calls and library functions on Linux versus other Unix implementations. (Conversely, where we do not indicate a feature as being Linux-specific, the reader can normally assume that it is a standard feature that appears on most or all Unix implementations.)
Linux and Unix
This book could have been purely about Unix system programming: most features found on other Unix implementations are also present on Linux, and vice versa. However, while emphasizing that writing portable applications is an important goal, I have chosen to also cover a range of Linux-specific extensions to the standard Unix API. The rationale for this approach is as follows:
- The use of nonstandard extensions is sometimes essential, either for performance reasons, or to access functionality that is unavailable in the standard Unix API. (All Unix implementations provide nonstandard extensions for these reasons.)
- I chose to focus on Linux because it is the implementation that I find to be the most important and interesting for a combination of reasons including its openness, licensing model, development model, and steadily increasing market share. (Ultimately, these reasons led me to become an active participant in Linux development.)
Usage and organization
This book is written to be used in two ways:
- As a tutorial introduction to the Linux/Unix API. The book can (if you have a lot of time) be read linearly: later chapters build on material presented in earlier chapters, with forward references minimized as far as possible.
- As a comprehensive reference to the Linux/Unix API, for use by experienced Linux and Unix programmers. An extensive index and heavy use of cross-referencing allow topics to be read in random order.