You are on page 1of 11

1

How Operating Systems Work


by Dave Coustan and Curt Franklin

)f you have a computer$ then you have heard about operatin# systems! "ny desktop or laptop *C that you buy normally comes pre+loaded with Windows XP! Macintosh computers come pre+loaded with OS X! Many corporate servers use the Linux or UNIX operatin# systems! 'he operatin# system ,-./ is the first thin# loaded onto the computer ++ without the operatin# system$ a computer is useless! More recently$ operatin# systems have started to pop up in smaller computers as well! )f you like to tinker with electronic devices$ you are probably pleased that operatin# systems can now be found on many of the devices we use every day$ from cell phones to wireless access points! 'he computers used in these little devices have #otten so powerful that they can now actually run an operatin# system and applications! 'he computer in a typical modern cell phone is now more powerful than a desktop computer from 20 years a#o$ so this pro#ression makes sense and is a natural development! )n any device that has an operatin# system$ there&s usually a way to make chan#es to how the device works! 'his is far from a happy accident0 one of the reasons operatin# systems are made out of portable code rather than permanent physical circuits is so that they can be chan#ed or modified without havin# to scrap the whole device!

Box shot reprinted with permission from Microsoft Corporation 200 Microsoft Corporation! "ll ri#hts reserved!

Microsoft XP operating system

For a desktop computer user$ this means you can add a new security update$ system patch$ new application or often even a new operatin# system entirely rather than %unk your computer and start a#ain with a new one when you need to make a chan#e! "s lon# as you understand how an operatin# system works and know how to #et at it$ you can in many cases chan#e some of the ways it behaves! "nd$ it&s as true of your cell phone as it is of your computer! 'he purpose of an operatin# system is to or#ani(e and control hardware and software so that the device it lives in behaves in a flexible but predictable way! )n this article$ we&ll tell you what a piece of software must do to be called an operatin# system$ show you how the operatin# system in your desktop computer works and #ive you some examples of how to take control of the other operatin# systems around you!

'he Bare Bones


1ot all computers have operatin# systems! 'he computer that controls the microwave oven in your kitchen$ for example$ doesn&t need an operatin# system! )t has one set of tasks to perform$ very strai#htforward input to expect ,a numbered keypad and a few pre+set buttons/ and simple$ never+chan#in# hardware to control! For a computer like this$ an operatin# system would be unnecessary ba##a#e$ drivin# up the development and manufacturin# costs si#nificantly and addin# complexity where none is re2uired! )nstead$ the computer in a microwave oven simply runs a sin#le hard+wired pro#ram all the time! For other devices$ an operatin# system creates the ability to3

serve a variety of purposes interact with users in more complicated ways keep up with needs that chan#e over time

"ll desktop computers have operatin# systems! 'he most common are the 4indows family of operatin# systems developed by Microsoft$ the Macintosh operatin# systems developed by "pple and the 51)6 family of operatin# systems ,which have been developed by a whole history of individuals$ corporations and collaborators/! 'here are hundreds of other operatin# systems available for special+purpose applications$ includin# speciali(ations for mainframes$ robotics$ manufacturin#$ real+time control systems and so on!

4hat Does )t Do7


"t the simplest level$ an operatin# system does two thin#s3 8! )t mana#es the hardware and software resources of the system! )n a desktop computer$ these resources include such thin#s as the processor$ memory$ disk space$ etc! ,-n a cell phone$ they include the keypad$ the screen$ the address book$ the phone dialer$ the battery and the network connection!/ 2! )t provides a stable$ consistent way for applications to deal with the hardware without havin# to know all the details of the hardware! 'he first task$ mana#in# the hardware and software resources$ is very important$ as various pro#rams and input methods compete for the attention of the central processing unit ,C*5/ and demand memory$ stora#e and input9output ,)9-/ bandwidth for their own purposes! )n this capacity$ the operatin# system plays the role of the #ood parent$ makin# sure that each application #ets the necessary resources while playin# nicely with all the other applications$ as well as husbandin# the limited capacity of the system to the #reatest #ood of all the users and applications!

