Home > Store

Advanced UNIX Programming

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

Advanced UNIX Programming

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2000
  • Dimensions: 7-3/8" x 9-1/8"
  • Pages: 624
  • Edition: 1st
  • Book
  • ISBN-10: 0-672-31990-X
  • ISBN-13: 978-0-672-31990-7

Advanced UNIX Programming goes beyond the fundamentals of UNIX programming and presents information and techniques the readers needs to expand their knowledge base. Designed for professional UNIX programmers, this book builds on the skills and knowledge the reader already possesses. It includes coverage of internet processes, interprocess control, file system manipulation, synchronization, and much more.

Downloads

Downloads

Source code from the book for Linux users- 47kb -- source.tar.gz
Source code from the book for Linux users- 75kb -- source.tar.z
Java archive files for Windows platforms- 93kb -- source.zip

Sample Content

Table of Contents



Introduction.

I: FILES AND DIRECTORIES.

1. Compiler Notes and Options.

Online Manual Pages.

Manual References Used in This Book. man(1) Resources on the Internet.

Example Code in This Book. Compiling C Programs.

The C Compile Command.

Managing Compiler Warnings.

Working with Compiler Warning Messages. Compiling to Standards. FreeBSD 3.4-Release Feature Tests. HPUX 10.2 Feature Tests. AIX 4.3 Feature Tests. SunOS 5.6 Feature Tests. Feature Test Summary.

Summary.

2. UNIX File System Objects.

File System Objects.

Regular Files. Directories. Block Devices. Character Devices. Named Pipes (FIFOs). Sockets. Symbolic Links. Special Files.

Permissions.

Access of Regular Files. Access of Directories.

Working with Files Under UNIX.

Opening and Closing Files. Opening Special Files. Working with Sockets. Duplicating File Descriptors.

UNIX File I/O. Summary.

3. Error Handling and Reporting.

Determining Success or Failure.

General Rules for Error Indication. Exceptions to the General Rule. Classifying Successful Return Values. Other Return Indications.

Determining the Reason for Failure. The Old errno Value.

Referencing Error Codes by Name. Applying errno Correctly.

The New errno Value.

Declaring the New errno Variable. Using the New errno Variable.

Reporting on errno Values.

Using the perror(3) Function. Using the sys_errlist[ ] Array. The strerror(3) Function.

Testing for Errors Using stdio(3).

Pitfalls of the ferror(3) Function. Avoiding the fclose(3) Pitfall. Delaying the Reporting of an Error.

Summary.

4. UNIX Input and Output.

The umask(2) Function and umask Bits.

Permission Bits. Understanding the Need for umask. Understanding the Scope of umask. Using the umask(2) Function. Example Using the umask Value. The <F102MO>umask(2) Function. The creat(2) Function.

Reading and Writing.

Introducing <F102MO>read(2) and <F102MO>write(2). Applying UNIX I/O.

Seeking Within a File.

Applying lseek(2).

Truncating Files.

The truncate(2) Function. The ftruncate(2) Function.

Sparse Files.

Creating a Sparse File.

Forcing Data to Media.

The sync(2) Function. The Disadvantages of sync(2). The fsync(2) Function.

Scattered Reading and Writing.

The readv(2) and writev(2) Functions.

Determining Your tty Name. Summary.

5. File Locking.

Understanding Lock Types. The Lock File Technique.

Limitations of the Lock File. Using an Advisory Lock on the Entire File. Locking with flock(2).

Record Locking.

Locking with lockf(2). POSIX Locking with fcntl(2). Mandatory Locking. Enabling Mandatory Locking.

Summary.

6. Managing Files and Their Properties.

Removing Files. Linking Files. Moving Files. Obtaining File System Information.

The stat(2) Function. The fstat(2) Function. Working with File Properties. Testing for File Type. Modification, Access, and Creation Times.

Testing Access to a File. Symbolic Links.

The symlink(2) Function. The lstat(2) Function. Reading the Contents of the Symbolic Link with readlink(2).

File Permissions and Ownership.

Changing Permissions. Changing Ownership.

Named Pipes (FIFOs). Obtaining Size and Configuration Information. Summary.

7. Directory Management.

Obtaining the Working Directory.

Specifying a Null Buffer Argument.

Changing the Current Directory.

Saving a Working Directory. A Limitation of fchdir(2).

Making a New Directory. Removing a Directory. Opening a Directory for Searching. Closing a Directory. Searching a Directory. Rewinding to the Start of a Directory. Saving Position Within a Directory. Restoring Position Within a Directory. Scanning a Directory.

Declaring Your Own select Function for <F102MO>scandir(3). Declaring Your Own compar Function for scandir(3). SysV Variations. A scandir(3) Example.

Walking a Directory Structure. Changing Your Root Directory. Summary.

8. Temporary Files and Process Cleanup.

Creating Temporary Files.

Using the tmpnam(3) Function. Using the mktemp(3) Function. Using the mkstemp(3) Function. Using the mkstemps(3) Function. Using the tmpfile(3) Function. Using the <F102MO>tempnam(3) Function.

