Table Of Content01_776130 ffirs.qxp 2/2/07 10:13 PM Page iii
Professional
Linux® Programming
Jon Masters
Richard Blum
01_776130 ffirs.qxp 2/2/07 10:13 PM Page ii
01_776130 ffirs.qxp 2/2/07 10:13 PM Page i
Professional
Linux® Programming
01_776130 ffirs.qxp 2/2/07 10:13 PM Page ii
01_776130 ffirs.qxp 2/2/07 10:13 PM Page iii
Professional
Linux® Programming
Jon Masters
Richard Blum
01_776130 ffirs.qxp 2/2/07 10:13 PM Page iv
Professional Linux® Programming
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data:
Masters, Jon, 1981-
Professional Linux programming / Jon Masters, Richard Blum.
p. cm.
Includes index.
ISBN: 978-0-471-77613-0 (paper/website)
1. Linux. 2. Operating systems (Computers) I. Blum, Richard, 1962- II. Title.
QA76.76.O63M37153 2007
005.4’32—dc22
2006102202
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any
means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections
107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or
authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood
Drive, Danvers, MA01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be
addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317)
572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REP-
RESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACYOR COMPLETENESS OF THE CON-
TENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT
LIMITATION WARRANTIES OF FITNESS FOR APARTICULAR PURPOSE. NO WARRANTYMAYBE CREATED
OR EXTENDED BYSALES OR PROMOTIONALMATERIALS. THE ADVICE AND STRATEGIES CONTAINED
HEREIN MAYNOT BE SUITABLE FOR EVERYSITUATION. THIS WORK IS SOLD WITH THE UNDERSTAND-
ING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PRO-
FESSIONALSERVICES. IF PROFESSIONALASSISTANCE IS REQUIRED, THE SERVICES OF ACOMPETENT
PROFESSIONALPERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALLBE
LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS
REFERRED TO IN THIS WORK AS ACITATION AND/OR APOTENTIALSOURCE OF FURTHER INFORMA-
TION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE
ORGANIZATION OR WEBSITE MAYPROVIDE OR RECOMMENDATIONS IT MAYMAKE. FURTHER, READ-
ERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAYHAVE CHANGED OR
DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services please contact our Customer Care Department within
the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks:Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are
trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other
countries, and may not be used without written permission. Linux is a registered trademark of Linus Torvalds. All
other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any
product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be
available in electronic books.
01_776130 ffirs.qxp 2/2/07 10:13 PM Page v
For Karin, whom I love very much.—Jon Masters
To my wife Barbara.—Richard Blum
01_776130 ffirs.qxp 2/2/07 10:13 PM Page vi
About the Authors
Jon Mastersis a 25-year-old British-born Linux kernel engineer, embedded systems specialist, and
author who lives and works in the United States for Red Hat. Jon made UK history by becoming one of
the youngest University students the country had ever seen, at the tender age of just 13. Having been
through college twice by the time his peers were completing their first time around, and having been
published over 100 times in a wide range of technical magazines, journals and books, Jon went on to
work for a variety of multinational technology companies. He has worked extensively in the field of
Embedded Systems, Enterprise Linux and Scientific instrumentation and has helped design anything
and everything from Set Top Boxes to future NMR (MRI) imaging platforms.
When not working on Enterprise Linux software for Red Hat, Jon likes to drink tea on Boston Common
and read the collective works of Thomas Paine and other great American Revolutionaries of a bygone
age. He dreams of a time when the world was driven not by electrons, but by wooden sailing ships and
a universal struggle for the birth of modern nations. He plays the violin, and occasionally sings in choral
ensembles, for which he has won several awards. For relaxation, Jon enjoys engaging in a little rock
climbing. He lives in Cambridge, Massachusetts, just across the river Charles from historic Boston, and
enjoys every minute of it.
Jon has extensive experience in speaking about and training people to use a wide variety of Linux
technologies and enjoys actively participating in many Linux User Groups the world over.
Richard Blumhas worked for over 18 years for a large U.S. government organization as a network and
systems administrator. During this time he has had plenty of opportunities to work with Microsoft,
Novell, and of course, UNIX and Linux servers. He has written applications and utilities using C, C++,
Java, C#, Visual Basic, and shell script.
Rich has a Bachelors of Science degree in Electrical Engineering, and a Masters of Science degree in
Management, specializing in Management Information Systems, from Purdue University. He is the author
of several books, including “sendmail for Linux” (2000, Sams publishing), “Running qmail” (2000, Sams
publishing), “Postfix” (2001, Sams Publishing), “Open Source E-mail Security” (2001, Sams Publishing),
“C#Network Programming” (2002, Sybex), “Network Performance Open SourceToolkit” (2003, John Wiley &
Sons), and “Professional Assembly Language Programming” (2005, Wrox).
When he is not being a computer nerd, Rich plays electric bass for the church worship and praise band,
and enjoys spending time with his wife Barbara, and daughters Katie Jane and Jessica.
01_776130 ffirs.qxp 2/2/07 10:13 PM Page vii
Credits
Contributing Writers Graphics and Production Specialists
Christopher Aillon Carrie A. Foster
Katherine and David Goodwin Jennifer Mayberry
Matthew Walton Barbara Moore
Alicia B. South
Acquisitions Editor
Kit Kemper Quality Control Technicians
Cynthia Fields
Development Editor John Greenough
Howard A. Jones
Project Coordinator
Production Editor Adrienne Martinez
Eric Charbonneau
Proofreading and Indexing
Copy Editor Techbooks
Foxxe Editorial
Anniversary Logo Design
Editorial Manager Richard Pacifico
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Joseph B. Wikert
01_776130 ffirs.qxp 2/2/07 10:13 PM Page viii