Home > Store

Linux Programming by Example: The Fundamentals

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

Linux Programming by Example: The Fundamentals

Book

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

About

Features

The perfect introduction to Linux programming fundamentals for developers new to Linux--ideal for Windows programmers making the switch!

° An example-driven introduction to the core Linux programming interfaces that EVERY Linux developer needs to master.

° Examples are "real-world," not canned, taken from the ACTUAL source code to popular GNU Linux programs.

° Written by the best-selling author of UNIX in a Nutshell and other popular O'Reilly books.

Description

  • Copyright 2004
  • Dimensions: 7" x 9-1/4"
  • Pages: 728
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-142964-7
  • ISBN-13: 978-0-13-142964-2

Linux Programming by Example introduces new Linux programmers to the core Linux programming interfaces in a gradual, consistent fashion, progressing intuitively from the basic to the more complex. It covers I/O, file metainformation, users and groups, processes, basic interprocess communication (pipes), general purpose APIs, signals, internationalization, and ends with a chapter on debugging Linux programs. Programmers know that the best way to learn about programming is to study well-written programs. This book teaches the fundamental Linux programming interfaces, those that form the core of any significant program, by presenting example code from real-world production programs that Linux users use every day. By looking at concrete programs, its possible not only to see how to use the Linux programming interfaces, but also to examine the real-world issues (performance, portability, robustness) that arise in writing Linux software. This book is the FIRST in a new series of books featuring Arnold Robbins as Series Editor. The books will all be branded "Linux Programming by Example" and cover programming topics for the new Linux programmer and Windows programmers making the switch.

Downloads

Source Code

Untitled Document Download the source code related to this title.

Extras

Links

To facilitate your work with the "Suggested Reading" sections of the text, we are providing links to select books and online resources referenced throughout the book.

From Chapter 1

  • The C Programming Language, 2nd edition , by Brian W. Kernighan and Dennis M. Ritchie. Prentice-Hall, Englewood Cliffs, New Jersey, USA, 1989. ISBN: 0-13-110370-9. This is the "bible" for C, covering the 1990 version of Standard C. It is a rather dense book, with lots of information packed into a startlingly small number of pages. You may need to read it through more than once; doing so is well worth the trouble.
  • C, A Reference Manual, 5th edition, by Samuel P. Harbison III and Guy L. Steele, Jr. Prentice-Hall, Upper Saddle River, New Jersey, USA, 2002. ISBN: 0-13-089592-X. This book is also a classic. It covers Original C as well as the 1990 and 1999 standards. Because it is current, it makes a valuable companion to The C Programming Language. It covers many important items, such as internationalization- related types and library functions, that aren't in the Kernighan and Ritchie book.
  • Notes on Programming in C , by Rob Pike, February 21, 1989. Available on the Web from many sites. Perhaps the most widely cited location is http://www.lysator.liu.se/c/pikestyle.html . (Many other useful articles are available from one level up: http://www.lysator.liu.se/c/ .) Rob Pike worked for many years at the Bell Labs research center where C and Unix were invented and did pioneering development there. His notes distill many years of experience into a "philosophy of clarity in programming" that is well worth reading.
  • The various links at http://www.chris-lott.org/resources/cstyle/ . This site includes Rob Pike's notes and several articles by Henry Spencer. Of particular note is the Recommended C Style and Coding Standards, originally written at the Bell Labs Indian Hill site.

From Chapter 6

  • The Art of Computer Programming Volume 3: Sorting and Searching, 2nd edition , by Donald E. Knuth. Addison-Wesley, Reading Massachusetts, USA, 1998. ISBN: 0-201-89685-0. This book is usually cited as the final word on sorting and searching. Bear in mind that it is considerably denser and harder to read than the Loudon book.
  • The GTK+ project consists of several libraries that work together. GTK+ is the underlying toolkit used by the GNU GNOME Project . At the base of the library hierarchy is Glib, a library of fundamental types and data structures and functions for working with them. Glib includes facilities for all the basic operations we've covered so far in this book, and many more, including linked lists and hash tables. To see the online documentation, start at the GTK+ Documentation Project's web site , click on the "Download" link, and proceed to the online version.