3
'he second task$ providin# a consistent application interface$ is especially important if there is to be more than one of a particular type of computer usin# the operatin# system$ or if the hardware makin# up the computer is ever open to chan#e! " consistent application program interface ,"*)/ allows a software developer to write an application on one computer and have a hi#h level of confidence that it will run on another computer of the same type$ even if the amount of memory or the 2uantity of stora#e is different on the two machines! :ven if a particular computer is uni2ue$ an operatin# system can ensure that applications continue to run when hardware up#rades and updates occur! 'his is because the operatin# system and not the application is char#ed with mana#in# the hardware and the distribution of its resources! -ne of the challen#es facin# developers is keepin# their operatin# systems flexible enou#h to run hardware from the thousands of vendors manufacturin# computer e2uipment! 'oday&s systems can accommodate thousands of different printers$ disk drives and special peripherals in any possible combination!

4hat ;inds "re 'here7


4ithin the broad family of operatin# systems$ there are #enerally four types$ cate#ori(ed based on the types of computers they control and the sort of applications they support! 'he broad cate#ories are3

Real-time operating system ,<'-./ + <eal+time operatin# systems are used to control machinery$ scientific instruments and industrial systems! "n <'-. typically has very little user+interface capability$ and no end+user utilities$ since the system will be a =sealed box= when delivered for use! " very important part of an <'-. is mana#in# the resources of the computer so that a particular operation executes in precisely the same amount of time every time it occurs! )n a complex machine$ havin# a part move more 2uickly %ust because system resources are available may be %ust as catastrophic as havin# it not move at all because the system is busy! Single-user, single task + "s the name implies$ this operatin# system is desi#ned to mana#e the computer so that one user can effectively do one thin# at a time! 'he Palm OS for *alm handheld computers is a #ood example of a modern sin#le+user$ sin#le+task operatin# system! Single-user, multi-tasking + 'his is the type of operatin# system most people use on their desktop and laptop computers today! Microsoft&s Windows and "pple&s MacOS platforms are both examples of operatin# systems that will let a sin#le user have several pro#rams in operation at the same time! For example$ it&s entirely possible for a 4indows user to be writin# a note in a word processor while downloadin# a file from the )nternet while printin# the text of an e+mail messa#e! Multi-user + " multi+user operatin# system allows many different users to take advanta#e of the computer&s resources simultaneously! 'he operatin# system must make sure that the re2uirements of the various users are balanced$ and that each of the pro#rams they are usin# has sufficient and separate resources so that a problem with one user doesn&t affect the entire community of users! 5nix$ >M. and mainframe operatin# systems$ such as MVS$ are examples of multi+user operatin# systems!

*hoto courtesy "pple

Mac OS X Panther screen shot

)t&s important to differentiate here between multi+user operatin# systems and sin#le+user operatin# systems that support networkin#! Windows 2000 and Novell Netware can each support hundreds or thousands of networked users$ but the operatin# systems themselves aren&t true multi+user operatin# systems! 'he system administrator is the only =user= for Windows 2000 or Netware! 'he network support and all of the remote user lo#ins the network enables are$ in the overall plan of the operatin# system$ a pro#ram bein# run by the administrative user! 4ith the different types of operatin# systems in mind$ it&s time to look at the basic functions provided by an operatin# system!

4ake+5p Call
4hen you turn on the power to a computer$ the first pro#ram that runs is usually a set of instructions kept in the computer&s read+only memory ,<-M/! 'his code examines the system hardware to make sure everythin# is functionin# properly! 'his power-on self test ,*-.'/ checks the C*5$ memory$ and basic input+output systems ,B)-./ for errors and stores the result in a special memory location! -nce the *-.' has successfully completed$ the software loaded in <-M ,sometimes called the B)-. or firmware/ will be#in to activate the computer&s disk drives! )n most modern computers$ when the computer activates the hard disk drive$ it finds the first piece of the operatin# system3 the ootstrap loader! 'he bootstrap loader is a small pro#ram that has a sin#le function3 )t loads the operatin# system into memory and allows it to be#in operation! )n the most basic form$ the bootstrap loader sets up the small driver pro#rams that interface with and control the various hardware subsystems of the computer! )t sets up the divisions of memory that hold the operatin# system$ user information and applications! )t establishes the data structures that will hold the myriad si#nals$ fla#s and semaphores that are used to communicate within and between the subsystems and applications of the computer! 'hen it turns control of the computer over to the operatin# system!

