Example: biology

Advanced Linux Programming - Esplins

AdvancedLinuxProgrammingContents At a GlanceIAdvanced unix Programmingwith Linux1 Getting Started32 Writing Good GNU/LinuxSoftware173 Processes454 Threads615 Interprocess Communication95 IIMastering Linux6 Devices1297 The /procFile System1478 Linux System Calls1679 Inline Assembly Code18910 Security19711A Sample GNU/ Linux Application219 IIIA ppendixesAOther Development Tools259 BLow-Level I/O281 CTable of Signals301 DOnline Resources303 EOpen Publication License Version General Public License30900 0430 FM 5/22/01 2:32 PM Page i00 0430 FM 5/22/01 2:32 PM Page iiAdvanced LinuxProgramming201 West 103rd Street, Indianapolis, Indiana 46290An Imprint of Pearson EducationBoston Indianapolis London Munich New York San Francisco Mark Mitchell, Jeffrey Oldham,and Alex 0430 FM 5/22/01 2:32 PM Page iiiPublisherDavid DwyerAssociate PublisherAl ValvanoExecutive EditorStephanie WallManaging EditorGina BrownAcquisitions EditorAnn QuinnDevelopment EditorLaura LoveallProduct MarketingManagerStephanie LaytonPublicity ManagerSusan PetroProject EditorCaroline WiseCopy EditorKrista HansingSenior IndexerCheryl LenserManufacturingCoordinatorJim ConwayBook DesignerLouisa KlucznikCover DesignerBrainstorm Design, ProductionAren HowellProofreaderDebra NeelCompositionAmy ParkerA

Advanced Linux Programming Contents At a Glance I Advanced UNIX Programming with Linux 1 Getting Started 3 2 Writing Good GNU/Linux Software 17 3 Processes 45 4 Threads 61 5 Interprocess Communication95 II Mastering Linux 6 Devices 129 7 The /proc File System 147 8 Linux System Calls 167 9 Inline Assembly Code 189 10 Security 197 11 A Sample GNU/Linux

Tags:

  Linux, Programming, Unix, Advanced, Advanced linux programming, Advanced unix programming

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Advanced Linux Programming - Esplins

1 AdvancedLinuxProgrammingContents At a GlanceIAdvanced unix Programmingwith Linux1 Getting Started32 Writing Good GNU/LinuxSoftware173 Processes454 Threads615 Interprocess Communication95 IIMastering Linux6 Devices1297 The /procFile System1478 Linux System Calls1679 Inline Assembly Code18910 Security19711A Sample GNU/ Linux Application219 IIIA ppendixesAOther Development Tools259 BLow-Level I/O281 CTable of Signals301 DOnline Resources303 EOpen Publication License Version General Public License30900 0430 FM 5/22/01 2:32 PM Page i00 0430 FM 5/22/01 2:32 PM Page iiAdvanced LinuxProgramming201 West 103rd Street, Indianapolis, Indiana 46290An Imprint of Pearson EducationBoston Indianapolis London Munich New York San Francisco Mark Mitchell, Jeffrey Oldham,and Alex 0430 FM 5/22/01 2:32 PM Page iiiPublisherDavid DwyerAssociate PublisherAl ValvanoExecutive EditorStephanie WallManaging EditorGina BrownAcquisitions EditorAnn QuinnDevelopment EditorLaura LoveallProduct MarketingManagerStephanie LaytonPublicity ManagerSusan PetroProject EditorCaroline WiseCopy EditorKrista HansingSenior IndexerCheryl LenserManufacturingCoordinatorJim ConwayBook DesignerLouisa KlucznikCover DesignerBrainstorm Design, ProductionAren HowellProofreaderDebra NeelCompositionAmy ParkerAdvanced Linux ProgrammingCopyright 2001 by New Riders PublishingFIRST EDITION: June, 2001 All rights reserved.

