\chapentry {Introduction}{1}{1} \secentry {Getting Started}{1}{1}{1} \secentry {Standards and Portability}{1}{2}{1} \subsecentry {ISO C}{1}{2}{1}{2} \subsecentry {POSIX (The Portable Operating System Interface)}{1}{2}{2}{2} \subsecentry {Berkeley Unix}{1}{2}{3}{3} \subsecentry {SVID (The System V Interface Description)}{1}{2}{4}{3} \secentry {Using the Library}{1}{3}{4} \subsecentry {Header Files}{1}{3}{1}{4} \subsecentry {Macro Definitions of Functions}{1}{3}{2}{5} \subsecentry {Reserved Names}{1}{3}{3}{6} \subsecentry {Feature Test Macros}{1}{3}{4}{8} \secentry {Roadmap to the Manual}{1}{4}{10} \chapentry {Error Reporting}{2}{15} \secentry {Checking for Errors}{2}{1}{15} \secentry {Error Codes}{2}{2}{16} \secentry {Error Messages}{2}{3}{27} \chapentry {Memory Allocation}{3}{31} \secentry {Dynamic Memory Allocation Concepts}{3}{1}{31} \secentry {Dynamic Allocation and C}{3}{2}{31} \secentry {Unconstrained Allocation}{3}{3}{32} \subsecentry {Basic Storage Allocation}{3}{3}{1}{32} \subsecentry {Examples of \code {malloc}}{3}{3}{2}{33} \subsecentry {Freeing Memory Allocated with \code {malloc}}{3}{3}{3}{34} \subsecentry {Changing the Size of a Block}{3}{3}{4}{35} \subsecentry {Allocating Cleared Space}{3}{3}{5}{36} \subsecentry {Efficiency Considerations for \code {malloc}}{3}{3}{6}{37} \subsecentry {Allocating Aligned Memory Blocks}{3}{3}{7}{37} \subsecentry {Malloc Tunable Parameters}{3}{3}{8}{38} \subsecentry {Heap Consistency Checking}{3}{3}{9}{38} \subsecentry {Storage Allocation Hooks}{3}{3}{10}{40} \subsecentry {Statistics for Storage Allocation with \code {malloc}}{3}{3}{11}{41} \subsecentry {Summary of \code {malloc}-Related Functions}{3}{3}{12}{42} \secentry {Obstacks}{3}{4}{43} \subsecentry {Creating Obstacks}{3}{4}{1}{43} \subsecentry {Preparing for Using Obstacks}{3}{4}{2}{44} \subsecentry {Allocation in an Obstack}{3}{4}{3}{45} \subsecentry {Freeing Objects in an Obstack}{3}{4}{4}{46} \subsecentry {Obstack Functions and Macros}{3}{4}{5}{47} \subsecentry {Growing Objects}{3}{4}{6}{48} \subsecentry {Extra Fast Growing Objects}{3}{4}{7}{49} \subsecentry {Status of an Obstack}{3}{4}{8}{51} \subsecentry {Alignment of Data in Obstacks}{3}{4}{9}{52} \subsecentry {Obstack Chunks}{3}{4}{10}{52} \subsecentry {Summary of Obstack Functions}{3}{4}{11}{53} \secentry {Automatic Storage with Variable Size}{3}{5}{55} \subsecentry {\code {alloca} Example}{3}{5}{1}{55} \subsecentry {Advantages of \code {alloca}}{3}{5}{2}{56} \subsecentry {Disadvantages of \code {alloca}}{3}{5}{3}{57} \subsecentry {GNU C Variable-Size Arrays}{3}{5}{4}{57} \secentry {Relocating Allocator}{3}{6}{58} \subsecentry {Concepts of Relocating Allocation}{3}{6}{1}{58} \subsecentry {Allocating and Freeing Relocatable Blocks}{3}{6}{2}{58} \chapentry {Character Handling}{4}{61} \secentry {Classification of Characters}{4}{1}{61} \secentry {Case Conversion}{4}{2}{63} \chapentry {String and Array Utilities}{5}{65} \secentry {Representation of Strings}{5}{1}{65} \secentry {String and Array Conventions}{5}{2}{66} \secentry {String Length}{5}{3}{67} \secentry {Copying and Concatenation}{5}{4}{67} \secentry {String/Array Comparison}{5}{5}{72} \secentry {Collation Functions}{5}{6}{75} \secentry {Search Functions}{5}{7}{78} \secentry {Finding Tokens in a String}{5}{8}{80} \chapentry {Input/Output Overview}{6}{85} \secentry {Input/Output Concepts}{6}{1}{85} \subsecentry {Streams and File Descriptors}{6}{1}{1}{85} \subsecentry {File Position}{6}{1}{2}{87} \secentry {File Names}{6}{2}{87} \subsecentry {Directories}{6}{2}{1}{88} \subsecentry {File Name Resolution}{6}{2}{2}{88} \subsecentry {File Name Errors}{6}{2}{3}{89} \subsecentry {Portability of File Names}{6}{2}{4}{90} \chapentry {Input/Output on Streams}{7}{93} \secentry {Streams}{7}{1}{93} \secentry {Standard Streams}{7}{2}{93} \secentry {Opening Streams}{7}{3}{94} \secentry {Closing Streams}{7}{4}{96} \secentry {Simple Output by Characters or Lines}{7}{5}{97} \secentry {Character Input}{7}{6}{98} \secentry {Line-Oriented Input}{7}{7}{100} \secentry {Unreading}{7}{8}{102} \subsecentry {What Unreading Means}{7}{8}{1}{102} \subsecentry {Using \code {ungetc} To Do Unreading}{7}{8}{2}{103} \secentry {Block Input/Output}{7}{9}{104} \secentry {Formatted Output}{7}{10}{105} \subsecentry {Formatted Output Basics}{7}{10}{1}{105} \subsecentry {Output Conversion Syntax}{7}{10}{2}{106} \subsecentry {Table of Output Conversions}{7}{10}{3}{107} \subsecentry {Integer Conversions}{7}{10}{4}{108} \subsecentry {Floating-Point Conversions}{7}{10}{5}{110} \subsecentry {Other Output Conversions}{7}{10}{6}{112} \subsecentry {Formatted Output Functions}{7}{10}{7}{113} \subsecentry {Dynamically Allocating Formatted Output}{7}{10}{8}{115} \subsecentry {Variable Arguments Output Functions}{7}{10}{9}{115} \subsecentry {Parsing a Template String}{7}{10}{10}{118} \subsecentry {Example of Parsing a Template String}{7}{10}{11}{119} \secentry {Customizing \code {printf}}{7}{11}{121} \subsecentry {Registering New Conversions}{7}{11}{1}{121} \subsecentry {Conversion Specifier Options}{7}{11}{2}{122} \subsecentry {Defining the Output Handler}{7}{11}{3}{124} \subsecentry {\code {printf} Extension Example}{7}{11}{4}{125} \secentry {Formatted Input}{7}{12}{126} \subsecentry {Formatted Input Basics}{7}{12}{1}{127} \subsecentry {Input Conversion Syntax}{7}{12}{2}{128} \subsecentry {Table of Input Conversions}{7}{12}{3}{129} \subsecentry {Numeric Input Conversions}{7}{12}{4}{130} \subsecentry {String Input Conversions}{7}{12}{5}{131} \subsecentry {Dynamically Allocating String Conversions}{7}{12}{6}{133} \subsecentry {Other Input Conversions}{7}{12}{7}{133} \subsecentry {Formatted Input Functions}{7}{12}{8}{134} \subsecentry {Variable Arguments Input Functions}{7}{12}{9}{135} \secentry {End-Of-File and Errors}{7}{13}{135} \secentry {Text and Binary Streams}{7}{14}{136} \secentry {File Positioning}{7}{15}{137} \secentry {Portable File-Position Functions}{7}{16}{139} \secentry {Stream Buffering}{7}{17}{140} \subsecentry {Buffering Concepts}{7}{17}{1}{140} \subsecentry {Flushing Buffers}{7}{17}{2}{141} \subsecentry {Controlling Which Kind of Buffering}{7}{17}{3}{142} \secentry {Other Kinds of Streams}{7}{18}{144} \subsecentry {String Streams}{7}{18}{1}{144} \subsecentry {Obstack Streams}{7}{18}{2}{146} \subsecentry {Programming Your Own Custom Streams}{7}{18}{3}{147} \subsubsecentry {Custom Streams and Cookies} {7}{18}{3}{1} {147} \subsubsecentry {Custom Stream Hook Functions} {7}{18}{3}{2} {149} \chapentry {Low-Level Input/Output}{8}{151} \secentry {Opening and Closing Files}{8}{1}{151} \secentry {Input and Output Primitives}{8}{2}{153} \secentry {Setting the File Position of a Descriptor}{8}{3}{156} \secentry {Descriptors and Streams}{8}{4}{159} \secentry {Dangers of Mixing Streams and Descriptors}{8}{5}{160} \subsecentry {Linked Channels}{8}{5}{1}{160} \subsecentry {Independent Channels}{8}{5}{2}{160} \subsecentry {Cleaning Streams}{8}{5}{3}{161} \secentry {Waiting for Input or Output}{8}{6}{162} \secentry {Control Operations on Files}{8}{7}{165} \secentry {Duplicating Descriptors}{8}{8}{166} \secentry {File Descriptor Flags}{8}{9}{168} \secentry {File Status Flags}{8}{10}{170} \subsecentry {File Access Modes}{8}{10}{1}{170} \subsecentry {Open-time Flags}{8}{10}{2}{171} \subsecentry {I/O Operating Modes}{8}{10}{3}{173} \subsecentry {Getting and Setting File Status Flags}{8}{10}{4}{174} \secentry {File Locks}{8}{11}{175} \secentry {Interrupt-Driven Input}{8}{12}{179} \chapentry {File System Interface}{9}{181} \secentry {Working Directory}{9}{1}{181} \secentry {Accessing Directories}{9}{2}{183} \subsecentry {Format of a Directory Entry}{9}{2}{1}{183} \subsecentry {Opening a Directory Stream}{9}{2}{2}{184} \subsecentry {Reading and Closing a Directory Stream}{9}{2}{3}{185} \subsecentry {Simple Program to List a Directory}{9}{2}{4}{186} \subsecentry {Random Access in a Directory Stream}{9}{2}{5}{187} \subsecentry {Scanning the Content of a Directory}{9}{2}{6}{187} \subsecentry {Simple Program to List a Directory, Mark II}{9}{2}{7}{188} \secentry {Hard Links}{9}{3}{189} \secentry {Symbolic Links}{9}{4}{190} \secentry {Deleting Files}{9}{5}{192} \secentry {Renaming Files}{9}{6}{193} \secentry {Creating Directories}{9}{7}{194} \secentry {File Attributes}{9}{8}{195} \subsecentry {What the File Attribute Values Mean}{9}{8}{1}{195} \subsecentry {Reading the Attributes of a File}{9}{8}{2}{198} \subsecentry {Testing the Type of a File}{9}{8}{3}{199} \subsecentry {File Owner}{9}{8}{4}{200} \subsecentry {The Mode Bits for Access Permission}{9}{8}{5}{202} \subsecentry {How Your Access to a File is Decided}{9}{8}{6}{204} \subsecentry {Assigning File Permissions}{9}{8}{7}{204} \subsecentry {Testing Permission to Access a File}{9}{8}{8}{206} \subsecentry {File Times}{9}{8}{9}{208} \secentry {Making Special Files}{9}{9}{210} \secentry {Temporary Files}{9}{10}{210} \chapentry {Pipes and FIFOs}{10}{215} \secentry {Creating a Pipe}{10}{1}{215} \secentry {Pipe to a Subprocess}{10}{2}{217} \secentry {FIFO Special Files}{10}{3}{219} \secentry {Atomicity of Pipe I/O}{10}{4}{220} \chapentry {Sockets}{11}{221} \secentry {Socket Concepts}{11}{1}{221} \secentry {Communication Styles}{11}{2}{222} \secentry {Socket Addresses}{11}{3}{223} \subsecentry {Address Formats}{11}{3}{1}{224} \subsecentry {Setting the Address of a Socket}{11}{3}{2}{225} \subsecentry {Reading the Address of a Socket}{11}{3}{3}{226} \secentry {The File Namespace}{11}{4}{227} \subsecentry {File Namespace Concepts}{11}{4}{1}{227} \subsecentry {Details of File Namespace}{11}{4}{2}{227} \subsecentry {Example of File-Namespace Sockets}{11}{4}{3}{228} \secentry {The Internet Namespace}{11}{5}{229} \subsecentry {Internet Socket Address Formats}{11}{5}{1}{230} \subsecentry {Host Addresses}{11}{5}{2}{231} \subsubsecentry {Internet Host Addresses} {11}{5}{2}{1} {231} \subsubsecentry {Host Address Data Type} {11}{5}{2}{2} {232} \subsubsecentry {Host Address Functions} {11}{5}{2}{3} {233} \subsubsecentry {Host Names} {11}{5}{2}{4} {235} \subsecentry {Internet Ports}{11}{5}{3}{237} \subsecentry {The Services Database}{11}{5}{4}{238} \subsecentry {Byte Order Conversion}{11}{5}{5}{239} \subsecentry {Protocols Database}{11}{5}{6}{240} \subsecentry {Internet Socket Example}{11}{5}{7}{242} \secentry {Other Namespaces}{11}{6}{243} \secentry {Opening and Closing Sockets}{11}{7}{244} \subsecentry {Creating a Socket}{11}{7}{1}{244} \subsecentry {Closing a Socket}{11}{7}{2}{244} \subsecentry {Socket Pairs}{11}{7}{3}{245} \secentry {Using Sockets with Connections}{11}{8}{246} \subsecentry {Making a Connection}{11}{8}{1}{246} \subsecentry {Listening for Connections}{11}{8}{2}{248} \subsecentry {Accepting Connections}{11}{8}{3}{248} \subsecentry {Who is Connected to Me?}{11}{8}{4}{250} \subsecentry {Transferring Data}{11}{8}{5}{250} \subsubsecentry {Sending Data} {11}{8}{5}{1} {250} \subsubsecentry {Receiving Data} {11}{8}{5}{2} {251} \subsubsecentry {Socket Data Options} {11}{8}{5}{3} {252} \subsecentry {Byte Stream Socket Example}{11}{8}{6}{252} \subsecentry {Byte Stream Connection Server Example}{11}{8}{7}{254} \subsecentry {Out-of-Band Data}{11}{8}{8}{257} \secentry {Datagram Socket Operations}{11}{9}{260} \subsecentry {Sending Datagrams}{11}{9}{1}{260} \subsecentry {Receiving Datagrams}{11}{9}{2}{261} \subsecentry {Datagram Socket Example}{11}{9}{3}{262} \subsecentry {Example of Reading Datagrams}{11}{9}{4}{263} \secentry {The \code {inetd} Daemon}{11}{10}{264} \subsecentry {\code {inetd} Servers}{11}{10}{1}{265} \subsecentry {Configuring \code {inetd}}{11}{10}{2}{265} \secentry {Socket Options}{11}{11}{266} \subsecentry {Socket Option Functions}{11}{11}{1}{266} \subsecentry {Socket-Level Options}{11}{11}{2}{267} \secentry {Networks Database}{11}{12}{269} \chapentry {Low-Level Terminal Interface}{12}{271} \secentry {Identifying Terminals}{12}{1}{271} \secentry {I/O Queues}{12}{2}{271} \secentry {Two Styles of Input: Canonical or Not}{12}{3}{272} \secentry {Terminal Modes}{12}{4}{273} \subsecentry {Terminal Mode Data Types}{12}{4}{1}{273} \subsecentry {Terminal Mode Functions}{12}{4}{2}{274} \subsecentry {Setting Terminal Modes Properly}{12}{4}{3}{276} \subsecentry {Input Modes}{12}{4}{4}{277} \subsecentry {Output Modes}{12}{4}{5}{279} \subsecentry {Control Modes}{12}{4}{6}{279} \subsecentry {Local Modes}{12}{4}{7}{281} \subsecentry {Line Speed}{12}{4}{8}{284} \subsecentry {Special Characters}{12}{4}{9}{286} \subsubsecentry {Characters for Input Editing} {12}{4}{9}{1} {286} \subsubsecentry {Characters that Cause Signals} {12}{4}{9}{2} {288} \subsubsecentry {Special Characters for Flow Control} {12}{4}{9}{3} {289} \subsubsecentry {Other Special Characters} {12}{4}{9}{4} {290} \subsecentry {Noncanonical Input}{12}{4}{10}{291} \secentry {Line Control Functions}{12}{5}{293} \secentry {Noncanonical Mode Example}{12}{6}{295} \chapentry {Mathematics}{13}{297} \secentry {Domain and Range Errors}{13}{1}{297} \secentry {Trigonometric Functions}{13}{2}{298} \secentry {Inverse Trigonometric Functions}{13}{3}{299} \secentry {Exponentiation and Logarithms}{13}{4}{300} \secentry {Hyperbolic Functions}{13}{5}{301} \secentry {Pseudo-Random Numbers}{13}{6}{302} \subsecentry {ISO C Random Number Functions}{13}{6}{1}{302} \subsecentry {BSD Random Number Functions}{13}{6}{2}{303} \chapentry {Low-Level Arithmetic Functions}{14}{305} \secentry {``Not a Number'' Values}{14}{1}{305} \secentry {Predicates on Floats}{14}{2}{305} \secentry {Absolute Value}{14}{3}{306} \secentry {Normalization Functions}{14}{4}{307} \secentry {Rounding and Remainder Functions}{14}{5}{308} \secentry {Integer Division}{14}{6}{309} \secentry {Parsing of Numbers}{14}{7}{310} \subsecentry {Parsing of Integers}{14}{7}{1}{310} \subsecentry {Parsing of Floats}{14}{7}{2}{314} \chapentry {Searching and Sorting}{15}{317} \secentry {Defining the Comparison Function}{15}{1}{317} \secentry {Array Search Function}{15}{2}{317} \secentry {Array Sort Function}{15}{3}{318} \secentry {Searching and Sorting Example}{15}{4}{319} \chapentry {Pattern Matching}{16}{323} \secentry {Wildcard Matching}{16}{1}{323} \secentry {Globbing}{16}{2}{324} \subsecentry {Calling \code {glob}}{16}{2}{1}{324} \subsecentry {Flags for Globbing}{16}{2}{2}{326} \secentry {Regular Expression Matching}{16}{3}{327} \subsecentry {POSIX Regular Expression Compilation}{16}{3}{1}{327} \subsecentry {Flags for POSIX Regular Expressions}{16}{3}{2}{329} \subsecentry {Matching a Compiled POSIX Regular Expression}{16}{3}{3}{330} \subsecentry {Match Results with Subexpressions}{16}{3}{4}{331} \subsecentry {Complications in Subexpression Matching}{16}{3}{5}{332} \subsecentry {POSIX Regexp Matching Cleanup}{16}{3}{6}{332} \secentry {Shell-Style Word Expansion}{16}{4}{333} \subsecentry {The Stages of Word Expansion}{16}{4}{1}{334} \subsecentry {Calling \code {wordexp}}{16}{4}{2}{334} \subsecentry {Flags for Word Expansion}{16}{4}{3}{336} \subsecentry {\code {wordexp} Example}{16}{4}{4}{337} \chapentry {Date and Time}{17}{339} \secentry {Processor Time}{17}{1}{339} \subsecentry {Basic CPU Time Inquiry}{17}{1}{1}{339} \subsecentry {Detailed Elapsed CPU Time Inquiry}{17}{1}{2}{340} \secentry {Calendar Time}{17}{2}{341} \subsecentry {Simple Calendar Time}{17}{2}{1}{342} \subsecentry {High-Resolution Calendar}{17}{2}{2}{342} \subsecentry {Broken-down Time}{17}{2}{3}{345} \subsecentry {Formatting Date and Time}{17}{2}{4}{347} \subsecentry {Specifying the Time Zone with \code {TZ}}{17}{2}{5}{352} \subsecentry {Functions and Variables for Time Zones}{17}{2}{6}{354} \subsecentry {Time Functions Example}{17}{2}{7}{355} \secentry {Setting an Alarm}{17}{3}{356} \secentry {Sleeping}{17}{4}{359} \secentry {Resource Usage}{17}{5}{360} \secentry {Limiting Resource Usage}{17}{6}{362} \secentry {Process Priority}{17}{7}{364} \chapentry {Extended Characters}{18}{367} \secentry {Introduction to Extended Characters}{18}{1}{367} \secentry {Locales and Extended Characters}{18}{2}{368} \secentry {Multibyte Characters}{18}{3}{368} \secentry {Wide Character Introduction}{18}{4}{371} \secentry {Conversion of Extended Strings}{18}{5}{372} \secentry {Multibyte Character Length}{18}{6}{373} \secentry {Conversion of Extended Characters One by One}{18}{7}{374} \secentry {Character-by-Character Conversion Example}{18}{8}{375} \secentry {Multibyte Codes Using Shift Sequences}{18}{9}{377} \chapentry {Locales and Internationalization}{19}{379} \secentry {What Effects a Locale Has}{19}{1}{379} \secentry {Choosing a Locale}{19}{2}{380} \secentry {Categories of Activities that Locales Affect}{19}{3}{380} \secentry {How Programs Set the Locale}{19}{4}{381} \secentry {Standard Locales}{19}{5}{383} \secentry {Numeric Formatting}{19}{6}{383} \subsecentry {Generic Numeric Formatting Parameters}{19}{6}{1}{384} \subsecentry {Printing the Currency Symbol}{19}{6}{2}{385} \subsecentry {Printing the Sign of an Amount of Money}{19}{6}{3}{387} \chapentry {Non-Local Exits}{20}{389} \secentry {Introduction to Non-Local Exits}{20}{1}{389} \secentry {Details of Non-Local Exits}{20}{2}{391} \secentry {Non-Local Exits and Signals}{20}{3}{392} \chapentry {Signal Handling}{21}{393} \secentry {Basic Concepts of Signals}{21}{1}{393} \subsecentry {Some Kinds of Signals}{21}{1}{1}{393} \subsecentry {Concepts of Signal Generation}{21}{1}{2}{394} \subsecentry {How Signals Are Delivered}{21}{1}{3}{394} \secentry {Standard Signals}{21}{2}{395} \subsecentry {Program Error Signals}{21}{2}{1}{396} \subsecentry {Termination Signals}{21}{2}{2}{399} \subsecentry {Alarm Signals}{21}{2}{3}{401} \subsecentry {Asynchronous I/O Signals}{21}{2}{4}{401} \subsecentry {Job Control Signals}{21}{2}{5}{402} \subsecentry {Operation Error Signals}{21}{2}{6}{404} \subsecentry {Miscellaneous Signals}{21}{2}{7}{404} \subsecentry {Signal Messages}{21}{2}{8}{405} \secentry {Specifying Signal Actions}{21}{3}{406} \subsecentry {Basic Signal Handling}{21}{3}{1}{406} \subsecentry {Advanced Signal Handling}{21}{3}{2}{408} \subsecentry {Interaction of \code {signal} and \code {sigaction}}{21}{3}{3}{410} \subsecentry {\code {sigaction} Function Example}{21}{3}{4}{410} \subsecentry {Flags for \code {sigaction}}{21}{3}{5}{412} \subsecentry {Initial Signal Actions}{21}{3}{6}{412} \secentry {Defining Signal Handlers}{21}{4}{413} \subsecentry {Signal Handlers that Return}{21}{4}{1}{414} \subsecentry {Handlers That Terminate the Process}{21}{4}{2}{415} \subsecentry {Nonlocal Control Transfer in Handlers}{21}{4}{3}{416} \subsecentry {Signals Arriving While a Handler Runs}{21}{4}{4}{417} \subsecentry {Signals Close Together Merge into One}{21}{4}{5}{418} \subsecentry {Signal Handling and Nonreentrant Functions}{21}{4}{6}{421} \subsecentry {Atomic Data Access and Signal Handling}{21}{4}{7}{423} \subsubsecentry {Problems with Non-Atomic Access} {21}{4}{7}{1} {423} \subsubsecentry {Atomic Types} {21}{4}{7}{2} {424} \subsubsecentry {Atomic Usage Patterns} {21}{4}{7}{3} {425} \secentry {Primitives Interrupted by Signals}{21}{5}{425} \secentry {Generating Signals}{21}{6}{426} \subsecentry {Signaling Yourself}{21}{6}{1}{426} \subsecentry {Signaling Another Process}{21}{6}{2}{428} \subsecentry {Permission for using \code {kill}}{21}{6}{3}{429} \subsecentry {Using \code {kill} for Communication}{21}{6}{4}{430} \secentry {Blocking Signals}{21}{7}{431} \subsecentry {Why Blocking Signals is Useful}{21}{7}{1}{432} \subsecentry {Signal Sets}{21}{7}{2}{432} \subsecentry {Process Signal Mask}{21}{7}{3}{433} \subsecentry {Blocking to Test for Delivery of a Signal}{21}{7}{4}{435} \subsecentry {Blocking Signals for a Handler}{21}{7}{5}{435} \subsecentry {Checking for Pending Signals}{21}{7}{6}{437} \subsecentry {Remembering a Signal to Act On Later}{21}{7}{7}{438} \secentry {Waiting for a Signal}{21}{8}{439} \subsecentry {Using \code {pause}}{21}{8}{1}{439} \subsecentry {Problems with \code {pause}}{21}{8}{2}{440} \subsecentry {Using \code {sigsuspend}}{21}{8}{3}{441} \secentry {Using a Separate Signal Stack}{21}{9}{442} \secentry {BSD Signal Handling}{21}{10}{444} \subsecentry {BSD Function to Establish a Handler}{21}{10}{1}{445} \subsecentry {BSD Functions for Blocking Signals}{21}{10}{2}{446} \chapentry {Process Startup and Termination}{22}{447} \secentry {Program Arguments}{22}{1}{447} \subsecentry {Program Argument Syntax Conventions}{22}{1}{1}{448} \subsecentry {Parsing Program Options}{22}{1}{2}{449} \subsecentry {Example of Parsing Arguments with \code {getopt}}{22}{1}{3}{450} \subsecentry {Parsing Long Options}{22}{1}{4}{452} \subsecentry {Example of Parsing Long Options}{22}{1}{5}{454} \subsecentry {Parsing of Suboptions}{22}{1}{6}{456} \subsecentry {Parsing of Suboptions Example}{22}{1}{7}{457} \secentry {Environment Variables}{22}{2}{458} \subsecentry {Environment Access}{22}{2}{1}{459} \subsecentry {Standard Environment Variables}{22}{2}{2}{460} \secentry {Program Termination}{22}{3}{462} \subsecentry {Normal Termination}{22}{3}{1}{462} \subsecentry {Exit Status}{22}{3}{2}{463} \subsecentry {Cleanups on Exit}{22}{3}{3}{464} \subsecentry {Aborting a Program}{22}{3}{4}{465} \subsecentry {Termination Internals}{22}{3}{5}{465} \chapentry {Processes}{23}{467} \secentry {Running a Command}{23}{1}{467} \secentry {Process Creation Concepts}{23}{2}{468} \secentry {Process Identification}{23}{3}{468} \secentry {Creating a Process}{23}{4}{469} \secentry {Executing a File}{23}{5}{470} \secentry {Process Completion}{23}{6}{473} \secentry {Process Completion Status}{23}{7}{476} \secentry {BSD Process Wait Functions}{23}{8}{476} \secentry {Process Creation Example}{23}{9}{477} \chapentry {Job Control}{24}{479} \secentry {Concepts of Job Control}{24}{1}{479} \secentry {Job Control is Optional}{24}{2}{480} \secentry {Controlling Terminal of a Process}{24}{3}{480} \secentry {Access to the Controlling Terminal}{24}{4}{481} \secentry {Orphaned Process Groups}{24}{5}{481} \secentry {Implementing a Job Control Shell}{24}{6}{482} \subsecentry {Data Structures for the Shell}{24}{6}{1}{482} \subsecentry {Initializing the Shell}{24}{6}{2}{484} \subsecentry {Launching Jobs}{24}{6}{3}{486} \subsecentry {Foreground and Background}{24}{6}{4}{490} \subsecentry {Stopped and Terminated Jobs}{24}{6}{5}{492} \subsecentry {Continuing Stopped Jobs}{24}{6}{6}{496} \subsecentry {The Missing Pieces}{24}{6}{7}{496} \secentry {Functions for Job Control}{24}{7}{497} \subsecentry {Identifying the Controlling Terminal}{24}{7}{1}{497} \subsecentry {Process Group Functions}{24}{7}{2}{498} \subsecentry {Functions for Controlling Terminal Access}{24}{7}{3}{499} \chapentry {System Databases and Name Service Switch}{25}{501} \secentry {NSS Basics}{25}{1}{501} \secentry {The NSS Configuration File}{25}{2}{502} \subsecentry {Services in the NSS configuration File}{25}{2}{1}{503} \subsecentry {Actions in the NSS configuration}{25}{2}{2}{503} \subsecentry {Notes on the NSS Configuration File}{25}{2}{3}{504} \secentry {NSS Module Internals}{25}{3}{505} \subsecentry {The Naming Scheme of the NSS Modules}{25}{3}{1}{505} \subsecentry {The Interface of the Function in NSS Modules}{25}{3}{2}{506} \secentry {Extending NSS}{25}{4}{508} \subsecentry {Adding another Service to NSS}{25}{4}{1}{508} \subsecentry {Internals of the NSS Module Functions}{25}{4}{2}{509} \chapentry {Users and Groups}{26}{511} \secentry {User and Group IDs}{26}{1}{511} \secentry {The Persona of a Process}{26}{2}{511} \secentry {Why Change the Persona of a Process?}{26}{3}{512} \secentry {How an Application Can Change Persona}{26}{4}{513} \secentry {Reading the Persona of a Process}{26}{5}{513} \secentry {Setting the User ID}{26}{6}{514} \secentry {Setting the Group IDs}{26}{7}{515} \secentry {Enabling and Disabling Setuid Access}{26}{8}{516} \secentry {Setuid Program Example}{26}{9}{517} \secentry {Tips for Writing Setuid Programs}{26}{10}{520} \secentry {Identifying Who Logged In}{26}{11}{520} \secentry {User Database}{26}{12}{521} \subsecentry {The Data Structure that Describes a User}{26}{12}{1}{521} \subsecentry {Looking Up One User}{26}{12}{2}{522} \subsecentry {Scanning the List of All Users}{26}{12}{3}{523} \subsecentry {Writing a User Entry}{26}{12}{4}{525} \secentry {Group Database}{26}{13}{525} \subsecentry {The Data Structure for a Group}{26}{13}{1}{525} \subsecentry {Looking Up One Group}{26}{13}{2}{525} \subsecentry {Scanning the List of All Groups}{26}{13}{3}{527} \secentry {Netgroup Database}{26}{14}{528} \subsecentry {Netgroup Data}{26}{14}{1}{528} \subsecentry {Looking up one Netgroup}{26}{14}{2}{529} \subsecentry {Testing for Netgroup Membership}{26}{14}{3}{530} \secentry {User and Group Database Exampl