5
'he operatin# system&s tasks$ in the most #eneral sense$ fall into six cate#ories3

*rocessor mana#ement Memory mana#ement Device mana#ement .tora#e mana#ement "pplication interface 5ser interface

4hile there are some who ar#ue that an operatin# system should do more than these six tasks$ and some operatin#+system vendors do build many more utility pro#rams and auxiliary functions into their operatin# systems$ these six tasks define the core of nearly all operatin# systems! ?et&s look at the tools the operatin# system uses to perform each of these functions!

*rocessor Mana#ement
'he heart of mana#in# the processor comes down to two related issues3

:nsurin# that each process and application receives enou#h of the processor&s time to function properly! 5sin# as many processor cycles for real work as is possible!

'he basic unit of software that the operatin# system deals with in schedulin# the work done by the processor is either a process or a thread$ dependin# on the operatin# system! )t&s temptin# to think of a process as an application$ but that #ives an incomplete picture of how processes relate to the operatin# system and hardware! 'he application you see ,word processor or spreadsheet or #ame/ is$ indeed$ a process$ but that application may cause several other processes to be#in$ for tasks like communications with other devices or other computers! 'here are also numerous processes that run without #ivin# you direct evidence that they ever exist! For example$ Windows XP and UNIX can have do(ens of back#round processes runnin# to handle the network$ memory mana#ement$ disk mana#ement$ virus checkin# and so on! " process$ then$ is software that performs some action and can be controlled ++ by a user$ by other applications or by the operatin# system! )t is processes$ rather than applications$ that the operatin# system controls and schedules for execution by the C*5! )n a sin#le+taskin# system$ the schedule is strai#htforward! 'he operatin# system allows the application to be#in runnin#$ suspendin# the execution only lon# enou#h to deal with interrupts and user input! )nterrupts are special si#nals sent by hardware or software to the C*5! )t&s as if some part of the computer suddenly raised its hand to ask for the C*5&s attention in a lively meetin#! .ometimes the operatin# system will schedule the priority of processes so that interrupts are masked ++ that is$ the operatin# system will i#nore the interrupts from some sources so that a particular %ob can be finished as 2uickly as possible! 'here are some interrupts ,such as those from error conditions or problems with memory/ that are so important that they can&t be i#nored! 'hese non-maska le interrupts ,1M)s/ must be dealt with immediately$ re#ardless of the other tasks at hand!

6
4hile interrupts add some complication to the execution of processes in a sin#le+taskin# system$ the %ob of the operatin# system becomes much more complicated in a multi+taskin# system! 1ow$ the operatin# system must arran#e the execution of applications so that you believe that there are several thin#s happenin# at once! 'his is complicated because the C*5 can only do one thin# at a time! )n order to #ive the appearance of lots of thin#s happenin# at the same time$ the operatin# system has to switch between different processes thousands of times a second! @ere&s how it happens3

" process occupies a certain amount of <"M! )t also makes use of re#isters$ stacks and 2ueues within the C*5 and operatin#+system memory space! 4hen two processes are multi+taskin#$ the operatin# system allots a certain number of C*5 execution cycles to one pro#ram! "fter that number of cycles$ the operatin# system makes copies of all the re#isters$ stacks and 2ueues used by the processes$ and notes the point at which the process paused in its execution! )t then loads all the re#isters$ stacks and 2ueues used by the second process and allows it a certain number of C*5 cycles!

4hen those are complete$ it makes copies of all the re#isters$ stacks and 2ueues used by the second pro#ram$ and loads the first pro#ram!

Memory .tora#e and Mana#ement


