Example: bachelor of science

The Abstraction: The Process

4 The abstraction : The ProcessIn this chapter, we discuss one of the most fundamental abstractions thatthe OS provides to users: theprocess. The definition of a Process , infor-mally, is quite simple: it is arunning program[V+65,BH70]. The programitself is a lifeless thing: it just sits there on the disk, a bunch of instructions(and maybe some static data), waiting to spring into action. Itis the oper-ating system that takes these bytes and gets them running, transformingthe program into something turns out that one often wants to run more than one program atonce; for example, consider your desktop or laptop where you might liketo run a web browser, mail program, a game, a music player, and fact, a typical system may be seemingly running tens or evenhundredsof processes at the same time.

ating system that takes these bytes and gets them running, transforming the program into something useful. It turns out that one often wants to run more than one program at once; for example, consider your desktop or laptop where you might like torunawebbrowser,mailprogram,agame,amusicplayer,andsoforth.

Tags:

  Process, Giant, The process, Abstraction, The abstraction

Information

Domain:

Source:

Link to this page:

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

Other abuse

Advertisement

Transcription of The Abstraction: The Process

1 4 The abstraction : The ProcessIn this chapter, we discuss one of the most fundamental abstractions thatthe OS provides to users: theprocess. The definition of a Process , infor-mally, is quite simple: it is arunning program[V+65,BH70]. The programitself is a lifeless thing: it just sits there on the disk, a bunch of instructions(and maybe some static data), waiting to spring into action. Itis the oper-ating system that takes these bytes and gets them running, transformingthe program into something turns out that one often wants to run more than one program atonce; for example, consider your desktop or laptop where you might liketo run a web browser, mail program, a game, a music player, and fact, a typical system may be seemingly running tens or evenhundredsof processes at the same time.

2 Doing so makes the system easy to use, asone never need be concerned with whether a CPU is available; one simplyruns programs. Hence our challenge:THECRUX OF THEPROBLEM:HOWTOPROVIDETHEILLUSIONOFMANY CPUS?Although there are only a few physical CPUs available, how can theOS provide the illusion of a nearly-endless supply of said CPUs?The OS creates this illusion byvirtualizingthe CPU. By running oneprocess, then stopping it and running another, and so forth, the OS canpromote the illusion that many virtual CPUs exist when in fact there isonly one physical CPU (or a few). This basic technique, known astimesharingof the CPU, allows users to run as many concurrent processes asthey would like; the potential cost is performance, as each will run moreslowly if the CPU(s) must be implement virtualization of the CPU, and to implement it well, theOS will need both some low-level machinery and some high-level in-telligence.

3 We call the low-level machinerymechanisms; mechanismsare low-level methods or protocols that implement a needed piece offunctionality. For example, we ll learn later how to implement acontext12 THEABSTRACTION: THEPROCESSTIP: USETIMESHARING(ANDSPACESHARING)Time sharingis a basic technique used by an OS to share a resource. Byallowing the resource to be used for a little while by one entity, and thena little while by another, and so forth, the resource in question ( , theCPU, or a network link) can be shared by many. The counterpart of timesharing isspace sharing, where a resource is divided (in space) amongthose who wish to use it. For example, disk space is naturally a space-shared resource; once a block is assigned to a file, it is normally not as-signed to another file until the user deletes the original , which gives the OS the ability to stop running one program andstart running another on a given CPU; thistime-sharingmechanism isemployed by all modern top of these mechanisms resides some of the intelligence in theOS, in the form ofpolicies.

4 Policies are algorithms for making somekind of decision within the OS. For example, given a number of possi-ble programs to run on a CPU, which program should the OS run? Ascheduling policyin the OS will make this decision, likely using histori-cal information ( , which program has run more over the last minute?),workload knowledge ( , what types of programs are run), and perfor-mance metrics ( , is the system optimizing for interactiveperformance,or throughput?) to make its The abstraction : A ProcessThe abstraction provided by the OS of a running program is somethingwe will call aprocess. As we said above, a Process is simply a runningprogram; at any instant in time, we can summarize a Process by taking aninventory of the different pieces of the system it accesses or affects duringthe course of its understand what constitutes a Process , we thus have to understanditsmachine state: what a program can read or update when it is any given time, what parts of the machine are important to theexecu-tion of this program?

