ebook img

System Programming with C and Unix PDF

392 Pages·2009·2.15 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview System Programming with C and Unix

System Programming with C and Unix This page intentionally left blank System Programming with C and Unix Adam Hoover Clemson University ADDISON-WESLEY Boston SanFrancisco NewYork London Toronto Sydney Tokyo Singapore Madrid MexicoCity Munich Paris CapeTown HongKong Montreal Editor-in-Chief MichaelHirsch AcquisitionsEditor MattGoldstein EditorialAssistant SarahMilmore ManagingEditor JeffreyHolcomb ProductionSupervisor HeatherMcNally ArtDirector LindaKnowles CoverDesigner ElenaSidorova CoverImage AbleStock/IndexOpen OnlineProductManager BethanyTidd MarketingManager ErinDavis MarketingCoordinator KathrynFerranti SeniorManufacturingBuyer CarolMelville ProductionCoordination,TextDesign,andComposition WindfallSoftware Copyediting YonieOverton Proofreading RickCamp Indexing TedLaux Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsareclaimedastrademarks. Wherethosedesignationsappearinthisbook,andAddison-Wesleywasawareofatrademarkclaim,thedesignations havebeenprintedininitialcapsorallcaps. Theprogramsandapplicationspresentedinthisbookhavebeenincludedfortheirinstructionalvalue.Theyhavebeen testedwithcare, butarenotguaranteedforanyparticularpurpose.Thepublisherdoesnotofferanywarrantiesor representations,nordoesitacceptanyliabilitieswithrespecttotheprogramsorapplications. ThisinteriorofthisbookwascomposedinMinionandStoneSansusingtheZzTEXtypesettingsystem. LibraryofCongressCataloging-in-PublicationData Hoover,Adam. SystemprogrammingwithCandUnix/AdamHoover.—1sted. p. cm. Includesindex. ISBN-13:978-0-13-606712-2(alk.paper) ISBN-10:0-13-606712-3 1.Systemsprogramming(Computerscience). I.Title. QA76.66.H662009 (cid:2) 005.42—dc22 2008052700 Copyright©2010PearsonEducation,Inc.Allrightsreserved.Nopartofthispublicationmaybereproduced,stored inaretrievalsystem,ortransmitted,inanyformorbyanymeans,electronic,mechanical,photocopying,recording,or otherwise,withoutthepriorwrittenpermissionofthepublisher.PrintedintheUnitedStatesofAmerica.Forinformation onobtainingpermissionforuseofmaterialinthiswork,pleasesubmitawrittenrequesttoPearsonEducation,Inc.,Rights andContractsDepartment,501BoylstonStreet,Suite900,Boston,MA02116,faxyourrequestto(617)671-3447,or e-mailathttp://www.pearsoned.com/legal/permissions.htm. ISBN-13:978-0-13-606712-2 ISBN-10:0-13-606712-3 www.pearsonhighered.com 1 2 3 4 5 6 7 8 9 10—DOH—13 12 11 10 09 Contents Preface ix 1 Introduction 1 1.1 WhatisSystemProgramming? 1 1.2 TheThreeTools 5 1.3 HowtoDebug 20 1.4 ProgramDevelopment 31 1.5 ReviewofC 35 QuestionsandExercises 41 2 Bits, Bytes, and Data Types 45 2.1 BitModels 45 2.2 BitwiseOperations 57 2.3 MemoryMap 65 QuestionsandExercises 68 3 Arrays and Strings 73 3.1 Arrays 74 3.2 Strings 79 3.3 StringLibraryFunctions 83 3.4 CommandLineArguments 92 QuestionsandExercises 94 vi Contents 4 Pointers and Structures 103 4.1 Pointers 103 4.2 UsingPointers 108 4.3 Structures 118 4.4 UsingStructures 121 QuestionsandExercises 127 5 Input/Output 135 5.1 Streams 136 5.2 Buffers 143 5.3 Pipes 145 5.4 Files 153 5.5 Devices 161 QuestionsandExercises 164 6 Program Management 171 6.1 ProgramBuilding 172 6.2 CodeOrganization 185 6.3 ProgramDistributionMethods 201 QuestionsandExercises 204 7 System Calls 213 7.1 FamiliesofOperations 214 7.2 LibrariesandSystemCalls 215 7.3 ProcessSystemCalls 217 7.4 SignalSystemCalls 229 7.5 SocketSystemCalls 236 QuestionsandExercises 251 8 Libraries 255 8.1 UsingaLibrary 256 8.2 PurposeofLibraries 261 8.3 TheCStandardLibrary 263 8.4 TheCursesLibrary 265 8.5 TheXLibrary 275 8.6 MakingaLibrary 288 8.7 LibraryPitfalls 291 QuestionsandExercises 292 Contents vii 9 Scripting Languages 299 9.1 UsingScriptingLanguages 301 9.2 ShellScripting 305 9.3 Perl 320 9.4 MATLAB 333 9.5 Discussion 347 QuestionsandExercises 348 A ASCII Table 351 B Common Shell Commands 355 C System Programs 357 Index 361 This page intentionally left blank Preface T he goals of this book are to teach the reader about system programming tools and resources, and to make the reader a better programmer. Con- sider the following questions: What is a library, and how is it used? What is a debugger,andhowdoesithelpduringprogramdevelopment?Whatarescript- inglanguages,andforwhatsortsofprogrammingworkaretheyuseful?Whatare systemcalls,andwhenaretheyuseful?Whywouldsomeoneeverwanttoruna programfromashellinsteadofusingagraphicaluserinterface?Thesequestions areaddressedbythestudyofsystemprogramming asoutlinedinthistextbook. In addition to the concepts of system programming, this text explores the lower-level data types: bits and bytes, bit operations, arrays, strings, structures, andpointers.Thismaterialiscoveredwithanemphasisonmemoryandunder- standing how and why these different data types are used. Understanding code at the memory level can help clarify even the most difficult programming con- cepts. It is common for a student to be less comfortable with these topics than withotherbasicprogrammingconcepts,suchasloopsandconditionals.Cover- ageofthelower-leveldatatypesisintendedtoreinforceanintroductorycoverage obtainedpreviously.Thegoalistoadvancetheprogrammingskillofthereader fromtheintermediateleveltotheadvancedlevel,tothepointwherethesetopics arewellandcomfortablyused.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.