没有合适的资源?快使用搜索试试~ 我知道了~
首页Linux Programming by Example - The Fundamentals
资源详情
资源评论
资源推荐

C opyright
Preface
Audience
What You Will Learn
Small Is Beautiful: Unix Programs
Standards
Features and Power: GNU Programs
Summary of Chapters
Typographical Conventions
Where to Get Unix and GNU Source Code
Unix Code
GNU Code
Where to Get the Example Programs Used in This Book
About the C over
Acknowledgments
Part I: Files and Users
C hapter 1. Introduction
Section 1.1. The Linux/Unix File Model
Section 1.2. The Linux/Unix Process Model
Section 1.3. Standard C vs. Original C
Section 1.4. Why GNU Programs Are Better
Section 1.5. Portability Revisited
Section 1.6. Suggested Reading
Section 1.7. Summary
Exercises
C hapter 2. Arguments, Options, and the Environment
Section 2.1. Option and Argument Conventions
Section 2.2. Basic Command-Line Processing
Section 2.3. Option Parsing: getopt() and getopt_long()
Section 2.4. The Environment
Section 2.5. Summary
Exercises
C hapter 3. User-Level Memory Management
Section 3.1. Linux/Unix Address Space
Section 3.2. Memory Allocation
Section 3.3. Summary
Exercises
C hapter 4. Files and File I/O
Section 4.1. Introducing the Linux/Unix I/O Model
Section 4.2. Presenting a Basic Program Structure
Section 4.3. Determining What Went Wrong
Section 4.4. Doing Input and Output
Section 4.5. Random Access: Moving Around within a File
Section 4.6. Creating Files
Section 4.7. Forcing Data to Disk
Section 4.8. Setting File Length
Section 4.9. Summary
Exercises
C hapter 5. Directories and File Metadata
Section 5.1. Considering Directory C ontents
Section 5.2. Creating and Removing Directories
Section 5.3. Reading Directories
Section 5.4. Obtaining Information about Files
Section 5.5. Changing Ownership, Permission, and Modification Times
Section 5.6. Summary
Exercises
C hapter 6. General Library Interfaces — Part 1
Section 6.1. Times and Dates

Section 6.2. Sorting and Searching Functions
Section 6.3. User and Group Names
Section 6.4. Terminals: isatty()
Section 6.5. Suggested Reading
Section 6.6. Summary
Exercises
C hapter 7. Putting It All Together: ls
Section 7.1. V7 ls Options
Section 7.2. V7 ls Code
Section 7.3. Summary
Exercises
C hapter 8. Filesystems and Directory Walks
Section 8.1. Mounting and Unmounting Filesystems
Section 8.2. Files for Filesystem Administration
Section 8.3. Retrieving Per-Filesystem Information
Section 8.4. Moving Around in the File Hierarchy
Section 8.5. Walking a File Tree: GNU du
Section 8.6. Changing the Root Directory: chroot()
Section 8.7. Summary
Exercises
Part II: Processes, IPC, and Internationalization
C hapter 9. Process Management and Pipes
Section 9.1. Process Creation and Management
Section 9.2. Process Groups
Section 9.3. Basic Interprocess Communication: Pipes and FIFOs
Section 9.4. File Descriptor Management
Section 9.5. Example: Two-Way Pipes in gawk
Section 9.6. Suggested Reading
Section 9.7. Summary
Exercises
C hapter 10. Signals
Section 10.1. Introduction
Section 10.2. Signal Actions
Section 10.3. Standard C Signals: signal() and raise()
Section 10.4. Signal Handlers in Action
Section 10.5. The System V Release 3 Signal APIs: sigset() et al.
Section 10.6. POSIX Signals
Section 10.7. Signals for Interprocess Communication
Section 10.8. Important Special-Purpose Signals
Section 10.9. Signals Across fork() and exec()
Section 10.10. Summary
Exercises
C hapter 11. Permissions and User and Group ID Numbers
Section 11.1. C hecking Permissions
Section 11.2. Retrieving User and Group IDs
Section 11.3. C hecking as the Real User: access()
Section 11.4. C hecking as the Effective User: euidaccess() (GLIBC )
Section 11.5. Setting Extra Permission Bits for Directories
Section 11.6. Setting Real and Effective IDs
Section 11.7. Working with All Three IDs: getresuid() and setresuid() (Linux)
Section 11.8. C rossing a Security Minefield: Setuid root
Section 11.9. Suggested Reading
Section 11.10. Summary
Exercises
C hapter 12. General Library Interfaces — Part 2
Section 12.1. Assertion Statements: assert()
Section 12.2. Low-Level Memory: The memXXX() Functions
Section 12.3. Temporary Files

