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.
- 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.
Source Code
Untitled Document
Download the
source code related to this title.
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
- Programming Pearls, 2nd edition , by Jon Louis Bentley. Addison-Wesley, Reading, Massachusetts, USA, 2000. ISBN: 0-201-65788-0. See also this book's web site at http://www.cs.bell-labs.com/cm/cs/pearls/ . Program design with assertions is one of the fundamental themes in the book.
- 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. Race conditions are only one of many issues to worry about when you are writing secure software. Random numbers are another. This book covers both, among other things. (We mentioned it in the Chapter 11.)
- The Art of Computer Programming: Volume 2: Seminumerical Algorithms, 3rd edition , by Donald E. Knuth. Addison-Wesley, Reading, Massachusetts, USA, 1998. ISBN: 0-201-89684-2. See also the book's web site at http://www-cs-faculty.stanford.edu/~knuth/taocp.html . This is the classic reference on random number generation.
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
- Programming Pearls, 2nd edition , by Jon Louis Bentley. Addison-Wesley, Reading, Massachusetts, USA, 2000. ISBN: 0-201-65788-0. See also this book's web site at http://www.cs.bell-labs.com/cm/cs/pearls/ . Chapter 5 of this book gives a good discussion of unit testing and building test scaffolding.
- The Practice of Programming , by Brian W. Kernighan and Rob Pike. Addison- Wesley, Reading, Massachusetts, USA, 1999. ISBN: 0-201-61585-X.
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.
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.