4hen an operatin# system mana#es the computer&s memory$ there are two broad tasks to be accomplished3 8! :ach process must have enou#h memory in which to execute$ and it can neither run into the memory space of another process nor be run into by another process! 2! 'he different types of memory in the system must be used properly so that each process can run most effectively! 'he first task re2uires the operatin# system to set up memory boundaries for types of software and for individual applications! "s an example$ let&s look at an ima#inary small system with 8 me#abyte ,8$000 kilobytes/ of <"M! Durin# the boot process$ the operatin# system of our ima#inary computer is desi#ned to #o to the top of available memory and then =back up= far enou#h to meet the needs of the operatin# system itself! ?et&s say that the operatin# system needs 00 kilobytes to run! 1ow$ the operatin# system #oes to the bottom of the pool of <"M and starts buildin# up with the various driver software re2uired to control the hardware subsystems of the computer! )n our ima#inary computer$ the drivers take up 200 kilobytes! .o after #ettin# the operatin# system completely loaded$ there are A00 kilobytes remainin# for application processes! 4hen applications be#in to be loaded into memory$ they are loaded in block si(es determined by the operatin# system! )f the block si(e is 2 kilobytes$ then every process that is loaded will be #iven a chunk of memory that is a multiple of 2 kilobytes in si(e! "pplications will be loaded in these fixed block si(es$ with the blocks startin# and endin# on boundaries established by words of B or C bytes! 'hese blocks and boundaries help to ensure that applications won&t be loaded on top of one another&s space by a poorly calculated bit or two! 4ith that ensured$ the lar#er 2uestion is what to do when the A00+ kilobyte application space is filled!

7
)n most computers$ it&s possible to add memory beyond the ori#inal capacity! For example$ you mi#ht expand <"M from 8 to 2 me#abytes! 'his works fine$ but tends to be relatively expensive! )t also i#nores a fundamental fact of computin# ++ most of the information that an application stores in memory is not bein# used at any #iven moment! " processor can only access memory one location at a time$ so the vast ma%ority of <"M is unused at any moment! .ince disk space is cheap compared to <"M$ then movin# information in <"M to hard disk can #reatly expand <"M space at no cost! 'his techni2ue is called !irtual memory management! Disk stora#e is only one of the memory types that must be mana#ed by the operatin# system$ and is the slowest! <anked in order of speed$ the types of memory in a computer system are3

High-speed cache + 'his is fast$ relatively small amounts of memory that are available to the C*5 throu#h the fastest connections! Cache controllers predict which pieces of data the C*5 will need next and pull it from main memory into hi#h+ speed cache to speed up system performance! Main memory + 'his is the <"M that you see measured in me#abytes when you buy a computer! Secondary memory + 'his is most often some sort of rotatin# ma#netic stora#e that keeps applications and data available to be used$ and serves as virtual <"M under the control of the operatin# system!

'he operatin# system must balance the needs of the various processes with the availability of the different types of memory$ movin# data in blocks ,called pages/ between available memory as the schedule of processes dictates!

Device Mana#ement
'he path between the operatin# system and virtually all hardware not on the computer&s motherboard #oes throu#h a special pro#ram called a driver! Much of a driver&s function is to be the translator between the electrical si#nals of the hardware subsystems and the hi#h+ level pro#rammin# lan#ua#es of the operatin# system and application pro#rams! Drivers take data that the operatin# system has defined as a file and translate them into streams of bits placed in specific locations on stora#e devices$ or a series of laser pulses in a printer! Because there are such wide differences in the hardware controlled throu#h drivers$ there are differences in the way that the driver pro#rams function$ but most are run when the device is re2uired$ and function much the same as any other process! 'he operatin# system will fre2uently assi#n hi#h+priority blocks to drivers so that the hardware resource can be released and readied for further use as 2uickly as possible! -ne reason that drivers are separate from the operatin# system is so that new functions can be added to the driver ++ and thus to the hardware subsystems ++ without re2uirin# the operatin# system itself to be modified$ recompiled and redistributed! 'hrou#h the development of new hardware device drivers$ development often performed or paid for by the manufacturer of the subsystems rather than the publisher of the operatin# system$ input9output capabilities of the overall system can be #reatly enhanced! Mana#in# input and output is lar#ely a matter of mana#in# "ueues and uffers$ special stora#e facilities that take a stream of bits from a device$ perhaps a keyboard or a serial port$ hold those bits$ and release them to the C*5 at a rate slow enou#h for the C*5 to cope with!