2 No part of this book may be reproducedor transmitted in any form or by any means, electronic ormechanical, including photocopying, recording, or by anyinformation storage and retrieval system, without writtenpermission from the publisher, except for the inclusion ofbrief quotations in a Standard Book Number: 0-7357-1043-0 Library of Congress Catalog Card Number:00-10534305 04 03 02 01 7 6 5 4 3 2 1 Interpretation of the printing code:The rightmost double-digit number is the year of the book s printing; the right-most single-digit number is the number of the book sprinting. For example, the printing code 01-1 shows that thefirst printing of the book occurred in in Bembo and MCPdigital by New in the United States of terms mentioned in this book that are known to betrademarks or service marks have been appropriately capital-ized. New Riders Publishing cannot attest to the accuracy ofthis information.

3 Use of a term in this book should not beregarded as affecting the validity of any trademark or is a trademark of Adobe Systems, is a trademark of Linus and DisclaimerThis book is designed to provide information aboutAdvanced Linux Programming . Every effort has been made tomake this book as complete and as accurate as possible, butno warranty or fitness is information is provided on an as-is authorsand New Riders Publishing shall have neither liability norresponsibility to any person or entity with respect to any lossor damages arising from the information contained in thisbook or from the use of the discs or programs that mayaccompany 0430 FM 5/22/01 2:32 PM Page iv00 0430 FM 5/22/01 2:32 PM Page vTable of ContentsI Advanced unix Programmingwith Linux 11 Getting Started Editing with Emacs Compiling with GCC Automating the Process with GNU Make Debugging with GNU Debugger (GDB) Finding More Information 132 Writing Good GNU/ Linux Software Interaction With the ExecutionEnvironment Coding Defensively Writing and Using Libraries 363 Processes Looking at Processes Creating Processes Signals Process Termination 554 Threads Thread Creation Thread Cancellation Thread-Specific Data Synchronization and Critical Sections GNU/ Linux Thread Implementation Processes 9400 0430 FM 5/22/01 2.

4 32 PM Page vi5 Interprocess Communication Shared Memory Processes Semaphores Mapped Memory Pipes Sockets 116II Mastering Linux 1276 Devices Device Types Device Numbers Device Entries Hardware Devices Special Devices PTYs The /proc File System Extracting Information from Process Entries Hardware Information Kernel Information Drives, Mounts, and File Systems System Statistics 1658 Linux System Calls Using :Testing File Permissions : Locks and Other File Operations fdatasync: Flushing Disk Buffers setrlimit: Resource Limits : Process Statistics :Wall-Clock Time 176viiContents00 0430 FM 5/22/01 2:32 PM Page The mlockFamily: Locking PhysicalMemory : Setting Memory Permissions : High-Precision Sleeping : Reading Symbolic Links : Fast Data Transfers : Setting Interval Timers : Obtaining System Statistics Inline Assembly Code When to Use Assembly Code Simple Inline Assembly Extended Assembly Syntax Example Optimization Issues Maintenance and Portability Issues 19610 Security Users and Groups Process User IDs and Process Group IDs File System Permissions Real and Effective IDs Authenticating Users More Security Holes 21111 A Sample GNU/ Linux Application Overview Implementation Modules Using the Server Finishing Up 255viiiContents00 0430 FM 5/22/01 2.

5 32 PM Page viiiIII Appendixes 257A Other Development Tools Static Program Analysis Finding Dynamic Memory Errors Profiling 269B Low-Level I/O Reading and Writing Data Vector Reads and Writes Relation to Standard C Library I/OFunctions Other File Operations Reading Directory Contents 296C Table of Signals 301D Online Resources General Information Information About GNU/ Linux Software Other Sites 304E Open Publication License Version 305I. Requirement on Both Unmodified andModified Versions 305II. Copyright 306 III. Scope of License 306IV. Requirements on Modified Works 306V. Good-Practice Recommendations 306VI. License Options 307 Open Publication Policy Appendix 307ixContents00 0430 FM 5/22/01 3:18 PM Page ixF GNU General Public License 309 Preamble 309 Terms and Conditions for Copying,Distribution and Modification 310 End of Terms and Conditions 315 How to Apply These Terms to Your NewPrograms 315 Index 317xContents00 0430 FM 5/22/01 2:32 PM Page x00 0430 FM 5/22/01 2.