From Chapter 9

  • Advanced Programming in the UNIX Environment, 2nd edition , by W. Richard Stevens and Stephen Rago. Addison-Wesley, Reading Massachusetts, USA, 2004. ISBN: 0-201-43307-9. This book is both complete and thorough, covering elementary and advanced Unix programming. It does an excellent job of covering process groups, sessions, job control, and signals.
  • The Design and Implementation of the 4.4 BSD Operating System , by Marshall Kirk McKusick, Keith Bostic, Michael J. Karels, and John S. Quarterman. Addison-Wesley, Reading, Massachusetts, USA, 1996. ISBN: 0-201-54979-4. This book gives a good overview of the same material, including a discussion of kernel data structures, which can be found in section 4.8 of that book.

From Chapter 11

  • Building Secure Software: How to Avoid Security Problems the Right Way , by John Viega and Gary McGraw. Addison-Wesley, Reading, Massachusetts, USA, 2001. ISBN: 0-201-72152-X. This is a good book on writing secure software and it includes how to deal with setuid issues. It assumes you are familiar with the basic Linux/Unix APIs; by the time you finish reading our book, you should be ready to read it.
  • "Setuid Demystified," by Hao Chen, David Wagner, and Drew Dean. Proceedings of the 11th USENIX Security Symposium, August 5-9, 2002. http://www.cs.berkeley.edu/~daw/papers/setuid-usenix02.pdf . Garfinkel, Spafford, and Schwartz recommend reading this paper "before you even think about writing code that tries to save and restore privileges." We most heartily agree with them.

From Chapter 12

