Home > Store

Advanced Programming in the UNIX Environment, 3rd Edition

Register your product to gain access to bonus material or receive a coupon.

Advanced Programming in the UNIX Environment, 3rd Edition

Best Value Purchase

Book + eBook Bundle

  • Your Price: $79.44
  • List Price: $136.98
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Acrobat® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

More Purchase Options

Book

  • Your Price: $55.99
  • List Price: $69.99
  • Usually ships in 24 hours.

eBook (Watermarked)

  • Your Price: $53.59
  • List Price: $66.99
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Acrobat® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

About

Features

  • W. Richard Stevens' definitive, classic guide to UNIX® programming, now 100% updated for today's leading systems and distributions!
  • The #1 guide to UNIX/Linux programming since 1992: now updated to address newer versions of Red Hat, Solaris, FreeBSD, and Mac OS X, cover Ubuntu Linux, and reflect newer techniques and best practices
  • Contains nearly 10,000 lines of code, all carefully tested on today's most widely-used UNIX/Linux platforms

Description

  • Copyright 2013
  • Dimensions: 7-3/8" x 9-1/8"
  • Pages: 1032
  • Edition: 3rd
  • Book
  • ISBN-10: 0-321-63773-9
  • ISBN-13: 978-0-321-63773-4

Practical, in-depth knowledge of the system programming interfaces that drive the UNIX and Linux kernels

Building on W. Rich Stevens’ pioneering work, this third edition of the classic was updated by Steve Rago, a colleague of Stevens, to reflect technical advances and best practices aligning with Version 4 of the Single UNIX Specification.

This edition covers more than seventy interfaces including:

  • POSIX asynchronous I/O
  • Spin locks
  • Barriers
  • POSIX semaphores

Steve carefully retains the spirit and approach that have made this book so valuable, starting with files, directories, and processes, carefully laying the groundwork for more advanced techniques, such as signal handling and terminal I/O. And he thoroughly covers threads and multithreaded programming, and socket-based IPC.

Filled with examples, case-studies, and access to thousands of lines of downloadable code, Advanced Programming in the UNIX® Environment has helped generations of programmers write code with exceptional power, performance, and reliability.

Extras

Related Article

Advanced Debugging in the Linux Environment

Author's Site

Please visit the author's site here.

Sample Content

Online Sample Chapter

Using Threads within a UNIX Process

Excerpt

Preface to "Advanced Programming in the UNIX Environment, 3rd Edition"

Sample Pages

Download the sample pages (includes Chapter 11 and Index)

Table of Contents

Foreword to the Second Edition xix

Preface xxi

Preface to the Second Edition xxv

Preface to the First Edition xxix

Chapter 1: UNIX System Overview 1

1.1 Introduction 1

1.2 UNIX Architecture 1

1.3 Logging In 2

1.4 Files and Directories 4

1.5 Input and Output 8

1.6 Programs and Processes 10

1.7 Error Handling 14

1.8 User Identification 16

1.9 Signals 18

1.10 Time Values 20

1.11 System Calls and Librar y Functions 21

1.12 Summary 23

Chapter 2: UNIX Standardization and Implementations 25

2.1 Introduction 25

2.2 UNIX Standardization 25

2.3 UNIX System Implementations 33

2.4 Relationship of Standards and Implementations 36

2.5 Limits 36

2.6 Options 53

2.7 Feature Test Macros 57

2.8 Primitive System Data Types 58

2.9 Differences Between Standards 58

2.10 Summary 60

Chapter 3: File I/O 61

3.1 Introduction 61

3.2 File Descr iptors 61

3.3 open and openat Functions 62

3.4 creat Function 66

3.5 close Function 66

3.6 lseek Function 66

3.7 read Function 71

3.8 write Function 72

3.9 I/O Efficiency 72

3.10 File Shar ing 74

3.11 Atomic Operations 77

3.12 dup and dup2 Functions 79

3.13 sync, fsync, and fdatasync Functions 81

3.14 fcntl Function 82

3.15 ioctl Function 87

3.16 /dev/fd 88

3.17 Summary 90

Chapter 4: Files and Directories 93

4.1 Introduction 93

4.2 stat, fstat, fstatat, and lstat Functions 93

4.3 File Types 95

4.4 Set-User-ID and Set-Group-ID 98

4.5 File Access Per missions 99

4.6 Ownership of New Files and Directories 101

