UNIX Systems Programming for SVR4

UNIX Systems Programming for SVR4

by David A. Curry

ISBN 10: 1-56592-163-1 / ISBN 13: 9781565921634

O'Reilly & Associates

August 1996

The following are made available for your personal, non-commercial use only. You may cite this document as a bibliographic reference in any works that you are writing. Any commercial use of this document, including printing and distribution to groups of people (such as a classroom) is prohibited without my prior written permission.

Complete text of the book:

Example source code:

From the back cover...

Any program worth its salt uses operating system services. Even the simplest program is likely to read input and produce output, and most real-world applications have more complex needs. They need to check the date and time, use the network, or start and communicate with other processes. "Systems programming" really means nothing more than writing software that uses these operating system services.

UNIX Systems Programming for SVR4 gives you the nitty gritty details on how UNIX interacts with applications. Whether you're a student, system administrator, or software developer, if you're working on any System V Release 4 platform, you'll find this book indispensable. The book contains many extended examples on topics ranging from string manipulation to network programming. These examples can serve as starting points for your own applications.

In addition to AT&T's release of SVR4, this book pays special attention to the three most important commercial UNIX implementations: Sun Microsystems' Solaris, Hewlett Packard's HP-UX 10, and Silicon Graphics' IRIX 5.3. It also includes notes on porting software from BSD UNIX to SVR4.

Topics covered include:

  • Working with low-level I/O routines and the standard I/O library
  • Creating and deleting files and directories, changing file attributes, processing multiple input streams, file and record locking, and memory-mapped files
  • Reading printing, and setting the system time and date
  • Determining who is logged in, when users log in and out, how to change a program's effective user ID or group ID, and how to write set-user-id programs
  • Changing system configuration parameters for resource limits
  • Creating processes, job control, and signal handling
  • Using pipes, FIFOs, UNIX-domain sockets, message queues, semaphores, and shared memory for interprocess communication
  • Reading and setting serial line characteristics including baud rate, echoing, and flow control
  • Network programming with Berkeley sockets and the Transport Layer Interface (TLI)

Table of Contents

Preface

Chapter 1 Introduction to SVR4

Standards Compliance

Notes on Compilers

The BSD Source Compatibility Package

Chapter 2 Utility Routines

Manipulating Character Strings

Manipulating Byte Strings

Manipulating Character Classes

Dynamic Memory Allocation

Manipulating Temporary Files

Parsing Command-Line Arguments

Miscellaneous Functions

Chapter Summary

Chapter 3 Low-Level I/O Routines

File Descriptors

Opening and Closing Files

Input and Output

Repositioning the Read/Write Offset

Duplicating File Descriptors

Chapter Summary

Chapter 4 The Standard I/O Library

Data Types and Constants

Opening and Closing Files

Character-Based Input and Output

Line-Based Input and Output

Buffer-Based Input and Output

Formatted Input and Output

Repositioning the Read/Write Offset

Reassigning a File Pointer

Buffering

Stream Status

File Pointers and File Descriptors

Chapter Summary

Chapter 5 Files and Directories

Filesystem Concepts

The UNIX Filesystem

Obtaining File Attributes

Changing File Attributes

Creating and Deleting Files and Directories

Working with Directories

Chapter Summary

Chapter 6 Special-Purpose File Operations

File Descriptor Attributes

Managing Multiple File Descriptors

File and Record Locking

Memory-Mapped Files

The /dev/fd Filesystem

Miscellaneous Functions

Chapter Summary

Chapter 7 Time of Day Operations

The Complexities of Time

Obtaining the Current Time

Obtaining the Local Time Zone

Converting Between UNIX Time and Human Time

Formatting Date Strings

Chapter Summary

Chapter 8 Users and Groups

Login Names

The User ID Number

The Group ID Number

The Password File

The Shadow Password File

The Group File

The utmp and wtmp Files

The Lastlog File

The Shells File

Writing Set-User-Id and Set-Group-Id Programs

Chapter Summary

Chapter 9 System Configuration and Resource Limits

General System Information

System Resource Liimts

Process Resource Limits

Resource Utilization Information

Chapter Summary

Chapter 10 Signals

Signal Concepts

Basic Signal Handling

Unreliable Signals

Reliable Signals

Signals and System Calls

Using Signals for Timeouts

Advanced Signal Handling

Porting Berkeley Signals to SVR4

Chapter Summary

Chapter 11 Processes

Process Concepts

Program Termination

Simple Program Execution

Advanced Program Execution

Redirecting Input and Output

Job Control

Timing Process Execution

Porting Notes

Chapter Summary

Chapter 12 Terminals

Overview of Terminal I/O

Terminal-Related Functions

POSIX Terminal Control

Pre-POSIX Terminal Control

Terminal Window Size

Chapter Summary

Chapter 13 Interprocess Communication

Pipes

FIFOs

UNIX-Domain Sockets

System V IPC Functions

Chapter Summary

Chapter 14 Networking with Sockets

Networking Concepts

Creating a Socket

Server-Side Functions

Client-Side Functions

Putting It All Together

Other Functions

Chapter Summary

Chapter 15 Networking with TLI

The netbuf Structure

Network Selection

Name-to-Address Translation

TLI Utility Functions

Transport Endpoint Management

Connectionless Service

Connection-Oriented Service

Other Functions

Using read and write with TLI

Chapter Summary

Chapter 16 Miscellaneous Routines

Exiting When Errors Occur

Error Logging

Searching

Sorting

Environment Variables

Passwords

Random Numbers

Directory Trees

Database Management

Pattern Matching

Internationalization

Chapter Summary

Appendix A Significant Changes in ANSI C

Appendix B Accessing Filesystem Data Structures

Appendix C The /proc Filesystem

Appendix D Pseudo-Terminals

Appendix E Accessing the Network at the Link Level

Index