Home > Store

Linux Application Development

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

Linux Application Development

Book

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

Description

  • Copyright 1998
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-30821-5
  • ISBN-13: 978-0-201-30821-1

A new edition of this title is available, ISBN-10: 0321563220 ISBN-13: 9780321563224

Downloads

Source Code

Click below for Source Code related to this title:
Source code

Supplements

Linux Information Here are some pointers to other Linux-related sites:

  • The Linux Documentation Project, recent Linux news and lots of freely-available documentation.
  • The comp.os.linux.announce archives; look here for announcements of all sorts of software, user group meetings, and other things related to Linux.
  • Red Hat Software, distributor of Red Hat Linux, the leading Linux distribution (and employer of both of the authors).
  • LinuxHQ, technical information about recent Linux kernels, including patches, descriptions of changes, and mailing list archives.
  • The Linux Kernel Archives, the official distribution point for the Linux Kernel, and more.
  • Slashdot.org, technical news, rumors, and editorials with frequent Linux coverage.
  • Freshmeat, up-to-the-second news on the latest software releases in the Linux world.
  • Linux Weekly News, Linux News, updated every Thursday.
  • Linux Web Watcher, keeps track of recent changes to Linux-related web pages.
  • Linux Journal, a monthly magazine about Linux.

Sample Content

Table of Contents



Preface.

I. GETTING STARTED.

History of Linux Development.

A Short History of Free UNIX Software.

Development of Linux.

Basic Lineage of UNIX Systems.

Linux Lineage.

Licenses and Copyright.

Copyright.

Licensing.

Free Software Licenses.

Combinations of Free and Commercial Software.

The GNU General Public License.

The GNU Library General Public License.

MIT/X-Style Licenses.

BSD-Style Licenses.

Artistic License.

License Incompatibilities.

More Information on Linux.

Overview of Linux Documentation.

The HOWTOs and mini-HOWTOs.

The LDP Books.

The Linux Software Map.

The man Pages.

Other Books.

Source Code.

Linux (and Other) Newsgroups.

Mailing Lists.

vger.

Other Lists.

Other Documentation.

GNU.

BSD.

Your Distribution Vendor.

II. DEVELOPMENT TOOLS AND ENVIRONMENT.

Development Tools.

Editors.

Emacs.

vi.

Make.

Complex Command Lines.

Variables.

Suffix Rules.

The GNU Debugger.

gcc Options and Extensions.

gcc Options.

Header Files.

long long.

Inline Functions.

Alternative Extended Keywords.

Attributes.

Memory Debugging Tools.

Buggy Code.

Electric Fence.

Using Electric Fence.

Memory Alignment.

Other Features.

Limitations.

Resource Consumption.

Checker.

Finding Overruns.

Finding Memory Leaks.

mpr and mcheck().

Finding Memory Corruption with mcheck.

Finding Memory Leaks with mpr.

Creating and Using Libraries.

Static Libraries.

Shared Libraries.

Designing Shared Libraries.

Managing Compatibility.

Incompatible Libraries.

Designing Compatible Libraries.

Building Shared Libraries.

Installing Shared Libraries.

Example.

Using Shared Libraries.

Using Noninstalled Libraries.

Preloading Libraries.

Linux Development Environment.

Understanding System Calls.

System Call Limitations.

System Call Return Codes.

Using System Calls.

Common Error Return Codes.

Finding Header and Library Files.

III. System Programming.

The Process Model.

Defining a Process.

Complicating Things with Threads.

The Linux Approach.

Process Attributes.

The pid and Parentage.

Credentials.

The fsuid.

User and Group ID Summary.

Process Information.

Program Arguments.

Resource Usage.

Establishing Usage Limits.

Process Primitives.

Having Children.

Watching Your Children Die.

Running New Programs.

A Bit of History: vfork().

Killing Yourself.

Killing Others.

Dumping Core.

Simple Children.

Running and Waiting with system().

Reading or Writing from a Process.

Sessions and Process Groups.

Sessions.

Controlling Terminal.

