Book description
The Linux Programming Interface is the definitive guide to the Linux and UNIX programming interface—the interface employed by nearly every application that runs on a Linux or UNIX system.
In this authoritative work, Linux programming expert Michael Kerrisk provides detailed descriptions of the system calls and library functions that you need in order to master the craft of system programming, and accompanies his explanations with clear, complete example programs.
You'll find descriptions of over 500 system calls and library functions, and more than 200 example programs, 88 tables, and 115 diagrams. You'll learn how to:
- Read and write files efficiently
- Use signals, clocks, and timers
- Create processes and execute programs
- Write secure programs
- Write multithreaded programs using POSIX threads
- Build and use shared libraries
- Perform interprocess communication using pipes, message queues, shared memory, and semaphores
- Write network applications with the sockets API
While The Linux Programming Interface covers a wealth of Linux-specific features, including epoll, inotify, and the /proc file system, its emphasis on UNIX standards (POSIX.1-2001/SUSv3 and POSIX.1-2008/SUSv4) makes it equally valuable to programmers working on other UNIX platforms.
The Linux Programming Interface is the most comprehensive single-volume work on the Linux and UNIX programming interface, and a book that's destined to become a new classic.
Praise for The Linux Programming Interface "If I had to choose a single book to sit next to my machine when writing software for Linux, this would be it." Martin Landers, Software Engineer, Google "This book, with its detailed descriptions and examples, contains everything you need to understand the details and nuances of the low-level programming APIs in Linux . . . no matter what the level of reader, there will be something to be learnt from this book." Mel Gorman, Author of Understanding the Linux Virtual Memory Manager "Michael Kerrisk has not only written a great book about Linux programming and how it relates to various standards, but has also taken care that bugs he noticed got fixed and the man pages were (greatly) improved. In all three ways, he has made Linux programming easier. The in-depth treatment of topics in The Linux Programming Interface . . . makes it a must-have reference for both new and experienced Linux programmers." Andreas Jaeger, Program Manager, openSUSE, Novell "Michael's inexhaustible determination to get his information right, and to express it clearly and concisely, has resulted in a strong reference source for programmers. While this work is targeted at Linux programmers, it will be of value to any programmer working in the UNIX/POSIX ecosystem." David Butenhof, Author of Programming with POSIX Threads and Contributor to the POSIX and UNIX Standards ". . . a very thorough—yet easy to read—explanation of UNIX system and network programming, with an emphasis on Linux systems. It's certainly a book I'd recommend to anybody wanting to get into UNIX programming (in general) or to experienced UNIX programmers wanting to know 'what's new' in the popular GNU/Linux system." Fernando Gont, Network Security Researcher, IETF Participant, and RFC Author ". . . encyclopedic in the breadth and depth of its coverage, and textbook-like in its wealth of worked examples and exercises. Each topic is clearly and comprehensively covered, from theory to hands-on working code. Professionals, students, educators, this is the Linux/UNIX reference that you have been waiting for." Anthony Robins, Associate Professor of Computer Science, The University of Otago "I've been very impressed by the precision, the quality and the level of detail Michael Kerrisk put in his book. He is a great expert of Linux system calls and lets us share his knowledge and understanding of the Linux APIs." Christophe Blaess, Author of Programmation systeme en C sous Linux ". . . an essential resource for the serious or professional Linux and UNIX systems programmer. Michael Kerrisk covers the use of all the key APIs across both the Linux and UNIX system interfaces with clear descriptions and tutorial examples and stresses the importance and benefits of following standards such as the Single UNIX Specification and POSIX 1003.1." Andrew Josey, Director, Standards, The Open Group, and Chair of the POSIX 1003.1 Working Group "What could be better than an encyclopedic reference to the Linux system, from the standpoint of the system programmer, written by none other than the maintainer of the man pages himself? The Linux Programming Interface is comprehensive and detailed. I firmly expect it to become an indispensable addition to my programming bookshelf." Bill Gallmeister, Author of POSIX.4 Programmer's Guide: Programming for the Real World ". . . the most complete and up-to-date book about Linux and UNIX system programming. If you're new to Linux system programming, if you're a UNIX veteran focused on portability while interested in learning the Linux way, or if you're simply looking for an excellent reference about the Linux programming interface, then Michael Kerrisk's book is definitely the companion you want on your bookshelf." Loic Domaigne, Chief Software Architect (Embedded), Corpuls.comPublisher resources
Table of contents
- Cover
- Title Page
- Copyright Page
- Brief Contents
- Contents in Detail
- Preface
- Chapter 1: History and Standards
-
Chapter 2: Fundamental Concepts
- 2.1 The Core Operating System: The Kernel
- 2.2 The Shell
- 2.3 Users and Groups
- 2.4 Single Directory Hierarchy, Directories, Links, and Files
- 2.5 File I/O Model
- 2.6 Programs
- 2.7 Processes
- 2.8 Memory Mappings
- 2.9 Static and Shared Libraries
- 2.10 Interprocess Communication and Synchronization
- 2.11 Signals
- 2.12 Threads
- 2.13 Process Groups and Shell Job Control
- 2.14 Sessions, Controlling Terminals, and Controlling Processes
- 2.15 Pseudoterminals
- 2.16 Date and Time
- 2.17 Client-Server Architecture
- 2.18 Realtime
- 2.19 The /proc File System
- 2.20 Summary
- Chapter 3: System Programming Concepts
- Chapter 4: File I/O: The Universal I/O Model
-
Chapter 5: File I/O: Further Details
- 5.1 Atomicity and Race Conditions
- 5.2 File Control Operations: fcntl()
- 5.3 Open File Status Flags
- 5.4 Relationship Between File Descriptors and Open Files
- 5.5 Duplicating File Descriptors
- 5.6 File I/O at a Specified Offset: pread() and pwrite()
- 5.7 Scatter-Gather I/O: readv() and writev()
- 5.8 Truncating a File: truncate() and ftruncate()
- 5.9 Nonblocking I/O
- 5.10 I/O on Large Files
- 5.11 The /dev/fd Directory
- 5.12 Creating Temporary Files
- 5.13 Summary
- 5.14 Exercises
- Chapter 6: Processes
- Chapter 7: Memory Allocation
- Chapter 8: Users and Groups
-
Chapter 9: Process Credentials
- 9.1 Real User ID and Real Group ID
- 9.2 Effective User ID and Effective Group ID
- 9.3 Set-User-ID and Set-Group-ID Programs
- 9.4 Saved Set-User-ID and Saved Set-Group-ID
- 9.5 File-System User ID and File-System Group ID
- 9.6 Supplementary Group IDs
- 9.7 Retrieving and Modifying Process Credentials
- 9.8 Summary
- 9.9 Exercises
- Chapter 10: Time
- Chapter 11: System Limits and Options
- Chapter 12: System and Process Information
-
Chapter 13: File I/O Buffering
- 13.1 Kernel Buffering of File I/O: The Buffer Cache
- 13.2 Buffering in the stdio Library
- 13.3 Controlling Kernel Buffering of File I/O
- 13.4 Summary of I/O Buffering
- 13.5 Advising the Kernel About I/O Patterns
- 13.6 Bypassing the Buffer Cache: Direct I/O
- 13.7 Mixing Library Functions and System Calls for File I/O
- 13.8 Summary
- 13.9 Exercises
-
Chapter 14: File Systems
- 14.1 Device Special Files (Devices)
- 14.2 Disks and Partitions
- 14.3 File Systems
- 14.4 I-nodes
- 14.5 The Virtual File System (VFS)
- 14.6 Journaling File Systems
- 14.7 Single Directory Hierarchy and Mount Points
- 14.8 Mounting and Unmounting File Systems
- 14.9 Advanced Mount Features
- 14.10 A Virtual Memory File System: tmpfs
- 14.11 Obtaining Information About a File System: statvfs()
- 14.12 Summary
- 14.13 Exercise
-
Chapter 15: File Attributes
- 15.1 Retrieving File Information: stat()
- 15.2 File Timestamps
- 15.3 File Ownership
-
15.4 File Permissions
- 15.4.1 Permissions on Regular Files
- 15.4.2 Permissions on Directories
- 15.4.3 Permission-Checking Algorithm
- 15.4.4 Checking File Accessibility: access()
- 15.4.5 Set-User-ID, Set-Group-ID, and Sticky Bits
- 15.4.6 The Process File Mode Creation Mask: umask()
- 15.4.7 Changing File Permissions: chmod() and fchmod()
- 15.5 I-node Flags (ext2 Extended File Attributes)
- 15.6 Summary
- 15.7 Exercises
- Chapter 16: Extended Attributes
- Chapter 17: Access Control Lists
-
Chapter 18: Directories and Links
- 18.1 Directories and (Hard) Links
- 18.2 Symbolic (Soft) Links
- 18.3 Creating and Removing (Hard) Links: link() and unlink()
- 18.4 Changing the Name of a File: rename()
- 18.5 Working with Symbolic Links: symlink() and readlink()
- 18.6 Creating and Removing Directories: mkdir() and rmdir()
- 18.7 Removing a File or Directory: remove()
- 18.8 Reading Directories: opendir() and readdir()
- 18.9 File Tree Walking: nftw()
- 18.10 The Current Working Directory of a Process
- 18.11 Operating Relative to a Directory File Descriptor
- 18.12 Changing the Root Directory of a Process: chroot()
- 18.13 Resolving a Pathname: realpath()
- 18.14 Parsing Pathname Strings: dirname() and basename()
- 18.15 Summary
- 18.16 Exercises
- Chapter 19: Monitoring File Events
-
Chapter 20: Signals: Fundamental Concepts
- 20.1 Concepts and Overview
- 20.2 Signal Types and Default Actions
- 20.3 Changing Signal Dispositions: signal()
- 20.4 Introduction to Signal Handlers
- 20.5 Sending Signals: kill()
- 20.6 Checking for the Existence of a Process
- 20.7 Other Ways of Sending Signals: raise() and killpg()
- 20.8 Displaying Signal Descriptions
- 20.9 Signal Sets
- 20.10 The Signal Mask (Blocking Signal Delivery)
- 20.11 Pending Signals
- 20.12 Signals Are Not Queued
- 20.13 Changing Signal Dispositions: sigaction()
- 20.14 Waiting for a Signal: pause()
- 20.15 Summary
- 20.16 Exercises
- Chapter 21: Signals: Signal Handlers
-
Chapter 22: Signals: Advanced Features
- 22.1 Core Dump Files
- 22.2 Special Cases for Delivery, Disposition, and Handling
- 22.3 Interruptible and Uninterruptible Process Sleep States
- 22.4 Hardware-Generated Signals
- 22.5 Synchronous and Asynchronous Signal Generation
- 22.6 Timing and Order of Signal Delivery
- 22.7 Implementation and Portability of signal()
- 22.8 Realtime Signals
- 22.9 Waiting for a Signal Using a Mask: sigsuspend()
- 22.10 Synchronously Waiting for a Signal
- 22.11 Fetching Signals via a File Descriptor
- 22.12 Interprocess Communication with Signals
- 22.13 Earlier Signal APIs (System V and BSD)
- 22.14 Summary
- 22.15 Exercises
- Chapter 23: Timers and Sleeping
- Chapter 24: Process Creation
- Chapter 25: Process Termination
- Chapter 26: Monitoring Child Processes
- Chapter 27: Program Execution
- Chapter 28: Process Creation and Program Execution in More Detail
- Chapter 29: Threads: Introduction
- Chapter 30: Threads: Thread Synchronization
- Chapter 31: Threads: Thread Safety and Per-Thread Storage
- Chapter 32: Threads: Thread Cancellation
- Chapter 33: Threads: Further Details
- Chapter 34: Process Groups, Sessions, and Job Control
- Chapter 35: Process Priorities and Scheduling
- Chapter 36: Process Resources
- Chapter 37: Daemons
-
Chapter 38: Writing Secure Privileged Programs
- 38.1 Is a Set-User-ID or Set-Group-ID Program Required?
- 38.2 Operate with Least Privilege
- 38.3 Be Careful When Executing a Program
- 38.4 Avoid Exposing Sensitive Information
- 38.5 Confine the Process
- 38.6 Beware of Signals and Race Conditions
- 38.7 Pitfalls When Performing File Operations and File I/O
- 38.8 Don’t Trust Inputs or the Environment
- 38.9 Beware of Buffer Overruns
- 38.10 Beware of Denial-of-Service Attacks
- 38.11 Check Return Statuses and Fail Safely
- 38.12 Summary
- 38.13 Exercises
-
Chapter 39: Capabilities
- 39.1 Rationale for Capabilities
- 39.2 The Linux Capabilities
-
39.3 Process and File Capabilities
- 39.3.1 Process Capabilities
- 39.3.2 File Capabilities
- 39.3.3 Purpose of the Process Permitted and Effective Capability Sets
- 39.3.4 Purpose of the File Permitted and Effective Capability Sets
- 39.3.5 Purpose of the Process and File Inheritable Sets
- 39.3.6 Assigning and Viewing File Capabilities from the Shell
- 39.4 The Modern Capabilities Implementation
- 39.5 Transformation of Process Capabilities During exec()
- 39.6 Effect on Process Capabilities of Changing User IDs
- 39.7 Changing Process Capabilities Programmatically
- 39.8 Creating Capabilities-Only Environments
- 39.9 Discovering the Capabilities Required by a Program
- 39.10 Older Kernels and Systems Without File Capabilities
- 39.11 Summary
- 39.12 Exercise
- Chapter 40: Login Accounting
-
Chapter 41: Fundamentals of Shared Libraries
- 41.1 Object Libraries
- 41.2 Static Libraries
- 41.3 Overview of Shared Libraries
- 41.4 Creating and Using Shared Libraries—A First Pass
- 41.5 Useful Tools for Working with Shared Libraries
- 41.6 Shared Library Versions and Naming Conventions
- 41.7 Installing Shared Libraries
- 41.8 Compatible Versus Incompatible Libraries
- 41.9 Upgrading Shared Libraries
- 41.10 Specifying Library Search Directories in an Object File
- 41.11 Finding Shared Libraries at Run Time
- 41.12 Run-Time Symbol Resolution
- 41.13 Using a Static Library Instead of a Shared Library
- 41.14 Summary
- 41.15 Exercise
- Chapter 42: Advanced Features of Shared Libraries
- Chapter 43: Interprocess Communication Overview
-
Chapter 44: Pipes and FIFOs
- 44.1 Overview
- 44.2 Creating and Using Pipes
- 44.3 Pipes as a Method of Process Synchronization
- 44.4 Using Pipes to Connect Filters
- 44.5 Talking to a Shell Command via a Pipe: popen()
- 44.6 Pipes and stdio Buffering
- 44.7 FIFOs
- 44.8 A Client-Server Application Using FIFOs
- 44.9 Nonblocking I/O
- 44.10 Semantics of read() and write() on Pipes and FIFOs
- 44.11 Summary
- 44.12 Exercises
-
Chapter 45: Introduction to System V IPC
- 45.1 API Overview
- 45.2 IPC Keys
- 45.3 Associated Data Structure and Object Permissions
- 45.4 IPC Identifiers and Client-Server Applications
- 45.5 Algorithm Employed by System V IPC get Calls
- 45.6 The ipcs and ipcrm Commands
- 45.7 Obtaining a List of All IPC Objects
- 45.8 IPC Limits
- 45.9 Summary
- 45.10 Exercises
-
Chapter 46: System V Message Queues
- 46.1 Creating or Opening a Message Queue
- 46.2 Exchanging Messages
- 46.3 Message Queue Control Operations
- 46.4 Message Queue Associated Data Structure
- 46.5 Message Queue Limits
- 46.6 Displaying All Message Queues on the System
- 46.7 Client-Server Programming with Message Queues
- 46.8 A File-Server Application Using Message Queues
- 46.9 Disadvantages of System V Message Queues
- 46.10 Summary
- 46.11 Exercises
-
Chapter 47: System V Semaphores
- 47.1 Overview
- 47.2 Creating or Opening a Semaphore Set
- 47.3 Semaphore Control Operations
- 47.4 Semaphore Associated Data Structure
- 47.5 Semaphore Initialization
- 47.6 Semaphore Operations
- 47.7 Handling of Multiple Blocked Semaphore Operations
- 47.8 Semaphore Undo Values
- 47.9 Implementing a Binary Semaphores Protocol
- 47.10 Semaphore Limits
- 47.11 Disadvantages of System V Semaphores
- 47.12 Summary
- 47.13 Exercises
-
Chapter 48: System V Shared Memory
- 48.1 Overview
- 48.2 Creating or Opening a Shared Memory Segment
- 48.3 Using Shared Memory
- 48.4 Example: Transferring Data via Shared Memory
- 48.5 Location of Shared Memory in Virtual Memory
- 48.6 Storing Pointers in Shared Memory
- 48.7 Shared Memory Control Operations
- 48.8 Shared Memory Associated Data Structure
- 48.9 Shared Memory Limits
- 48.10 Summary
- 48.11 Exercises
-
Chapter 49: Memory Mappings
- 49.1 Overview
- 49.2 Creating a Mapping: mmap()
- 49.3 Unmapping a Mapped Region: munmap()
- 49.4 File Mappings
- 49.5 Synchronizing a Mapped Region: msync()
- 49.6 Additional mmap() Flags
- 49.7 Anonymous Mappings
- 49.8 Remapping a Mapped Region: mremap()
- 49.9 MAP_NORESERVE and Swap Space Overcommitting
- 49.10 The MAP_FIXED Flag
- 49.11 Nonlinear Mappings: remap_file_pages()
- 49.12 Summary
- 49.13 Exercises
- Chapter 50: Virtual Memory Operations
- Chapter 51: Introduction to POSIX IPC
-
Chapter 52: POSIX Message Queues
- 52.1 Overview
- 52.2 Opening, Closing, and Unlinking a Message Queue
- 52.3 Relationship Between Descriptors and Message Queues
- 52.4 Message Queue Attributes
- 52.5 Exchanging Messages
- 52.6 Message Notification
- 52.7 Linux-Specific Features
- 52.8 Message Queue Limits
- 52.9 Comparison of POSIX and System V Message Queues
- 52.10 Summary
- 52.11 Exercises
- Chapter 53: POSIX Semaphores
- Chapter 54: POSIX Shared Memory
- Chapter 55: File Locking
- Chapter 56: Sockets: Introduction
- Chapter 57: Sockets: UNIX Domain
- Chapter 58: Sockets: Fundamentals of TCP/IP Networks
-
Chapter 59: Sockets: Internet Domains
- 59.1 Internet Domain Sockets
- 59.2 Network Byte Order
- 59.3 Data Representation
- 59.4 Internet Socket Addresses
- 59.5 Overview of Host and Service Conversion Functions
- 59.6 The inet_pton() and inet_ntop() Functions
- 59.7 Client-Server Example (Datagram Sockets)
- 59.8 Domain Name System (DNS)
- 59.9 The /etc/services File
- 59.10 Protocol-Independent Host and Service Conversion
- 59.11 Client-Server Example (Stream Sockets)
- 59.12 An Internet Domain Sockets Library
- 59.13 Obsolete APIs for Host and Service Conversions
- 59.14 UNIX Versus Internet Domain Sockets
- 59.15 Further Information
- 59.16 Summary
- 59.17 Exercises
- Chapter 60: Sockets: Server Design
-
Chapter 61: Sockets: Advanced Topics
- 61.1 Partial Reads and Writes on Stream Sockets
- 61.2 The shutdown() System Call
- 61.3 Socket-Specific I/O System Calls: recv() and send()
- 61.4 The sendfile() System Call
- 61.5 Retrieving Socket Addresses
- 61.6 A Closer Look at TCP
- 61.7 Monitoring Sockets: netstat
- 61.8 Using tcpdump to Monitor TCP Traffic
- 61.9 Socket Options
- 61.10 The SO_REUSEADDR Socket Option
- 61.11 Inheritance of Flags and Options Across accept()
- 61.12 TCP Versus UDP
- 61.13 Advanced Features
- 61.14 Summary
- 61.15 Exercises
-
Chapter 62: Terminals
- 62.1 Overview
- 62.2 Retrieving and Modifying Terminal Attributes
- 62.3 The stty Command
- 62.4 Terminal Special Characters
- 62.5 Terminal Flags
- 62.6 Terminal I/O Modes
- 62.7 Terminal Line Speed (Bit Rate)
- 62.8 Terminal Line Control
- 62.9 Terminal Window Size
- 62.10 Terminal Identification
- 62.11 Summary
- 62.12 Exercises
- Chapter 63: Alternative I/O Models
- Chapter 64: Pseudoterminals
- Appendix A: Tracing System Calls
- Appendix B: Parsing Command-Line Options
- Appendix C: Casting the NULL Pointer
- Appendix D: Kernel Configuration
- Appendix E: Further Sources of Information
- Appendix F: Solutions to Selected Exercises
- Bibliography
- Index
Product information
- Title: The Linux Programming Interface
- Author(s):
- Release date: October 2010
- Publisher(s): No Starch Press
- ISBN: 9781593272203
You might also like
book
The Linux Command Line, 2nd Edition
The Linux Command Line takes you from your very first terminal keystrokes to writing full programs …
book
Learning Modern Linux
If you use Linux in development or operations and need a structured approach to help you …
book
Understanding the Linux Kernel, 3rd Edition
In order to thoroughly understand what makes Linux tick and why it works so well on …
book
How Linux Works, 3rd Edition
Unlike some operating systems, Linux doesn’t try to hide the important bits from you—it gives you …