From Chapter 13

  • C: A Reference Manual, 5th edition , by Samuel P. Harbison III and Guy L. Steele, Jr., Prentice-Hall, Upper Saddle River, New Jersey, USA, 2002. ISBN: 0-13-089592-X. We have mentioned this book before. It provides a concise and comprehensible description of the evolution and use of the multibyte and wide-character facilities in the C standard library. This is particularly valuable on modern systems supporting C99 because the library was significantly enhanced for the 1999 C standard.
  • GNU gettext tools, by Ulrich Drepper, Jim Meyering, Francois Pinard, and Bruno Haible. This is the manual for GNU gettext. On a GNU/Linux system, you can see the local copy with 'info gettext'. Or download and print the latest version (from ftp://ftp.gnu.org/gnu/gettext/ ).

From Chapter 15

From Chapter 16

  • The UNIX Programming Environment , by Brian W. Kernighan and Rob Pike. Prentice-Hall, Englewood Cliffs, New Jersey, USA, 1984. ISBN: 0-13-937699-2. This is the classic book on Unix programming, describing the entire gestalt of the Unix environment, from interactive use, to shell programming, to programming with the <stdio.h> functions and the lower-level system calls, to program development with make, yacc, and lex, and documentation with nroff and troff. Although the book shows its age, it is still eminently worth reading, and we highly recommend it.
  • The Art of UNIX Programming , by Eric S. Raymond. Addison-Wesley, Reading, Massachusetts, USA, 2004. ISBN: 0-13-142901-9. This is a higher-level book that focuses on the design issues in Unix programming: how Unix programs work and how to design your own programs to fit comfortably into a Linux/Unix environment. While we don't always agree with much of what the author has to say, the book does have considerable important material and is worth reading.

Sample Content

Online Sample Chapters

Arguments, Options, and the Environment

User-Level Memory Management in Linux Programming

Table of Contents



Preface.

Audience. What You Will Learn. Small Is Beautiful: Unix Programs. Standards. Features and Power: GNU Programs. Chapter Summary. Typographical Conventions. Where To Get Unix and GNU Source Code. Unix Code. GNU Code.



Acknowledgments.


1. Introduction.

The Linux/Unix File Model. The Linux/Unix Process Model. Standard C vs. Original C. Why GNU Programs Are Better. Portability Revisited. Suggested Reading. Summary. Exercises.



2. Arguments, Options, and the Environment

Option and Argument Conventions. Basic Command Line Processing. Option Parsing: getopt() and getopt_long(). The Environment. Summary. Exercises.



3. User-Level Memory Management

Linux/Unix Address Space. Allocating Memory. Summary. Exercises.



4. Files and File I/O.

Introduction. Basic Program Structure. Determining What Went Wrong. Input and Output. Random Access: Moving Around Within A File. Creating Files. Forcing Data to Disk. Setting File Length. Summary. Exercises.



5. Directories and File Metadata.

Directory Contents. Creating and Removing Directories. Reading Directories. File Types and Information. Changing Ownership, Permission, and Modification Times. Summary. Exercises.



6. General Library Interfaces - Part 1

Times and Dates. Sorting and Searching. User and Group Names. Terminals: isatty(). Suggested Reading. Summary. Exercises.



7. Putting It All Together: ls.

V7 ls Options. The V7 ls Code. Summary. Exercises.



8. Filesystems and Directory Walks.

Mounting and Unmounting Filesystems. Filesystem Administration Files. Retrieving Per-filesystem Information. Moving Around In The File Hierarchy. Doing A File Tree Walk: GNU du. Changing The Root Directory: chroot(). Summary. Exercises.



9. Process Management and Pipes.

Process Creation and Management. Process Groups. Basic Interprocess Communication: Pipes and FIFOs. File Descriptor Management. Example: Two Way Pipes In gawk. Suggested Reading. Summary. Exercises.



10. Signals.

Introduction. Signal Actions. Standard C Signals: signal() and raise(). Signal Handlers In Action. The System V Release 3 Signal APIs: sigset() et al. POSIX Signals. Signals For Interprocess Communication. Important Special Purpose Signals. Signals Across fork() and exec(). Summary. Exercises.



11. User and Group ID Numbers and Permissions.

Introduction. Retrieving User and Group Ids. Checking As The Real User: access(). GLIBC Only: Checking As The E_ective User: euidaccess(). Extra Permission Bits For Directories. Setting Real and E_ective Ids. Linux Only: getresuid() and setresuid(). Setuid root: A Security Minefield. Suggested Reading. Summary. Exercises.



12. General Library Interfaces - Part 2.

Stating Assertions: assert(). Low-level Memory: The memXXX() Functions. Temporary Files. Committing Suicide: abort(). Non-local Gotos. Pseudorandom Numbers. Metacharacter Expansions. Regular Expressions. Suggested Reading. Summary. Exercises.



13. Internationalization and Localization.

Locales and the C Library. Dynamic Translation of Program Messages. Can You Spell That For Me Please? Suggested Reading. Summary. Exercises.



14. Extended Interfaces.

Allocating Aligned Memory: posix_memalign() and memalign(). Locking Files. More Precise Times. Advanced Searching With Binary Trees. Summary. Exercises



15. Debugging.

What To Do First? Compiling For Debugging. GDB Basics. Programming For Debugging. Debugging Tools. Software Testing. Debugging Rules. Suggested Reading. Summary. Exercises.



16. Tying It Together - A Project.

Project Description. Suggested Reading.



Appendix A. Teach Yourself Programming in Ten Years.

Why is everyone in such a rush? Teach Yourself Programming in Ten Years. References. Answers. Footnotes.



Appendix B. Caldera Ancient UNIX License.


Appendix C. GNU General Public License.


Preamble.


Terms and Conditions for Copying, Distribution and Modification.


How to Apply These Terms to Your New Programs.


Example Use.


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