Process Groups.

Introduction to ladsh.

Running External Programs with ladsh.

Creating Clones.

Simple File Handling.

The File Mode.

File Access Permissions.

File Permission Modifiers.

File Types.

The Process's umask.

Basic File Operations.

File Descriptors.

Closing Files.

Opening Files in the File System.

Reading, Writing, and Moving Around.

Partial Reads and Writes.

Shortening Files.

Other Operations.

Querying and Changing Inode Information.

Finding Inode Information.

A Simple Example of stat().

Easily Determining Access Rights.

Changing a File's Access Permissions.

Changing a File's Owner and Group.

Changing a File's Timestamps.

Ext2 Extended Attributes.

Manipulating Directory Entries.

Creating Device and Named Pipe Entries.

Creating Hard Links.

Using Symbolic Links.

Removing Files.

Renaming Files.

Manipulating File Descriptors.

Changing the Access Mode for an Open File.

Modifiying the close-on-exec Flag.

Duplicating File Descriptors.

Creating Unnamed Pipes.

Adding Redirection to ladsh.

The Data Structures.

Changing the Code.

Directory Operations.

The Current Working Directory.

Finding the Current Working Directory.

The . and .. Special Files.

Changing the Current Directory.

Changing the Root Directory.

Creating and Removing Directories.

Creating New Directories.

Removing Directories.

Reading a Directory's Contents.

Starting Over.

File Name Globbing.

Use a Subprocess.

Internal Globbing.

Adding Directories and Globbing to ladsh.

Adding cd and pwd.

Adding File Name Globbing.

Advanced File Handling.

Input and Output Multiplexing.

Nonblocking I/O.

Multiplexing with select().

Memory Mapping.

Page Alignment.

Establishing Memory Mappings.

Unmapping Regions.

Syncing Memory Regions to Disk.

Locking Memory Regions.

File Locking.

Lock Files.

Record Locking.

Mandatory Locks.

Scatter/Gather Reads and Writes.

Signal Processing.

Signal Concepts.

Simple Signals.

POSIX Signals.

Signals and System Calls.

The Linux (and POSIX) Signal API.

Sending Signals.

Using sigset_t.

Catching Signals.

Manipulating a Process's Signal Mask.

Finding the Set of Pending Signals.

Waiting for Signals.

Available Signals.

Writing Signal Handlers.

Reopening Log Files.

Job Control.

Job Control Basics.

Restarting Processes.

Stopping Processes.

Handling Job Control Signals.

Job Control in ladsh.

Terminals and Pseudo Terminals.

tty Operations.

Controlling Terminals.

termios Overview.

termios Examples.

Passwords.

Serial Communications.

termios Debugging.

termios Reference.

Functions.

Window Sizes.

Flags.

Input Flags.

Output Flags.

Control Flags.

Control Characters.

Local Flags.

Controlling read().

Pseudo ttys.

Opening Pseudo ttys.

Pseudo tty Example.

Networking with Sockets.

Protocol Support.

Nice Networking.

Real Networking.

Making Reality Play Nice.

Addresses.

Utility Functions.

Basic Socket Operations.

Creating a Socket.

Establishing Connections.

Binding an Address to a Socket.

Waiting for Connections.

Connecting to a Server.

UNIX Domain Sockets.

UNIX Domain Addresses.

Waiting for a Connection.

Connecting to a Server.

Running the UNIX Domain Examples.

Unnamed UNIX Domain Sockets.

Passing File Descriptors.

Networking Machines with TCP/IP.

Byte Ordering.

IPv4 Addressing.

IP Socket Addresses.

Manipulating IP Addresses.

Using Hostnames.

Host Information Lookup Example.

Looking Up Port Numbers.

Listening for TCP Connections.

TCP Client Applications.

Socket Errors.

Time.

Telling Time and Dates.

Representing Time.

Converting, Formatting, and Parsing Times.

The Limits of Time.

Using Timers.

Sleeping.

Interval Timers.

Random Numbers.

Pseudo-Random Numbers.

