目录
PrefacePART I Files and UsersChapter 1 Introduction1.1 The Linux/Unix File Model1.1.1 Files and Permissions1.1.2 Directories and Filenames1.1.3 Executable Files1.1.4 Devices1.2 The Linux/Unix Process Model1.2.1 Pipes: Hooking Processes Together :1.3 Standard C vs. Original C1.4 Why GNU Programs Are Better1.4.1 Program Design1.4.2 Program Behavior1.4.3 C Code Programming1.4.4 Things That Make a GNU Program Better1.4.5 Parting Thoughts about the "GNU Coding Standards".1.5 Portability Revisited1.6 Suggested Reading1.7 SummaryExercisesChapter 2 Arguments, Options, and the Environment2.1 Option and Argument Conventions2.1.1 POSIX Conventions2.1.2 GNU Long options2.2 Basic Command-Line Processing2.2.1 The V7 echo Program2.3 Option Parsing: getopt ( ) and getopt_long ( )2.3.1 Single-Letter Options2.3.2 GNU getopt ( ) and Option Ordering2.3.3 Long Options2.3.3.1 Long Options Table2.3.3.2 Long Options, POSIX Style2.3.3.3 getopt_long ( ) Return Value Summary2.3.3.4 GNU getopt ( ) or getopt long ( ) in User Programs2.4 The Environment2.4.1 Environment Management Functions2.4.2 The Entire Environment: environ2.4.3 GNU env2.5 SummaryExercisesChapter 3 User-Level Memory Management3.1 Linux/Unix Address Space3.2 Memory Allocation3.2.1 Library Calls: malloc (), calloc (), realloc (), free ( )3.2.1.1 Examining C Language Details3.2.1.2 Initially Allocating Memory: malloc ( )3.2.1.3 Releasing Memory: free ( )3.2.1.4 Changing Size: realloc ( )3.2.1.5 Allocating and Zero-filling: calloc ( )3.2.1.6 Summarizing from the GNU Coding Standards3.2.1.7 Using Private Allocators3.2.1.8 Example: Reading Arbitrarily Long Lines3.2.1.9 GLIBC Only: Reading Entire Lines: getline ( ) and getdelim ( ) .3.2.2 String Copying: strdup ( )3.2.3 System Calls: brk ( ) and sbrk ( )3.2.4 Lazy Programmer Calls: alloca ( )3.2.5 Address Space Examination3.3 SummaryExercisesChapter 4 Files and File I/O4.1 Introducing the Linux/Unix I/O Model4.2 Presenting a Basic Program Structure4.3 Determining What Went Wrong4.3.1 Values for errno4.3.2 Error Message Style4.4 Doing Input and Output4.4.1 Understanding File DeScriptors4.4.2 Opening and Closing Files4.4.2.1 Mapping FILE * Variables to File DeScriptors4.4.2.2 Closing All Open Files4.4.3 Reading and Writing4.4.4 Example: Unix cat4.5 Random Access: Moving Around within a File4.6 Creating Files4.6.1 Specifying Initial File Permissions4.6.2 Creating Files with ereat ( )4.6.3 Revisiting open ( )4.7 Forcing Data to Disk4.8 Setting File Length4.9 SummaryExercisesChapter 5 Directories and File Metaclata5.1 Considering Directory Contents5.1.1 Definitions5.1.2 Directory Contents5.1.3 Hard Links5.1.3.1 The GNU link Program5.1.3.2 Dot and Dot-Dot5.1.4 File Renaming5.1.5 File Removal5.1.5.1 Removing Open Files5.1.5.2 Using ISO C: remove ( )5.1.6 Symbolic Links5.2 Creating and Removing Directories5.3 Reading Directories5.3.1 Basic Directory Reading5.3.1.1 Portability Considerations5.3.1.2 Linux and BSD Directory Entries5.3.2 BSD Directory Positioning Functions5.4 Obtaining Information about Files5.4.1 Linux File Types5.4.2 Retrieving File Information5.4.3 Linux Only: Specifying Higher-Precision File Times5.4.4 Determining File Type5.4.4.1 Device Information5.4.4.2 The V7 cat Revisited5.4.5 Working with Symbolic Links5.5 Changing Ownership, Permission, and Modification Times5.5.1 Changing File Ownership: chown (), fchown (), and ichown ( )5.5.2 Changing Permissions: chmod ( ) and fchmod ( )5.5.3 Changing Timestamps: utime ( )5.5.3.1 Faking utime (file, NULL)5.5.4 Using fchown ( ) and fchmod ( ) for Security5.6 SummaryExercisesChapter 6 General Library Interfaces - Part 16.1 Times and Dates6.1.1 Retrieving the Current Time: time ( ) and difftime ( )6.1.2 Breaking Down Times: gmtime ( ) and localtime ( )6.1.3 Formatting Dates and Times6.1.3.1 Simple Time Formatting: asctime ( ) and ctime ( )6.1.3.2 Complex Time Formatting: strftime ( )6.1.4 Converting a Broken-Down Time to a t ime_t6.1.5 Getting Time-Zone Information6.1.5.1 BSD Systems Gotcha: timezone (), Not timezone6.2 Sorting and Searching Functions6.2.1 Sorting: qsort ( )6.2.1.1 Example: Sorting Employees6.2.1.2 Example: Sorting Directory Contents6.2.2 Binary Searching: bsearch ( )6.3 User and Group Names6.3.1 User Database6.3.2 Group Database6.4 Terminals: isatty ( )6.5 Suggested Reading6.6 SummaryExercisesChapter 7 Putting It All Together: ls7.1 V7 ls Options7.2 V7 ls Code7.3 SummaryExercisesChapter 8 Filesystems and Directory Walks8.1 Mounting and Unmounting Filesystems8.1.1 Reviewing the Background8.1.2 Looking at Different Filesystem Types8.1.3 Mounting Filesystems: mount8.1.4 Unmounting Fil, esystems: uraount:8.2 Files for Filesystem Administration8.2.1 Using Mount Options8.2.2 Working with Mounted Filesystems: getmntent ( )8.3 Retrieving Per-Filesystem Information8.3.1 POSIX Style: statvfs ( ) and fstatvfs ( )8.3.2 Linux Style: statvfs ( ) and fstatvfs ( )8.4 Moving Around in the File Hierarchy8.4.1 Changing Directory: cbdir ( ) and fchdir ( )8.4.2 Getting the Current Directory: getcwd ( )8.4.3 Walking a Hierarchy: nftw ( )8.4.3.1 The rift:w() Interface8.4.3.2 The rill:w() Callback Function8.5 Walking a File Tree: GNU clu8.6 Changing the Root Directory: ~larool: ( )8.7 SummaryExercisesPART II Processes, IPC, and InternationalizationChapter 9 Process Management and Pipes9.1 Process Creation and Management9.1.1 Creating a Process: fork( )9.1.1.1 After the fork ( ) : Shared and Distinct Attributes9.1.1.2 File DeScriptor Sharing9.1.1.3 File DeScriptor Sharing and close ( )9.1.2 Identifying a Process: getpid ( ) and getppid ( )9.1.3 Setting Process Priority: nice ( )9.1.3.1 POSIX vs. Reality9.1.4 Starting New Programs: The exec ( ) Family9.1.4.1 The execve ( ) System Call9.1.4.2 Wrapper Functions: execl( ) et al9.1.4.3 Program Names and argv [ 0 ]9.1.4.4 Attributes Inherited across exec ( )9.1.5 Terminating a Process9.1.5.1 Defining Process Exit Status9.1.5.2 Returning from main ( )9.1.5.3 Exiting Functions9.1.6 Recovering a Child''''s Exit Status9.1.6.1 Using POSIX Functions: wait; ( ) and waitpid ( )9.1.6.2 Using BSD Functions: wait3 ( ) and wait4 ()9.2 Process Groups9.2.1 Job Control Overview9.2.2 Process Group Identification: getpgrp ( ) and getpgid ( )9.2.3 Process Group Setting: setpgid ( ) and setpgrp ( )9.3 Basic Interprocess Communication: Pipes and FIFOs9.3.1 Pipes 9.3.1.1 Creating Pipes9.3.1.2 Pipe Buffering9.3.2 FIFOs9.4 File DeScriptor Management9.4.1 Duplicating Open Files: dup ( ) and dup2 ( )9.4.2 Creating Nonlinear Pipelines: /dev/fd/XX9.4.3 Managing File Attributes: fcntl ( )9.4.3.1 The Close-on-exec Flag9.4.3.2 File DeScriptor Duplication9.4.3.3 Manipulation of File Status Flags and Access Modes9.4.3.4 Nonblocking I/O for Pipes and FIFOs9.4.3.5 fcntl ( ) Summary9.5 Example: Two-Way Pipes in gawk9.6 Suggested Reading9.7 SummaryExercisesChapter 10 Signals10.1 Introduction10.2 Signal Actions10.3 Standard C Signals: signaZ ( ) and raise ( )10.3.1 The s~gnal () Function10.3.2 Sending Signals Programmatically: raise ( )10.4 Signal Handlers in Action10.4.1 Traditional Systems10.4.2 BSD and GNU/Linux10.4.3 Ignoring Signals10.4.4 Restartable System Calls10.4.4.1 Example: GNU Coreutils safe_read( ) and safe_write()10.4.4.2 GLIBC Only: TEMP_FAILURE_RETRY ( )10.4.5 Race Conditions and sig_atomic_t (ISO C)10.4.6 Additional Caveats10.4.7 Out Story So Far, Episode I10.5 The System V Release 3 Signal APIs: sigset ( ) et al10.6 POSIX Signals10.6.1 Uncovering the Problem10.6.2 Signal Sets: sigset_t and
| |