Foreword xv Preface xvii Part I: Files and Users 1 Chapter 1: Introduction 3 1.1 The Linux/Unix File Model 3 1.2 The Linux/Unix Process Model 7 1.3 Standard C versus Original C 9 1.4 Why GNU Programs Are Better 13 1.5 Portability Revisited 17 1.6 Some Words about Coding Style 18 1.7 Artificial Intelligence Isn''t Intelligent 19 1.
8 Suggested Reading 19 1.9 Summary 20 Exercises 21 Chapter 2: Arguments, Options, and the Environment 23 2.1 Option and Argument Conventions 23 2.2 Basic Command-Line Processing 26 2.3 Option Parsing: getopt() and getopt_long() 28 2.4 The Environment 37 2.5 Summary 49 Exercises 49 Chapter 3: User-Level Memory Management 51 3.1 Linux/Unix Address Space 51 3.
2 Memory Allocation 55 3.3 Summary 76 Exercises 77 Chapter 4: Files and File I/O 79 4.1 Introducing the Linux/Unix I/O Model 79 4.2 Presenting a Basic Program Structure 79 4.3 Determining What Went Wrong 81 4.4 Doing Input and Output 87 4.5 Random Access: Moving Around within a File 96 4.6 Creating Files 101 4.
7 Forcing Data to Disk 106 4.8 Setting File Length 107 4.9 Summary 108 Exercises 109 Chapter 5: Directories and File Metadata 111 5.1 Considering Directory Contents 111 5.2 Creating and Removing Directories 121 5.3 Reading Directories 123 5.4 Obtaining Information about Files 130 5.5 Avoiding Race Conditions: openat() and Friends 144 5.
6 Changing Ownership, Permission, and Modification Times 145 5.7 Summary 151 Exercises 153 Chapter 6: General Library Interfaces--Part 1 155 6.1 Times and Dates 155 6.2 Sorting and Searching Functions 171 6.3 User and Group Names 190 6.4 Terminals: isatty() 196 6.5 Suggested Reading 196 6.6 Summary 197 Exercises 198 Chapter 7: Putting It All Together: ls 201 7.
1 V7 ls Options 201 7.2 V7 ls Code 202 7.3 Summary 218 Exercises 218 Chapter 8: Filesystems and Directory Walks 221 8.1 Mounting and Unmounting Filesystems 221 8.2 Files for Filesystem Administration 228 8.3 Retrieving Per-Filesystem Information 234 8.4 Moving Around in the File Hierarchy 247 8.5 Processing a File Hierarchy: GNU du 261 8.
6 Changing the Root Directory: chroot() 269 8.7 Summary 270 Exercises 271 Part II: Processes, Networking, and Internationalization 273 Chapter 9: Process Management and Pipes 275 9.1 Process Creation and Management 275 9.2 Process Groups 300 9.3 Basic Interprocess Communication: Pipes and FIFOs 302 9.4 File Descriptor Management 307 9.5 Example: Two-Way Pipes in gawk 323 9.6 Suggested Reading 327 9.
7 Summary 328 Exercises 330 Chapter 10: Signals 333 10.1 Introduction 333 10.2 Signal Actions 333 10.3 Standard C Signals: signal() and raise() 334 10.4 Signal Handlers in Action 337 10.5 The System V Release 3 Signal APIs: sigset() et al. 349 10.6 POSIX Signals 350 10.
7 Signals for Interprocess Communication 360 10.8 Important Special-Purpose Signals 363 10.9 Signals across fork() and exec() 378 10.10 Summary 379 Exercises 381 Chapter 11: Permissions and User and Group ID Numbers 383 11.1 Checking Permissions 383 11.2 Retrieving User and Group IDs 385 11.3 Checking as the Real User: access() 388 11.4 Setting Extra Permission Bits for Directories 391 11.
5 Setting Real and Effective IDs 393 11.6 Working with All Three IDs: getresuid() and setresuid() (Linux) 398 11.7 Crossing a Security Minefield: Setuid root 399 11.8 Suggested Reading 400 11.9 Summary 401 Exercises 403 Chapter 12: Resource Limits 405 12.1 Introduction 405 12.2 System Limits: sysconf(), pathconf(), and fpathconf() 405 12.3 Getting Configuration String Variables: confstr() 411 12.
4 Basic Process Limits: ulimit() 413 12.5 Hard and Soft Limits: getrlimit() and setrlimit() 414 12.6 Summary 417 Exercises 418 Chapter 13: General Library Interfaces--Part 2 419 13.1 Assertion Statements: assert() 419 13.2 Low-Level Memory: The memXXX() Functions 423 13.3 Temporary Files 426 13.4 Committing Suicide: abort() 434 13.5 Nonlocal Gotos 435 13.
6 Pseudorandom Numbers 442 13.7 Metacharacter Expansions 450 13.8 Regular Expressions 459 13.9 Suggested Reading 467 13.10 Summary 468 Exercises 469 Chapter 14: Sockets and Basic Networking 473 14.1 Introduction, with a Little Bit of History 473 14.2 Networking Technologies 474 14.3 Internet Building Blocks 474 14.
4 Networking and Client/Server 477 14.5 Basic Structure of a Server Program 478 14.6 Basic Structure of a Client Program 488 14.7 Specialized Send and Receive Functions 492 14.8 Handling Multiple Open Connections: select() 494 14.9 pselect(): A Smarter Version of select() 501 14.10 Unix-Domain Sockets 502 14.11 Suggested Reading 502 14.
12 Summary 503 Exercises 504 Chapter 15: Internationalization and Localization 507 15.1 Introduction 507 15.2 Locales and the C Library 508 15.3 Dynamic Translation of Program Messages 526 15.4 Can You Spell That for Me, Please? 540 15.5 Suggested Reading 553 15.6 Summary 553 Exercises 555 Chapter 16: Extended Interfaces 557 16.1 Allocating Aligned Memory: posix_memalign() and memalign() 557 16.
2 Locking Files 558 16.3 More Precise Times 567 16.4 Advanced Searching with Binary Trees 575 16.5 Summary 586 Exercises 587 Part III: Debugging and Final Project 589 Chapter 17: Debugging 591 17.1 First Things First 591 17.2 Compilation for Debugging 592 17.3 GDB Basics 593 17.4 Programming for Debugging 606 17.
5 Debugging Tools I: A Modern lint 632 17.6 Debugging Tools II: Memory Allocation Debuggers 633 17.7 Asking for Help 650 17.8 Software Testing 651 17.9 Debugging Rules 653 17.10 Suggested Reading 655 17.11 Summary 656 Exercises 657 Chapter 18: A Project That Ties Everything Together 659 18.1 Project Description 659 18.
2 Suggested Reading 661 Part IV: Appendices 663 Appendix A: Teach Yourself Programming in Ten Years 665 Appendix B: Caldera Ancient UNIX License 671 Appendix C: GNU General Public License 673 Appendix D: License for the One True Awk 685 Appendix E: License for 4.4 BSD Code 687 Index 689.