Professional Linux Programming 1st Edition Jon Masters PDF Download
Professional Linux Programming 1st Edition Jon Masters PDF Download
https://ebookfinal.com/download/professional-linux-
programming-1st-edition-jon-masters/
https://ebookfinal.com/download/linux-system-programming-1st-edition-
robert-love/
https://ebookfinal.com/download/beginning-linux-programming-4th-
edition-neil-matthew/
https://ebookfinal.com/download/beginning-linux-programming-3rd-
edition-neil-matthew/
https://ebookfinal.com/download/linux-programming-by-example-the-
fundamentals-1st-edition-robbins/
Professional Oracle Programming 1st Edition Rick Greenwald
https://ebookfinal.com/download/professional-oracle-programming-1st-
edition-rick-greenwald/
https://ebookfinal.com/download/red-hat-fedora-linux-3-for-
dummies-1st-edition-jon-maddog-hall/
https://ebookfinal.com/download/c-programming-in-linux-2nd-edition-
david-haskins/
https://ebookfinal.com/download/professional-dotnetnuke-module-
programming-mitchel-sellers/
https://ebookfinal.com/download/professional-android-sensor-
programming-1st-edition-greg-milette/
Professional Linux Programming 1st Edition Jon Masters
Digital Instant Download
Author(s): Jon Masters, Richard Blum
ISBN(s): 9780471776130, 0471776130
Edition: 1
File Details: PDF, 13.43 MB
Year: 2007
Language: english
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 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
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REP-
RESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CON-
TENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT
LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED
OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED
HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTAND-
ING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PRO-
FESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT
PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE
LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS
REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMA-
TION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE
ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READ-
ERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE 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
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 Blum has 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 Source Toolkit” (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
Acknowledgments
I sit here writing these acknowledgements on my 25th birthday, having spent many long evenings over
the last year pouring over schedules, planning and even occasionally actually getting some writing
done. When I first undertook to write this book, I could never have fully appreciated the amount of
work it takes to put such a thing together nor the difficulties that would need to be overcome along the
way. I started writing this book living just outside London and finished it less than a year later from my
new home in Cambridge, Massachusetts, having decided to leave the country in the interim. Over the
last year, a lot has changed for me both personally and professionally, but I am supported by a great net-
work of friends and family who have helped make it possible.
First and foremost I would like to thank the team I have worked with at Wiley — Debra, Adaobi, Kit,
Howard and Carol as well as numerous others whose job it is to turn this manuscript into a finished
book. Kit Kemper deserves special thanks for enduring my writing schedule and somehow making that
just about work out in the end, as does Debra Williams-Cauley for believing that this project was a good
idea in the first place. Howard Jones helped to keep me honest by doing an excellent job as my editor.
This book would not exist without the inspiration I received from my good friends (and former bosses)
Malcolm Buckingham and Jamie McKendry at Resonance Instruments (later Oxford Instruments), who
used to moan about the lack of Linux-specific programming books. This book would also not exist with-
out the kind contributions from several good friends of mine — Kat and David Goodwin, Matthew Walton,
and Chris Aillon, thank you. Thanks also to Richard Blum for stepping up and joining the team once it
became apparent to me that I couldn’t hope to finish this in time. You’ve all done a great job and I really
do thank you very much.
I have been helped along the way by my fantastic family — my parents Paula and Charles, my sisters
Hannah Wrigley and Holly, my brother-in-law Joe, and occasional inspiration too from my grandmothers.
I have also benefited from some of the best friends anyone could ask for — there are too many to list every-
one individually, but I would like to specifically mention Hussein Jodiyawalla, Johannes Kling, Ben Swan,
Paul Sladen, Markus Kobler, Tom Hawley, Sidarshan Guru Ratnavellu, Chris and Mad Ball (and Zoe, the
cat), Emma Maule, John and Jan Buckman, Toby Jaffey and Sara, Sven Thorsten-Dietrich, Bill Weinberg,
Daniel James, Joe Casad and Andrew Hutton and Emilie. Special thanks also to all of my friends at Red
Hat, my boss and all the other hard-working people who help to make our company truly the greatest
place to work anywhere in the world. Red Hat really understands what it means to work on Linux, and
I am extremely grateful for having such a cool work environment, which really does encourage involve-
ment in projects such as this one, in the true spirit of the Linux community — thanks, guys, you rock.
Finally, I would like to thank Karin Worley for her friendship, which provided me with ample opportu-
nity for procrastination during the final stages of this project. Karin, I’m not sure I would have completed
it without the new-found sense of happiness that recently entered into my life.
Jon Masters
Cambridge, Massachusetts
01_776130 ffirs.qxp 2/2/07 10:13 PM Page x
Acknowledgments
Many thanks go to the great team of people at Wiley for their outstanding work on this project. Thanks
to Kit Kemper, the Acquisitions Editor, for offering me the opportunity to work on this book. Also
thanks to Howard Jones, the Developmental Editor, for keeping things on track and helping make this
book presentable. I would also like to thank Carole McClendon at Waterside Productions, Inc. for
arranging this opportunity for me, and for helping out in my writing career.
Finally, I would like to thank my parents, Mike and Joyce Blum, for their dedication and support while
raising me, and to my wife Barbara and daughters Katie Jane and Jessica for their love, patience, and
understanding, especially while I’m writing.
Richard Blum
x
02_776130 ftoc.qxp 2/2/07 10:13 PM Page xi
Contents
Acknowledgments ix
Introduction xix
Chapter 2: Toolchains 19
The Linux Development Process 19
Working with Sources 20
Configuring to the Local Environment 21
Building the Sources 22
Components of the GNU Toolchain 23
The GNU Compiler Collection 23
The GNU binutils 34
GNU Make 39
The GNU Debugger 40
02_776130 ftoc.qxp 2/2/07 10:13 PM Page xii
Contents
The Linux Kernel and the GNU Toolchain 44
Inline Assembly 44
Attribute Tags 45
Custom Linker Scripts 45
Cross-Compilation 46
Building the GNU Toolchain 47
Summary 48
Chapter 3: Portability 49
The Need for Portability 50
The Portability of Linux 51
Layers of Abstraction 51
Linux Distributions 52
Building Packages 57
Portable Source Code 70
Internationalization 81
Hardware Portability 88
64-Bit Cleanliness 89
Endian Neutrality 89
Summary 92
xii
02_776130 ftoc.qxp 2/2/07 10:13 PM Page xiii
Contents
Moving Data 133
Datagrams vs. Streams 133
Marking Message Boundaries 137
Using Network Programming Libraries 140
The libCurl Library 140
Using the libCurl Library 141
Summary 147
xiii
02_776130 ftoc.qxp 2/2/07 10:13 PM Page xiv
Contents
Chapter 8: Kernel Interfaces 217
What Is an Interface? 217
Undefined Interfaces 218
External Kernel Interfaces 219
System Calls 219
The Device File Abstraction 224
Kernel Events 238
Ignoring Kernel Protections 239
Internal Kernel Interfaces 243
The Kernel API 243
The kernel ABI 244
Summary 245
xiv
02_776130 ftoc.qxp 2/2/07 10:13 PM Page xv
Contents
Graphical Debugging Tools 299
DDD 299
Eclipse 302
Kernel Debugging 305
Don’t Panic! 306
Making Sense of an oops 307
Using UML for Debugging 309
An Anecdotal Word 312
A Note about In-Kernel Debuggers 313
Summary 313
xv
02_776130 ftoc.qxp 2/2/07 10:13 PM Page xvi
Contents
Chapter 13: Graphics and Audio 361
Linux and Graphics 361
X Windows 362
Open Graphics Library 364
OpenGL Utilities Toolkit 365
Simple Directmedia Layer 365
Writing OpenGL Applications 365
Downloading and Installing 366
Programming Environment 367
Using the GLUT Library 368
Writing SDL Applications 382
Downloading and Installing 382
Programming Environment 383
Using the SDL Library 383
Summary 394
xvi
02_776130 ftoc.qxp 2/2/07 10:13 PM Page xvii
Contents
Optimization Techniques 422
Installing Additional PHP Software 427
Logging 427
Parameter Handling 428
Session Handling 429
Unit Testing 430
Databases and PHP 432
PHP Frameworks 432
The DVD Library 433
Version 1: The Developer’s Nightmare 433
Version 2: Basic Application with DB-Specific Data Layer 434
Version 3: Rewriting the Data Layer, Adding Logging and Exceptions 437
Version 4: Applying a Templating Framework 441
Summary 442
Index 443
GNU 473
xvii
Discovering Diverse Content Through
Random Scribd Documents
THE COURIER.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com