Cryptography and Random Numbers.

Programming Virtual Consoles.

Getting Started.

Beeping.

Determining Whether the Terminal Is a VC.

Finding the Current VC.

Managing VC Switching.

Example: The open Command.

The Linux Console.

Capability Databases.

Glyphs, Characters, and Maps.

Linux Console Capabilities.

Control Characters.

Escape Sequences.

Testing Sequences.

Complex Escape Sequences.

Direct Screen Writing.

IV. DEVELOPMENT LIBRARIES.

String Matching.

Globbing Arbitrary Strings.

Regular Expressions.

Terminal Handling with S-Lang.

Input Handling.

Initializing S-Lang Input Handling.

Restoring the Terminal State.

Reading Characters from the Terminal.

Checking for Input with SLang_input_pending().

Output Handling.

Initializing Screen Management.

Updating the Display.

Moving the Cursor.

Finishing Screen Management.

Skeleton Screen Management.

Switching Character Sets.

Writing to the Screen.

Drawing Lines and Boxes.

Using Color.

The Database Library.

Overview.

Basic Operations.

Opening a db File.

Closing a Database.

Obtaining the File Descriptor.

Syncing the Database.

Reading Records.

Reading Records Sequentially.

Reading a Particular Record.

Modifying the Database.

Adding Records.

Removing Records.

Example.

Parsing Command-Line Options.

Basic popt Usage.

The Option Table.

Creating a Context.

Parsing the Command Line.

Leftover Arguments.

Error Handling.

Option Aliasing.

Specifying Aliases.

Enabling Aliases.

Parsing Argument Strings.

Handling Extra Arguments.

Sample Application.

Dynamic Loading at Run Time.

The dl Interface.

Example.

Names and the User Databases.

ID-to-Name Translation.

Example: The id Command.

Modifying the System Databases.

Pluggable Authentication Modules.

Password Database Library.

Appendices.
Direct Access to I/O Ports.

Almost Portable I/O Port Access.

Direct I/O Port Access.

The Safe Way.

The Dangerous Way.

ladsh Source Code.
The GNU Licenses.

The GNU General Public License.

The GNU Library General Public License.

Glossary.
Bibliography.
Index. 0201308215T04062001

Preface

We wrote this book for experienced (or not-so-experienced, but eager-to-learn) programmers who want to develop Linux software or to port software from other platforms to Linux. This is the book we wish we had when we were learning to program for Linux, and the book we now keep on our desks for reference. By the time we wrote our first three chapters, we were already using the drafts as reference material while we worked.

Linux is designed to be similar to Unix. This book gives you a good background in Unix programming basics and style. Linux is not fundamentally different from Unix--only different enough to repeatedly trip up a programmer who relies only on a Unix programming reference that ignores Linux. This book, therefore, is very much a Unix programming guide that is written from a Linux viewpoint.

Linux also has unique extensions, such as its direct screen access capabilities (see Chapter 20), and it has features that are used more often on it than on other systems, such as the S-Lang library (see Chapter 22). This book covers many of those extensions and features so that you can write programs that truly take advantage of Linux.

  • If you are a C programmer, but you know neither Unix nor Linux, reading this book cover-to-cover and working with the examples should put you well on the road to being a competent Linux programmer. With the aid of other, system-specific documentation, you should find the transition to any version of Unix easy.
  • If you are already a proficient Unix programmer, you will find that this book makes your transition to Linux easier. We have tried very hard to make it easy for you to find precisely the information you need to know. We also carefully and clearly cover topics that sometimes trip up even experienced Unix programmers, such as process and session groups, job control, and tty handling.
  • If you are already a Linux programmer, this book covers confusing topics clearly and will make many of your programming tasks easier. Nearly every chapter will stand alone for you, because you already possess the minimal knowledge of Linux on which they are based. No matter how experienced you are, you will find material here that you will appreciate having at your elbow.