Section 12.4. C ommitting Suicide: abort()
Section 12.5. Nonlocal Gotos
Section 12.6. Pseudorandom Numbers
Section 12.7. Metacharacter Expansions
Section 12.8. Regular Expressions
Section 12.9. Suggested Reading
Section 12.10. Summary
Exercises
C hapter 13. Internationalization and Localization
Section 13.1. Introduction
Section 13.2. Locales and the C Library
Section 13.3. Dynamic Translation of Program Messages
Section 13.4. C an You Spell That for Me, Please?
Section 13.5. Suggested Reading
Section 13.6. Summary
Exercises
C hapter 14. Extended Interfaces
Section 14.1. Allocating Aligned Memory: posix_memalign() and memalign()
Section 14.2. Locking Files
Section 14.3. More Precise Times
Section 14.4. Advanced Searching with Binary Trees
Section 14.5. Summary
Exercises
Part III: Debugging and Final Project
C hapter 15. Debugging
Section 15.1. First Things First
Section 15.2. C ompilation for Debugging
Section 15.3. GDB Basics
Section 15.4. Programming for Debugging
Section 15.5. Debugging Tools
Section 15.6. Software Testing
Section 15.7. Debugging Rules
Section 15.8. Suggested Reading
Section 15.9. Summary
Exercises
C hapter 16. A Project that Ties Everything Together
Section 16.1. Project Description
Section 16.2. Suggested Reading
Part IV: Appendixes
Appendix A. Teach Yourself Programming in Ten Years
Why Is Everyone in Such a Rush?
References
Answers
Footnotes
Appendix B. Caldera Ancient UNIX License
Appendix C. GNU General Public License
Preamble
Terms and Conditions for C opying, Distribution and Modification
How to Apply These Terms to Your New Programs
Example Use
Index

Preface
One of the best ways to learn about programming is to read well-written programs. This book teaches the
fundamental Linux system call APIs—those that form the core of any significant program—by presenting code
from production programs that you use every day.
By looking at concrete programs, you can not only see how to use the Linux APIs, but you also can examine the
real-world issues (performance, portability, robustness) that arise in writing software.
While the book's title is Linux Programming by Example, everything we cover, unless otherwise noted, applies
to modern Unix systems as well. In general we use "Linux" to mean the Linux kernel, and "GNU/Linux" to mean
the total system (kernel, libraries, tools). Also, we often say "Linux" when we mean all of Linux, GNU/Linux and
Unix; if something is specific to one system or the other, we mention it explicitly.

Audience
This book is intended for the person who understands programming and is familiar with the basics of C, at least
on the level of The C Programming Language by Kernighan and Ritchie. (Java programmers wishing to read
this book should understand C pointers, since C code makes heavy use of them.) The examples use both the
1990 version of Standard C and Original C.
In particular, you should be familiar with all C operators, control-flow structures, variable and pointer declarations
and use, the string management functions, the use of exit(), and the <stdio.h> suite of functions for file
input/output.
You should understand the basic concepts of standard input, standard output, and standard error and the fact
that all C programs receive an array of character strings representing invocation options and arguments. You
should also be familiar with the fundamental command-line tools, such as cd, cp, date, ln, ls, man (and info if
you have it), rmdir, and rm, the use of long and short command-line options, environment variables, and I/O
redirection, including pipes.
We assume that you want to write programs that work not just under GNU/Linux but across the range of Unix
systems. To that end, we mark each interface as to its availability (GLIBC systems only, or defined by POSIX,
and so on), and portability advice is included as an integral part of the text.
The programming taught here may be at a lower level than you're used to; that's OK. The system calls are the
fundamental building blocks for higher operations and are thus low-level by nature. This in turn dictates our use of
C: The APIs were designed for use from C, and code that interfaces them to higher-level languages, such as C++
and Java, will necessarily be lower level in nature, and most likely, written in C. It may help to remember that "low
level" doesn't mean "bad," it just means "more challenging."
剩余591页未读,继续阅读














安全验证
文档复制为VIP权益,开通VIP直接复制

评论7