ebook img

thinkos.pdf (PDFy mirror) PDF

1.5 MB·English
by  
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 thinkos.pdf (PDFy mirror)

Think OS: A Brief Introduction to Operating Systems Version0.3 Think OS A Brief Introduction to Operating Systems Version0.3 Allen B. Downey Green Tea Press Needham,Massachusetts Copyright©2014AllenB.Downey. GreenTeaPress 9WashburnAve NeedhamMA02492 Permission is granted to copy, distribute, and/or modify this document under thetermsoftheCreativeCommonsAttribution-NonCommercial3.0UnportedLi- cense,whichisavailableathttp://creativecommons.org/licenses/by-nc/3.0/. The original form of this book is LATEX source code. Compiling this code has the effect of generating a device-independent representation of a textbook, which can beconvertedtootherformatsandprinted. TheLATEXsourceforthisbookisavailablefromhttp://thinkstats2.com. The cover for this book is based on a photo by Paul Friel (http://flickr.com/ people/frielp/),whomadeitavailableundertheCreativeCommonsAttribution license. Theoriginalphotoisathttp://flickr.com/photos/frielp/11999738/. Preface In many computer science programs, Operating Systems is an advanced topic. By the time students take it, they usually know how to program in C,andtheyhaveprobablytakenaclassinComputerArchitecture. Usually thegoaloftheclassistoexposestudentstothedesignandimplementation of operating systems, with the implied assumption that some of them will doresearchinthisarea,orwritepartofanOS. This book is intended for a different audience, and it has different goals. I developeditforaclassatOlinCollegecalledSoftwareSystems. Most students taking this class learned to program in Python, so one of the goals is to help them learn C. For that part of the class, I use Griffiths and Griffiths, Head First C, from O’Reilly Media. This book is meant to complementthatone. Few of my students will ever write an operating system, but many of them will write low-level applications in C, and some of them will work on em- bedded systems. My class includes material from operating systems, net- works,databases,andembeddedsystems,butitemphasizesthetopicspro- grammersneedtoknow. This book does not assume that you have studied Computer Architecture. Aswegoalong,Iwillexplainwhatweneed. Ifthisbookissuccessful,itshouldgiveyouabetterunderstandingofwhat is happening when programs run, and what you can do to make them run betterandfaster. Chapter 1 explains some of the differences between compiled and inter- preted languages, with some insight into how compilers work. Recom- mendedreading: HeadFirstCChapter1. Chapter2explainshowtheoperatingsystemusesprocessestoprotectrun- ningprogramsfrominterferingwitheachother. vi Chapter0. Preface Chapter3explainsvirtualmemoryandaddresstranslation. Recommended reading: HeadFirstCChapter2. Chapter 4 is about file systems and data streams. Recommended reading: HeadFirstCChapter3. Chapter 5 describes how numbers, letters, and other values are encoded, andpresentsthebitwiseoperators. Chapter 6 explains how to use dynamic memory management, and how it works. Recommendedreading: HeadFirstCChapter6. Chapter7isaboutcachingandthememoryhierarchy. Chapter8isaboutmultitaskingandscheduling. Chapter9willbeaboutthreads. Chapter 10 will be about synchronization with POSIX mutexes and condi- tionvariables. A note on this draft Thecurrentversionofthisbookisanearlydraft. WhileIamworkingonthe text,Ihavenotyetincludedthefigures. Sothereareafewplaceswhere,I’m sure,theexplanationwillbegreatlyimprovedwhenthefiguresareready. Where to get the code ThesourcematerialforthisbookandthesupportingcodeareinaGitrepos- itoryat. Contributor List If you have a suggestion or correction, please send email to [email protected]. If I make a change based on your feed- back, I will add you to the contributor list (unless you ask to be omitted). Ifyouincludeatleastpartofthesentencetheerrorappearsin,thatmakesit easy for me to search. Page and section numbers are fine, too, but not quite aseasytoworkwith. Thanks! vii • IamgratefultothestudentinSoftwareSystemsatOlinCollege,whotested an early draft of this book in Spring 2014. They corrected many errors and mademanyhelpfulsuggestions. Iappreciatetheirpioneeringspirit! viii Chapter0. Preface Contents Preface v 1 Compilation 1 1.1 Compiledandinterpretedlanguages . . . . . . . . . . . . . . 1 1.2 Statictypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.3 Thecompilationprocess . . . . . . . . . . . . . . . . . . . . . 3 1.4 Objectcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.5 Assemblycode . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.6 Preprocessing . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.7 Understandingerrors . . . . . . . . . . . . . . . . . . . . . . . 7 2 Processes 9 2.1 Abstractionandvirtualization . . . . . . . . . . . . . . . . . . 9 2.2 Isolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.3 Unixprocesses . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3 Virtualmemory 15 3.1 Abitofinformationtheory . . . . . . . . . . . . . . . . . . . . 15 3.2 Memoryandstorage . . . . . . . . . . . . . . . . . . . . . . . 16 3.3 Addressspaces . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.4 Memorysegments . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.5 Addresstranslation . . . . . . . . . . . . . . . . . . . . . . . . 19 x Contents 4 Filesandfilesystems 23 4.1 Diskperformance . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.2 Diskmetadata . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 4.3 Blockallocation . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.4 Everythingisafile? . . . . . . . . . . . . . . . . . . . . . . . . 28 5 Morebitsandbytes 31 5.1 Representingintegers . . . . . . . . . . . . . . . . . . . . . . . 31 5.2 Bitwiseoperators . . . . . . . . . . . . . . . . . . . . . . . . . 32 5.3 Representingfloating-pointnumbers . . . . . . . . . . . . . . 33 5.4 Unionsandmemoryerrors . . . . . . . . . . . . . . . . . . . 35 5.5 Representingstrings . . . . . . . . . . . . . . . . . . . . . . . 37 6 Memorymanagement 39 6.1 Memoryerrors . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 6.2 Memoryleaks . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 6.3 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 42 7 Caching 45 7.1 Cacheperformance . . . . . . . . . . . . . . . . . . . . . . . . 47 7.2 Locality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 7.3 Measuringcacheperformance . . . . . . . . . . . . . . . . . . 48 7.4 Programmingforcacheperformance . . . . . . . . . . . . . . 51 7.5 Thememoryhierarchy . . . . . . . . . . . . . . . . . . . . . . 52 7.6 Cachingpolicy . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

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.