8
'his function is especially important when a number of processes are runnin# and takin# up processor time! 'he operatin# system will instruct a buffer to continue takin# input from the device$ but to stop sendin# data to the C*5 while the process usin# the input is suspended! 'hen$ when the process needin# input is made active once a#ain$ the operatin# system will command the buffer to send data! 'his process allows a keyboard or a modem to deal with external users or computers at a hi#h speed even thou#h there are times when the C*5 can&t use input from those sources! Mana#in# all the resources of the computer system is a lar#e part of the operatin# system&s function and$ in the case of real+time operatin# systems$ may be virtually all the functionality re2uired! For other operatin# systems$ thou#h$ providin# a relatively simple$ consistent way for applications and humans to use the power of the hardware is a crucial part of their reason for existin#!

)nterface to the 4orld


"pplication )nterface
Dust as drivers provide a way for applications to make use of hardware subsystems without havin# to know every detail of the hardware&s operation$ application program interfaces ,"*)s/ let application pro#rammers use functions of the computer and operatin# system without havin# to directly keep track of all the details in the C*5&s operation! ?et&s look at the example of creatin# a hard disk file for holdin# data to see why this can be important! " pro#rammer writin# an application to record data from a scientific instrument mi#ht want to allow the scientist to specify the name of the file created! 'he operatin# system mi#ht provide an "*) function named Make#ile for creatin# files! 4hen writin# the pro#ram$ the pro#rammer would insert a line that looks like this3 Make#ile $%, &'ame, () )n this example$ the instruction tells the operatin# system to create a file that will allow random access to its data ,si#nified by the 8 ++ the other option mi#ht be 0 for a serial file/$ will have a name typed in by the user ,E1ame/ and will be a si(e that varies dependin# on how much data is stored in the file ,si#nified by the 2 ++ other options mi#ht be (ero for a fixed si(e$ and 8 for a file that #rows as data is added but does not shrink when data is removed/! 1ow$ let&s look at what the operatin# system does to turn the instruction into action! 'he operatin# system sends a 2uery to the disk drive to #et the location of the first available free stora#e location! 4ith that information$ the operatin# system creates an entry in the file system showin# the be#innin# and endin# locations of the file$ the name of the file$ the file type$ whether the file has been archived$ which users have permission to look at or modify the fil$ and the date and time of the file&s creation! 'he operatin# system writes information at the be#innin# of the file that identifies the file$ sets up the type of access possible and includes other information that ties the file to the application! )n all of this information$ the 2ueries to the disk drive and addresses of the be#innin# and endin# point of the file are in formats heavily dependent on the manufacturer and model of the disk drive!

9
Because the pro#rammer has written the pro#ram to use the "*) for disk stora#e$ the pro#rammer doesn&t have to keep up with the instruction codes$ data types and response codes for every possible hard disk and tape drive! 'he operatin# system$ connected to drivers for the various hardware subsystems$ deals with the chan#in# details of the hardware ++ the pro#rammer must simply write code for the "*) and trust the operatin# system to do the rest! "*)s have become one of the most hotly contested areas of the computer industry in recent years! Companies reali(e that pro#rammers usin# their "*) will ultimately translate this into the ability to control and profit from a particular part of the industry! 'his is one of the reasons that so many companies have been willin# to provide applications like readers or viewers to the public at no char#e! 'hey know consumers will re2uest that pro#rams take advanta#e of the free readers$ and application companies will be ready to pay royalties to allow their software to provide the functions re2uested by the consumers!

5ser )nterface
Dust as the "*) provides a consistent way for applications to use the resources of the computer system$ a user interface ,5)/ brin#s structure to the interaction between a user and the computer! )n the last decade$ almost all development in user interfaces has been in the area of the graphical user interface ,F5)/$ with two models$ "pple&s Macintosh and Microsoft&s Windows$ receivin# most of the attention and #ainin# most of the market share! 'he popular$ open+source ?inux operatin# system also supports a #raphical user interface!

.creen shot copyri#ht 200 <ed @at$ )nc! "ll ri#hts reserved! <eprinted with permission from <ed @at$ )nc!

Screen shot of Red Hat*s +inu, operating system

'here are other user interfaces$ some #raphical and some not$ for other operatin# systems! 5nix$ for example$ has user interfaces called shells that present a user interface more flexible and powerful than the standard operatin# system text+based interface! *ro#rams such as the orn Shell and the ! Shell are text+based interfaces that add important utilities$ but their main purpose is to make it easier for the user to manipulate the functions of the

