Using C on the Unix System

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Using C on the UNIX System provides a thorough introduction to the UNIX system call libraries. It is aimed at programmers who already know C, but who want to take full advantage of the UNIX programming environment. If you want to learn how to work with the operating system and to write programs that can interact with directories, terminals, and networks at the lowest level, you will find this book essential. It is impossible to write UNIX utilities of any sophistication without understanding the material in this book.

Even if you don't want to program at this level, familiarity with the UNIX system interface is the mark of an experienced and fluent user. If you want to know how the C shell performs job control or how network addressing works, you will find the answer here. Your knowledge of the UNIX system is fundamentally incomplete until you can make C work for you.

Using C provides discussions of the most important system calls as well as detailed descriptions of the important system data structures.

Topics covered include:


Low-level I/O (open, close, read, write). Files, directories, and the low-level structure of the file system. I/O control, including terminal management (ioctl). Reading the system administrative databases (getpwent, etc.). Time, timers, and timing. Signal handling. How one program starts another program (system, execv, fork). Job control. Interprocess communication (sockets, message queues, semaphores, shared memory). Networking (addressing, port numbers). This book is based on Berkeley 4.3 UNIX, but also covers System V.

Author(s): Dave Curry
Publisher: O'Reilly Media
Year: 1989

Language: English
Pages: 250

Using C on the UNIX System
A Guide to System Programming
Preface
Documentation Conventions
Acknowledgements
Chapter 1 Introduction
System Calls vs. Library Routines
Versions of UNIX
Error Handling
Chapter 2 The Standard I/O Library
File Pointers
Opening and Creating Files
Closing Files
Reading and Writing Files
The getc and putc Routines
The fgets and fputs Routines
The fread and fwrite Routines
The fscanf and fprintf Routines
The sscanf and sprintf Routines
Moving Around in Files
Chapter 3 Low-Level I/O
File Descriptors
Opening and Creating Files
Opening and Creating Files on Older UNIX Systems
Closing Files
Reading and Writing Files
Moving Around in Files
Duplicating File Descriptors
Converting File Descriptors to File Pointers
Chapter 4 Files and Directories
File System Concepts
Ordinary Files
Directories
Special Files
Removable File Systems
Device Numbers
I-Numbers, the I-List, and I-Nodes
Hard Links
Symbolic Links
Determining the Accessibility of a File
Getting Information From an I-Node
Reading Directories
Modifying File Attributes
Miscellaneous File System Routines
Changing Directories
Deleting and Truncating Files
Making Directories
Linking and Renaming Files
Symbolic Links
The umask Value
Chapter 5 Device I/O Control
The Version 7 and Berkeley UNIX ioctl
Line Disciplines
The sgttyb Structure
The tchars Structure
The ltchars Structure
The Local Mode Word
The winsize Structure
Miscellaneous Operations
The System V ioctl
c_iflag
c_oflag
c_cflag
c_lflag
c_cc
The fcntl System Call
Non-Blocking I/O
The select System Call
Chapter 6 Information About Users
The Login Name
The User Id
The Group Id
The Berkeley UNIX Group Mechanism
Reading the Password File
Reading the Group File
Reading the utmp File
Chapter 7 Telling Time and Timing Things
Telling Time
Obtaining the Time
Timezones
Converting the Time to ASCII
Time Differences
Sleeping and Alarm Clocks
Sleeping
The Alarm Clock
Interval Timers
Process Timing
Changing File Times
Chapter 8 Processing Signals
Overview of Signal Handling
Resetting Signals
Restarting System Calls
The Signals
Sending Signals
Catching and Ignoring Signals
Ignoring Signals
Catching Signals
Using Signals for Timeouts
The setjmp and longjmp Routines
The New Berkeley UNIX Signal Mechanism
Handler Calling Conventions
The Signal Mask
The Signal Stack
Chapter 9 Executing Programs
The system Library Routine
Executing Programs Directly
Creating Processes
Executing Programs
Waiting for Processes to Terminate
Redirecting Input and Output
Setting Up Pipelines
The popen Library Routine
Creating Pipes Directly
Chapter 10 Job Control
Preliminary Concepts
The Controlling Terminal
Process Groups
System Calls
ioctl
setpgrp
killpg
wait3
The JOB and PROC Data Types
Job Control in the Shell
Setting Up for Job Control
Executing a Program
Stopping a Job
Backgrounding a Job
Foregrounding a Job
The jobs Command
Waiting for Jobs
Asynchronous Process Notification
Job Control Outside the Shell
Important Points
Chapter 11 Interprocess Communication
Berkeley UNIX IPC
The socket System Call
The bind System Call
The send and recv System Calls
The listen System Call
The shutdown System Call
Connection-Based Sockets
The accept System Call
The connect System Call
Connectionless Sockets
The sendto System Call
The recvfrom System Call
Connecting Datagram Sockets
A Small Client Program
A Small Server Program
System V IPC
Message Queues
The msgget System Call
The msgctl System Call
The msgsnd and msgrcv System Calls
Semaphores
The semget System Call
The semctl System Call
The semop System Call
Shared Memory
The shmget System Call
The shmctl System Call
The shmat System Call
The shmdt System Call
Chapter 12 Networking
Addresses
Translating Hostnames Into Network Numbers
Obtaining Port Numbers
Network Byte Order
Networking System Calls
Chapter 13 The File System
Disk Terminology
The “Standard” UNIX File System
The Berkeley Fast File System
Reading Data Blocks From the File System
Chapter 14 Miscellaneous Routines
Resource Limits
The getrlimit System Call
The setrlimit System Call
Obtaining Resource Usage Information
Manipulating Byte Strings
The bcmp and memcmp Library Routines
The bcopy and memcpy Library Routines
The bzero and memset Library Routines
Environment Variables
The Current Working Directory
Searching for Characters in Strings
Determining Whether a File is a Terminal
The isatty Library Routine
The ttyname Library Routine
The /dev/tty Device
Printing Error Messages
The perror Library Routine
The psignal Library Routine
Sorting Arrays in Memory
Appendix A Calling FORTRAN From C
Data Representation
Procedure Naming
Naming C Routines to be Called From FORTRAN
Naming FORTRAN Routines to be Called From C
Returning Values from Functions
Integer, Logical, Real, Double Precision
Complex and Double Complex
Character Strings
Passing Arguments
Integers, Floats (Reals), and Doubles
Characters and Logicals
Character Strings
Functions
Overall Argument Sequence
Input and Output
From C Programs
From FORTRAN Programs
Libraries
Further Information
Appendix B Using Berkeley UNIX Pseudo Terminals
Appendix C Reading Kernel Data Structures
Appendix D Berkeley UNIX Directory Compatibility Routines
Appendix E Interval Timer Version of nap()
Bibliography
Colophon