This book is different from usual Unix programming texts because it is unabashedly specific to a particular operating system. We have no need to confuse newcomers by saying BSD does this this way, SVR4 does it another, HPUX has its own way of handling it, and SGI also has its way. We'll cover each of these and let you sort it all out. We know from our own experience that once you learn how to program well for any Unix-like system, the others are easy to learn.

This book does not cover all the details of Linux programming. For example, it does not cover programming the X Window System, because such programming is the same on any Linux or Unix platform. Similarly, it does not explain the basic interface specified by ANSI C--other books do that quite well. Without extraordinary verbosity, we cover the information you need to know to go from being a C programmer for another system, such as DOS, Windows, or Macintosh, to being a C programmer for Linux. We do not cover the wealth of other programming languages available for Linux, and we do not cover the graphical programming libraries that are identical no matter what supported system you are using. Instead, we point you to books that specialize in those areas.

Linux Application Development is written in four parts.

  • The first part introduces you to Linux--the operating system, license terms, documentation, and milieu.
  • The second part covers the most important facets of the development environment--the compilers, linker and loader, and some debugging tools that are not widely used on other platforms.
  • The third part is the heart of the book--it describes the interface to the kernel and to the system libraries, which are primarily meant as an interface to the kernel. Only the final three chapters of this section are very Linux-specific; most of this section covers general Unix programming from a Linux perspective.
  • The fourth part rounds out your knowledge--it includes descriptions of some important libraries that provide interfaces that are more independent of the kernel. These libraries are, properly speaking, not Linux-specific, but several are used more often on Linux systems than on other systems.
If you are already familiar with Linux or Unix programming, you will be able to read the chapters in this book in any order. Do not feel compelled to read chapters that do not interest you. If you are not familiar with either Linux or Unix, most of the chapters will stand alone, but you will probably want to read Chapters 1, 2, 4, 5, 8, 9, 10, and 11 first, as they will give you most of what you need to know to read the other chapters. In particular, Chapters 9, 10, and 11 form the core of the Unix and Linux programming model.

The following books, although they may overlap a little here and there, mostly complement this book by being simpler, more advanced, or on related topics.

  • The C Programming Language, second edition Kernighan, 1998 concisely teaches ANSI standard C programming, with scant reference to the operating system. It recommends that readers have either some programming knowledge or ''access to a more knowledgeable colleague.''
  • Practical C Programming Oualline, 1993 teaches C programming and style in a step-by-step, easy-to-follow manner that is designed for people with no prior programming experience.
  • Programming with GNU Software Loukides, 1997 is an introduction to the GNU programming environment, including chapters on running the C compiler, the debugger, the make utility, and the RCS source code control system.
  • Advanced Programming in the UNIX Environment Stevens, 1992 covers most important Unix and Unix-like systems, although it predates Linux. It covers similar material to the final two parts of Linux Application Development: system calls and shared libraries. It also provides many examples and explains the difference between various Unix versions.
  • UNIX Network Programming Stevens, 1990 thoroughly covers network programming, including legacy types of networking that are not available on Linux, at least as we write this. While reading this book, stick to the Berkeley socket interface (see Chapter 16) to maintain maximum portability. This book may be useful if you need to make a few slight changes to port your Linux network program to some brand of Unix.
See the bibliography on page 513 for an extensive list of related titles.

All the source code in this book comes from working examples that we have tested while writing. All of the source code in this book is available in electronic format at ftp://ftp.awl.com/cseng/books/lad/src/. In the interest of clarity, some short source code segments check only for likely errors that document how the system works rather than check for all possible errors. However, in the full programs in the book and on our Web and FTP sites, we have made an attempt (we are not perfect) to check for all reasonable errors.

This book will teach you which functions to use and how they fit together; we encourage you to learn also how to use the reference documentation (Chapter 3 discusses how to find information on Linux-related topics), the great majority of which was included with your system.

We welcome your comments sent to lad-comments@awl.com We will read your comments, although we cannot promise to respond to them individually.

Linux is a rapidly developing operating s

Bibliography

Click below for Bibliography related to this title:
Bibliography

Updates

Errata

Click below for Errata related to this title:
Errata

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