Making Files Temporary.

Using unlink(2) to Make Files Temporary. Performing Exit Cleanup. Using the atexit(3) Function. Using C++ Destructors. Avoiding Cleanup with _exit(2).

Summary.

II. LIBRARY FUNCTIONS.

9. UNIX Command-Line Processing.

Command-Line Conventions.

Using Multiple Options. Combining Multiple Options. Using Options with Arguments. Identifying Options or Arguments.

Arguments That Look Like Options. The getopt(3) Function.

The getopt(3) External Values. The getopt(3) Function Call. Defining the optstring Argument. Defining an Option-Processing Loop.

The getsubopt(3) Function.

Determining the End of Suboption Processing. A Full getsubopt(3) Example.

GNU Long Options Extension.

The GNU getopt_long(3) Function. Understanding the option Structure. Setting Up the option Structure. Using a Null option.flag Pointer. Using a Non-Null option.flag Pointer.

Summary.

10. Conversion Functions.

Simple Conversion Functions.

Scrutinizing the Functions atoi(3) and atol(3). The atof(3) Function.

Using sscanf(3) for Conversion and Validation.

Applying sscanf(3) to Numeric Conversion. Testing Numeric Conversions Using sscanf(3). Improving the sscanf(3) Conversion. The Limitations of sscanf(3).

The strtol(3) and strtoul(3) Functions.

Using the strtol(3) Function. Testing for Errors. Testing the Conversion Pointer. Performing Multiple Conversions. Using the base Argument for Radix Conversions. Testing for Overflows and Underflows. Testing for strtoul(3) Overflows.

Large Integer Conversions. BSD strtoq(3) and strtouq(3) Functions. The strtod(3) Function.

Using the strtod(3) Function. Testing for Math Errors. Flowchart of Math Error Tests.

Summary.

11. UNIX Date and Time Facilities.

Time Zones.

Introducing World Time Standards.

Defining the Date and Time Data Type. Time Conversion Functions.

Converting Time to String Form Using ctime(3). The ctime_r(3) Function. The localtime(3) and gmtime(3) Functions. The Members of the struct tm. Conversion of Date/Time Components to Strings Using the asctime(3) Function. The tzset(3) Function. Creating Epoch Time Values with the mktime(3) Function.

Customizing Date and Time Formats with strftime(3).

The strftime(3) Format Specifiers. Implementing the <F102MO>DTime::strftime() Method. Testing Class DTime. Understanding the Effects of Locale.

Summary.

12. User, Password, and Group Management.

Introduction to UNIX User Management.

Understanding Username and User ID Numbers. Understanding Username root. The Group Name and Group ID Numbers. Understanding gid Zero.

The getuid(2) and geteuid(2) Functions. The getgid(2) and getegid(2) Functions. Real, Effective, and Saved User ID.

The Effective User ID. The Real User ID. The Saved User ID. The Identification Role Summary.

Setting User ID. Setting Group ID. The FreeBSD Function issetugid(2). The <F102MO>/etc/passwd File.

The Comment Field. Using the & Feature of the Comment Field.

The Password Database Routines.

The passwd Structure. Error Handling for getpwent(3). The fgetpwent(3) Function. The putpwent(3) Function. The getpwuid(3) Function. The getpwnam(3) Function.

The Group Database.

The <F102MO>/etc/group File. Functions getgrent(3), <F102MO>setgrent(3), and endgrent(3). Understanding the group Structure. The fgetgrent(3) Function. The getgrgid(3) Function. The getgrnam(3) Function.

Related Re-entrant Functions. Supplementary Groups.

The getgroups(2) Function. Setting Groups with setgroups(2). Setting Groups for a Specific Username.

Summary.

13. Static and Shared Libraries.

The Static Library.

Examining the Process Memory Image. Implementing a Static Library. Using the ar(1) Command to Create an Archive. Listing the Contents of an Archive. Obtaining a Verbose Listing of an Archive. Linking with Static Libraries.

The Shared Library.

Limitations of Static Libraries. Creating a Shared Library Linking with a Shared Library. Choosing Static or Dynamic Libraries. Listing Shared Library References. The Dynamic Loader. Position-Independent Code. Controlling What Is Shared.

Comparing Static and Shared Libraries.

The Benefits of Static Libraries. The Benefits of Shared Libraries.

Dynamic Library Loading.

Opening the Shared Library. Reporting Errors. Obtaining a Shared Reference Pointer. Closing a Shared Library. Initialization and Destruction. Applying Dynamic Loading. HPUX 10.2 Dynamic Library Loading.

Summary.

14. Database Library Routines.

The NDBM Database.

Error Handling. Opening an NDBM Database. Closing an NDBM Database. Storing Information. Fetching Information. Deleting Information. Visiting All Keys. Deleting Keys with dbm_nextkey(3).

An NDBM Database Example.

Directory Software. The Dbm Class. The InoDb Class. The SnapShot Application. Running the SnapShot Application. Visiting All Keys and Deletion.

Summary.

III. ADVANCED CONCEPTS.

15. Signals.