5 One obvious component of machine state that comprises a Process isitsmemory. Instructions lie in memory; the data that the running pro-gram reads and writes sits in memory as well. Thus the memory that theprocess can address (called itsaddress space) is part of the part of the Process s machine state areregisters; many instructionsexplicitly read or update registers and thus clearly they areimportant tothe execution of the that there are some particularly special registers that form partof this machine state. For example, theprogram counter(PC) (sometimescalled theinstruction pointerorIP) tells us which instruction of the pro-gram is currently being executed; similarly astack pointerand associatedOPERATINGSYSTEMS[ ] : THEPROCESS3 TIP: SEPARATEPOLICYANDMECHANISMIn many operating systems, a common design paradigm is to separatehigh-level policies from their low-level mechanisms [L+75].

6 You canthink of the mechanism as providing the answer to ahowquestion abouta system; for example,howdoes an operating system perform a contextswitch? The policy provides the answer to awhichquestion; for example,whichprocess should the operating system run right now? Separating thetwo allows one easily to change policies without having to rethink themechanism and is thus a form ofmodularity, a general software pointerare used to manage the stack for function parameters, localvariables, and return , programs often access persistent storage devices too. SuchI/Oinformationmight include a list of the files the Process currently has Process APIT hough we defer discussion of a real Process API until a subsequentchapter, here we first give some idea of what must be included in anyinterface of an operating system.

7 These APIs, in some form, are availableon any modern operating system. Create:An operating system must include some method to cre-ate new processes. When you type a command into the shell, ordouble-click on an application icon, the OS is invoked to create anew Process to run the program you have indicated. Destroy:As there is an interface for Process creation, systems alsoprovide an interface to destroy processes forcefully. Of course,manyprocesses will run and just exit by themselves when complete; whenthey don t, however, the user may wish to kill them, and thus an in-terface to halt a runaway Process is quite useful. Wait:Sometimes it is useful to wait for a Process to stop running;thus some kind of waiting interface is often provided.

8 Miscellaneous Control:Other than killing or waiting for a Process ,there are sometimes other controls that are possible. For example,most operating systems provide some kind of method to suspend aprocess (stop it from running for a while) and then resume it (con-tinue it running). Status:There are usually interfaces to get some status informationabout a Process as well, such as how long it has run for, or whatstate it is 2008 18, ARPACI-DUSSEAUTHREEEASYPIECES4 THEABSTRACTION: THEPROCESSM emoryCPUD iskcodestatic dataheapstackProcesscodestatic dataProgramLoading:Takes on-disk programand reads it into theaddress space of processFigure :Loading: From Program To Process Creation: A Little More DetailOne mystery that we should unmask a bit is how programs are trans-formed into processes.

9 Specifically, how does the OS get a program upand running? How does Process creation actually work?The first thing that the OS must do to run a program is toloadits codeand any static data ( , initialized variables) into memory, into the ad-dress space of the Process . Programs initially reside ondisk(or, in somemodern systems,flash-based SSDs) in some kind ofexecutable format;thus, the Process of loading a program and static data into memory re-quires the OS to read those bytes from disk and place them in memorysomewhere (as shown in Figure ).In early (or simple) operating systems, the loading Process is doneea-gerly, , all at once before running the program; modern OSes performthe processlazily, , by loading pieces of code or data only as they areneeded during program execution.

10 To truly understand how lazy loadingof pieces of code and data works, you ll have to understand more aboutthe machinery ofpagingandswapping, topics we ll cover in the futurewhen we discuss the virtualization of memory. For now, just rememberthat before running anything, the OS clearly must do some work togetthe important program bits from disk into [ ] : THEPROCESS5 Once the code and static data are loaded into memory, there are a fewother things the OS needs to do before running the Process . Some mem-ory must be allocated for the program srun-time stack(or juststack).As you should likely already know, C programs use the stack for localvariables, function parameters, and return addresses; the OS allocatesthis memory and gives it to the Process .


Related search queries