4.7 access and faccessat Functions 102

4.8 umask Function 104

4.9 chmod, fchmod, and fchmodat Functions 106

4.10 Sticky Bit 108

4.11 chown, fchown, fchownat, and lchown Functions 109

4.12 File Size 111

4.13 File Tr uncation 112

4.14 File Systems 113

4.15 link, linkat, unlink, unlinkat, and remove Functions 116

4.16 rename and renameat Functions 119

4.17 Symbolic Links 120

4.18 Creating and Reading Symbolic Links 123

4.19 File Times 124

4.20 futimens, utimensat, and utimes Functions 126

4.21 mkdir, mkdirat, and rmdir Functions 129

4.22 Reading Director ies 130

4.23 chdir, fchdir, and getcwd Functions 135

4.24 Device Special Files 137

4.25 Summary of File Access Per mission Bits 140

4.26 Summary 140

Chapter 5: Standard I/O Library 143

5.1 Introduction 143

5.2 Streams and FILE Objects 143

5.3 Standard Input, Standard Output, and Standard Error 145

5.4 Buffer ing 145

5.5 Opening a Stream 148

5.6 Reading and Writing a Stream 150

5.7 Line-at-a-Time I/O 152

5.8 Standard I/O Efficiency 153

5.9 Binary I/O 156

5.10 Positioning a Stream 157

5.11 For matted I/O 159

5.12 Implementation Details 164

5.13 Temporar y Files 167

5.14 Memory Streams 171

5.15 Alternatives to Standard I/O 174

5.16 Summary 175

Chapter 6: System Data Files and Information 177

6.1 Introduction 177

6.2 Password File 177

6.3 Shadow Passwords 181

6.4 Group File 182

6.5 Supplementary Group IDs 183

6.6 Implementation Differences 184

6.7 Other Data Files 185

6.8 Login Accounting 186

6.9 System Identification 187

6.10 Time and Date Routines 189

6.11 Summary 196

Chapter 7: Process Environment 197

7.1 Introduction 197

7.2 main Function 197

7.3 Process Termination 198

7.4 Command-Line Arguments 203

7.5 Environment List 203

7.6 Memory Lay out of a C Program 204

7.7 Shared Librar ies 206

7.8 Memory Allocation 207

7.9 Environment Var iables 210

7.10 setjmp and longjmp Functions 213

7.11 getrlimit and setrlimit Functions 220

7.12 Summary 225

Chapter 8: Process Control 227

8.1 Introduction 227

8.2 Process Identifiers 227

8.3 fork Function 229

8.4 vfork Function 234

8.5 exit Functions 236

8.6 wait and waitpid Functions 238

8.7 waitid Function 244

8.8 wait3 and wait4 Functions 245

8.9 Race Conditions 245

8.10 exec Functions 249

8.11 Changing User IDs and Group IDs 255

8.12 Interpreter Files 260

8.13 system Function 264

8.14 Process Accounting 269

8.15 User Identification 275

8.16 Process Scheduling 276

8.17 Process Times 280

8.18 Summary 282

Chapter 9: Process Relationships 285

9.1 Introduction 285

9.2 Ter minal Logins 285

9.3 Networ k Logins 290

9.4 Process Groups 293

9.5 Sessions 295

9.6 Controlling Terminal 296

9.7 tcgetpgrp, tcsetpgrp, and tcgetsid Functions 298

9.8 Job Control 299

9.9 Shell Execution of Programs 303

9.10 Orphaned Process Groups 307

9.11 FreeBSD Implementation 310

9.12 Summary 312

Chapter 10: Signals 313

10.1 Introduction 313

10.2 Signal Concepts 313

10.3 signal Function 323

10.4 Unreliable Signals 326

10.5 Interrupted System Calls 327

10.6 Reentrant Functions 330

10.7 SIGCLD Semantics 332

10.8 Reliable-Signal Ter minology and Semantics 335

10.9 kill and raise Functions 336

10.10 alarm and pause Functions 338

10.11 Signal Sets 344

10.12 sigprocmask Function 346

10.13 sigpending Function 347

10.14 sigaction Function 349

10.15 sigsetjmp and siglongjmp Functions 355

10.16 sigsuspend Function 359

10.17 abort Function 365

10.18 system Function 367

10.19 sleep, nanosleep, and clock_nanosleep Functions 373

10.20 sigqueue Function 376