6 32 PM Page xiTable of Program (C source file), (C++ source file), (header file), (argc and argv parameters), (getopt_long function), (printing execution environment), (network client program), (mkstemp function), (resource allocation during errorchecking), (library contents), (program with library functions), (libtiff library), (printing process IDs), (system function), (fork function), (fork and exec functions), (signal handlers), (zombie processes), (cleaning up child processes), (creating threads), thread-create2 (creating two threads), (revised main function), (prime number computation in athread), (creating detached threads), (critical sections), (thread-specific data), (cleanup handlers), (C++ thread cleanup), (thread race conditions), (mutexes), (semaphores), (condition variables), 8700 0430 FM 5/22/01 2.

7 32 PM Page (condition variables), thread-pid (printing thread process IDs), (shared memory), (semaphore allocation anddeallocation), (semaphore initialization), (semaphore wait and post operations), (mapped memory), (mapped memory), (parent-child process communication), (output redirection), (popen command), (local sockets), (local sockets), (Internet-domain sockets), (random number generation), (ioctl example), (cpu clock speed from/proc/cpuinfo), (process ID from /proc/self), (printing process argumentlists), (process environment), (program executable path), (opening files), (system uptime and idle time), (file access permissions), (write locks), (data buffer flushing), (resource limits), (process statistics), 176xiiiProgram Listings00 0430 FM 5/22/01 2.

8 32 PM Page (date/time printing), (memory access), (high-precision sleep), (symbolic links), (sendfile system call), (interal timers), (system statistics), print-uname (version number and hardware information), (bit position with loop), (bit position with bsrl), (printing user and group IDs), (viewing file permissions withstat system call), (setuid programs), (PAM example), (temporary file creation), (word search), (function and variable declarations), (utility functions), (loading server modules), (server implementation), (main server program), (show wall-clock time), (GNU/ Linux distribution information), (free disk space information), (summarizing runningprocesses), Makefile (Makefile for sample applicationprogram), 252xivProgram Listings00 0430 FM 5/22/01 2:32 PM Page (Hello World), (dynamic memory allocation), (main calculator program), (unary number implementation), (unary number stack), (header file for calculator program), (create a new file), (append a timestamp), (write all buffered data), (print a hexadecimal file dump), (creating large files), (reading files into buffers), (writev function), (printing directory listings), 297xvProgram Listings00 0430 FM 5/22/01 2:32 PM Page xvxviAbout the AuthorsMark Mitchellreceived a bachelor of arts degree in computer science from Harvard in 1994 and a master of science degree fromStanford in 1999.

9 His research interests centered on computationalcomplexity and computer security. Mark has participated substantiallyin the development of the GNU Compiler Collection, and he has astrong interest in developing quality Oldhamreceived a bachelor of arts degree in computer science from Rice University in 1991. After working at the Center forResearch on Parallel Computation, he obtained a doctor of philoso-phy degree from Stanford in 2000. His research interests center onalgorithm engineering, concentrating on flow and other combinator-ial algorithms. He works on GCC and scientific computing Samuelgraduated from Harvard in 1995 with a degree inphysics. He worked as a software engineer at BBN before returningto study physics at Caltech and the Stanford Linear AcceleratorCenter. Alex administers the Software Carpentry project and workson various other projects, such as optimizations in and Alex founded CodeSourcery LLCtogether in joined the company in 2000.

10 CodeSourcery s mission is toprovide development tools for GNU/ Linux and other operating systems; to make the GNU tool chain a commercial-quality,standards-conforming development tool set; and to provide generalconsulting and engineering services. CodeSourcery s Web site 0430 FM 5/22/01 2:32 PM Page xvixviiAbout the Technical ReviewersThese reviewers contributed their considerable hands-on expertise to the entire devel-opment process for Advanced Linux Programming . As the book was being written, thesededicated professionals reviewed all the material for technical content, organization,and feedback was critical to ensuring that Advanced Linux Programmingfitsour reader s need for the highest quality technical Beckerhas many degrees, all in theatre. He presently works as anonline producer for , the online component of the SCI FIchannel, in New York City.


Related search queries