10
operatin# system! 'here are also #raphical user interfaces$ such as X"Windows and #nome$ that make 5nix and ?inux more like 4indows and Macintosh computers from the user&s point of view! )t&s important to remember that in all of these examples$ the user interface is a pro#ram or set of pro#rams that sits as a layer above the operatin# system itself! 'he same thin# is true$ with somewhat different mechanisms$ of both 4indows and Macintosh operatin# systems! 'he core operatin#+system functions ++ the mana#ement of the computer system ++ lie in the kernel of the operatin# system! 'he display manager is separate$ thou#h it may be tied ti#htly to the kernel beneath! 'he ties between the operatin#+system kernel and the user interface$ utilities and other software define many of the differences in operatin# systems today$ and will further define them in the future!

4hat&s 1ew
'he Frowin# )mportance of 1etworks
For desktop systems$ access to a ?"1 or the )nternet has become such an expected feature that in many ways it&s hard to discuss an operatin# system without makin# reference to its connections to other computers and servers! -peratin# system developers have made the )nternet the standard method for deliverin# crucial operatin# system updates and bu# fixes! "lthou#h it is possible to receive these updates via CD$ it is becomin# increasin#ly less common! )n fact$ some entire operatin# systems themselves are only available throu#h distribution over the )nternet! Further$ a process called 'et-ooting has streamlined the capability to move the workin# operatin# system of a standard consumer desktop computer + kernel$ user interface and all + off of the machine it controls! 'his was previously only possible for experienced power+users on multi+user platforms like 51)6 and with a suite of speciali(ed applications! 1etBootin# allows the operatin# system for one computer to be served over a network connection$ by a remote computer connected anywhere in the network! -ne 1etBoot server can serve operatin# systems to several do(en client computers simultaneously$ and to the user sittin# in front of each client computer the experience is %ust like they are usin# their familiar desktop operatin# system like Windows or MacOS!

-pen .ource
-ne 2uestion concernin# the future of operatin# systems revolves around the ability of a particular philosophy of software distribution to create an operatin# system useable by corporations and consumers to#ether!

11
?inux$ the operatin# system created and distributed accordin# to the principles of open source$ has had a si#nificant impact on the operatin# system in #eneral! Most operatin# systems$ drivers and utility pro#rams are written by commercial or#ani(ations that distribute e,ecuta le !ersions of their software ++ versions that can&t be studied or altered! -pen source re2uires the distribution of ori#inal source materials that can be studied$ altered and built upon$ with the results once a#ain freely distributed! )n the desktop computer realm$ this has led to the development and distribution of countless useful and cost+free applications like the ima#e manipulation pro#ram F)M* ?o#o courtesy ?arry :win# and the popular web server "pache! )n the consumer +inu, logo device realm$ the use of ?inux has paved the way for individual users to have #reater control over how their devices behave!

Fettin# at the -.
Many consumer devices like cell phones and routers deliberately hide access to the operatin# system from the user$ mostly to make sure that it&s not inadvertently broken or removed! )n many cases$ they leave open a =developer&s mode= or =pro#rammer&s mode= which allow chan#es to be made if you know how to find it! -ften these systems may be pro#rammed in such a way that there are only a limited ran#e of chan#es that can be made! But some devices leave open both a mode of access and the means of makin# powerful chan#es$ especially those that use ?inux! @ere are a couple of examples3

'he 'i>o D>< runs on a modified version of ?inux! "ll of the modifications are public knowled#e$ and can be downloaded here alon# with some special tools for manipulatin# the code! Many enterprisin# 'i>o users have done %ust that$ addin# functionality to their systems$ from increasin# the stora#e capacity to #ettin# to 51)6 shells to chan#in# the mode from 1'.C to *"?! @ere&s a F"G on how to hack your 'i>o!

*hoto courtesy "ma(on!com

Philips H.R/%( 0i1o /2-Hour .igital 1ideo Recorder and +inksys 34XS55W 3ther#ast %26%22 5-Port Workgroup Switch

Many home routers also run on Linux, including those made y Lin!sys" #his article $rom %4#ech#& discusses ho' to hac! your Lin!sys (outer and ta!e control o$ the Linux inside"