10.21 Job-Control Signals 377

10.22 Signal Names and Numbers 379

10.23 Summary 381

Chapter 11: Threads 383

11.1 Introduction 383

11.2 Thread Concepts 383

11.3 Thread Identification 384

11.4 Thread Creation 385

11.5 Thread Termination 388

11.6 Thread Synchronization 397

11.7 Summary 422

Chapter 12: Thread Control 425

12.1 Introduction 425

12.2 Thread Limits 425

12.3 Thread Attr ibutes 426

12.4 Synchronization Attr ibutes 430

12.5 Reentrancy 442

12.6 Thread-Specific Data 446

12.7 Cancel Options 451

12.8 Threads and Signals 453

12.9 Threads and fork 457

12.10 Threads and I/O 461

12.11 Summary 462

Chapter 13: Daemon Processes 463

13.1 Introduction 463

13.2 Daemon Character istics 463

13.3 Coding Rules 466

13.4 Error Logging 469

13.5 Single-Instance Daemons 473

13.6 Daemon Conventions 474

13.7 Client–Server Model 479

13.8 Summary 480

Chapter 14: Advanced I/O 481

14.1 Introduction 481

14.2 Nonblocking I/O 481

14.3 Record Locking 485

14.4 I/O Multiplexing 500

14.5 Asynchronous I/O 509

14.6 readv and writev Functions 521

14.7 readn and writen Functions 523

14.8 Memory-Mapped I/O 525

14.9 Summary 531

Chapter 15: Interprocess Communication 533

15.1 Introduction 533

15.2 Pipes 534

15.3 popen and pclose Functions 541

15.4 Coprocesses 548

15.5 FIFOs 552

15.6 XSI IPC 556

15.7 Message Queues 561

15.8 Semaphores 565

15.9 Shared Memor y 571

15.10 POSIX Semaphores 579

15.11 Client–Server Proper ties 585

15.12 Summary 587

Chapter 16: Network IPC: Sockets 589

16.1 Introduction 589

16.2 Socket Descr iptors 590

16.3 Addressing 593

16.4 Connection Establishment 605

16.5 Data Tr ansfer 610

16.6 Socket Options 623

16.7 Out-of-Band Data 626

16.8 Nonblocking and Asynchronous I/O 627

16.9 Summary 628

Chapter 17: Advanced IPC 629

17.1 Introduction 629

17.2 UNIX Domain Sockets 629

17.3 Unique Connections 635

17.4 Passing File Descriptors 642

17.5 An Open Server, Version 1 653

17.6 An Open Server, Version 2 659

17.7 Summary 669

Chapter 18: Terminal I/O 671

18.1 Introduction 671

18.2 Over view 671

18.3 Special Input Characters 678

18.4 Getting and Setting Ter minal Attr ibutes 683

18.5 Ter minal Option Flags 683

18.6 stty Command 691

18.7 Baud Rate Functions 692

18.8 Line Control Functions 693

18.9 Ter minal Identification 694

18.10 Canonical Mode 700

18.11 Noncanonical Mode 703

18.12 Ter minal Window Size 710

18.13 termcap, terminfo, and curses 712

18.14 Summary 713

Chapter 19: Pseudo Terminals 715

19.1 Introduction 715

19.2 Over view 715

19.3 Opening Pseudo-Ter minal Devices 722

19.4 pty_fork Function 726

19.5 pty Program 729

19.6 Using the pty Program 733

19.7 Advanced Features 740

19.8 Summary 741

Chapter 20: A Database Library 743

20.1 Introduction 743

20.2 History 743

20.3 The Librar y 744

20.4 Implementation Over view 746

20.5 Centralized or Decentralized? 750

20.6 Concurrency 752

20.7 Building the Librar y 753

20.8 Source Code 753

20.9 Perfor mance 781

20.10 Summary 786

Chapter 21: Communicating with a Network Printer 789

21.1 Introduction 789

21.2 The Inter net Pr inting Protocol 789

21.3 The Hyper text Transfer Protocol 792

21.4 Printer Spooling 793

21.5 Source Code 795

21.6 Summary 843

Appendix A: Function Prototypes 845

Appendix B: Miscellaneous Source Code 895

B.1 Our Header File 895

B.2 Standard Error Routines 898

Appendix C: Solutions to Selected Exercises 905

Bibliography 947

Index 955

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020