Understanding UNIX Signals. Reliable and Unreliable Signals. The Unreliable signal(3) API. The Reliable Signal API.

Emptying a Signal Set. Filling a Signal Set. Adding Signals to a Signal Set. Removing Signals from a Signal Set. Testing for Signals in a Set. Setting Signal Actions. Signal Action Flags Applying Reliable Signals.

Controlling Signals.

Blocking Signals. Obtaining Pending Signals. The sigsuspend(2) Function.

Applying the alarm(3) Function. Calling Functions from a Signal Handler.

Avoiding Re-entrant Code Issues. Re-entrancy Issues with errno in a Signal Handler.

Applying the EINTR Error Code. Raising Signals. Summary.

16. Efficient I/O Scheduling.

Non-Blocking I/O.

Opening Files in Non-Blocking Mode. Setting Non-Blocking Mode. Performing Non-Blocking I/O. The Problem with Non-Blocking I/O.

I/O Scheduling Functions.

File Descriptor Sets and Their Macros. The timeval Structure. The select(2) Function. Using the select(2) Function.

I/O Polling.

Poll Events. Poll Priorities. A poll(2) Example.

Summary.

17. Timers.

The Sleep Functions.

The UNIX Implementation of sleep(3). Sleeping in Microsecond Units. Sleeping in Nanosecond Units.

Interval Timer Functions.

The Interval Timer API. Interval Timer Macros. Interval Timer Restrictions. Creating One-Shot Timers. Establishing Repeating Timers.

Summary.

18. Pipes and Processes.

UNIX Pipes.

Creating UNIX Pipes. Opening Pipes to Other Processes. Reading from Pipes. Writing to Pipes. Closing a Pipe. Handling a Broken Pipe.

External Processes Without Pipes.

Interpreting system(3) Return Values. Invoking Commands. Scrutinizing the system(3) Function.

Summary.

19. Forked Processes.

Overview of the UNIX Fork Process. The fork(2) Function.

Applying fork(2).

Waiting for Process Completion.

Zombie Processes. The wait(2) Function. Interpreting the Exit Status. Other Wait System Calls.

Executing New Programs.

Other exec(2) Family Members.

Summary.

20. Pattern Matching.

Shell Patterns.

The * Meta-Character. The ? Meta-Character. The [ and ] Meta-Characters. The ! Meta-Character. Escaping Characters with \.

String Pattern Functions. The glob(3) Function.

Return Values for glob(3).

Summary.

21. Regular Expressions.

Understanding Regular Expressions.

Anchors. Sets. Range. Character Classes. The . Meta-Character. Parenthesized Match Subexpression. Atoms. Piece. Branch. Expression Bounds. Quoted Characters.

The Regular Expression Library.

Compiling Regular Expressions. Reporting Errors. Freeing Regular Expressions. Matching Regular Expressions. Applying Regular Expressions.

Summary.

22. Interprocess Communication Concepts.

Types of IPC. The Message Queue. Shared Memory. Semaphores. Referencing IPC Resources.

The IPC Key Value. Creating an IPC Resource. Accessing by IPC Key. Accessing by IPC ID.

Destroying IPC Resources. Summary.

23. Message Queues.

Controlling a Message Queue.

Creating Message Queues. Accessing a Message Queue. Destroying a Message Queue. Obtaining Message Queue Information. Altering a Message Queue.

Sending and Receiving Messages.

Sending Messages. Receiving Messages.

Applying Message Queues. Summary.

24. Semaphores.

Semaphore Utility Program. Creating and Accessing Semaphore Sets. Destroying Semaphore Sets. Controlling Semaphores.

Querying Semaphore Sets. Changing Semaphore Access. Querying the Value of a Semaphore. Query the Entire Semaphore Set of Values. Change the Value of a Semaphore. Change the Entire Semaphore Set of Values. Querying the Process ID for a Semaphore. Query the Number of Processes Waiting for Notifies. Query the Number of Processes Waiting for Zero.

Using Semaphores.

Waiting on Semaphores. Notifying Semaphores. Waiting for Zero. Semaphore Undo Processing. The semop Utility Program.

Summary.

25. Shared Memory.

The globvar Utility Program.

Creating Global Variable Pools. Destroying Global Variable Pools. The GLOBVAR Environment Variable. Creating Global Variables. Accessing Global Variables. Removing Global Variables. Clearing Global Variable Pools.

Shared Memory System Calls.

Creating and Accessing Shared Memory. Obtaining Information About Shared Memory. Changing Shared Memory Attributes. Attaching Shared Memory. Detaching Shared Memory. Destroying Shared Memory.

Using Shared Memory. Summary.

26. Memory-Mapped Files.

Determining the Page Size. Creating Memory Mappings. Controlling Memory-Mapped Regions.

Changing the Access Protection. Advising the Kernel About Memory Use. Querying Pages in Memory. Synchronizing Changes.

Destroying Memory Mappings. Summary.

27. X Window Programming.

Event-Driven Programming.

An Event-Driven Model. Client/Server Processing. Software Layers.

An Xlib Client Program. Summary.

Index.

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