os structure & processes1 vivek pai cos 318 september 19, 2002

27
OS Structure & Processes 1 OS Structure & OS Structure & Processes Processes Vivek Pai Vivek Pai COS 318 COS 318 September 19, 2002 September 19, 2002

Post on 19-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 1

OS Structure & ProcessesOS Structure & Processes

Vivek PaiVivek Pai

COS 318COS 318

September 19, 2002September 19, 2002

Page 2: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 2

FoodundgedankFoodundgedank

You’re the host/hostess of a banquet hall that has You’re the host/hostess of a banquet hall that has accidentally been double-booked. It has three accidentally been double-booked. It has three rooms – the large dining room, the cocktail room, rooms – the large dining room, the cocktail room, and a small buffet line room.and a small buffet line room.

If each guest is given a card with the room layout If each guest is given a card with the room layout with table numbers, and the guest’s own table with table numbers, and the guest’s own table number, how can you solve this problem?number, how can you solve this problem?

What issues are involved regarding the sizes of the What issues are involved regarding the sizes of the two groups?two groups?

Page 3: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 3

AdministrativeAdministrative

First precept happened, more to comeFirst precept happened, more to come– Friday’s booked – same time, same placeFriday’s booked – same time, same place

Yong is this project’s TAYong is this project’s TA Project 1 due 11:59pm Oct 1Project 1 due 11:59pm Oct 1 Almost everyone has given me detailsAlmost everyone has given me details

– Get me what remainsGet me what remains Next reading assignment: ???Next reading assignment: ???

Page 4: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 4

A Friendly DeceptionA Friendly Deception

Hiding informationHiding information Giving out different information while Giving out different information while

appearing to be the sameappearing to be the same Stalling when necessaryStalling when necessary

Drawback? Maybe lots of extra workDrawback? Maybe lots of extra work Benefit: makes life easier for userBenefit: makes life easier for user

Page 5: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 5

Host/Hostess ProblemHost/Hostess Problem

Each group < 50%Each group < 50%– Have two sets of cards with different Have two sets of cards with different

numbering schemesnumbering schemes Each group slightly above 50%Each group slightly above 50%

– Slow down the buffet line & entranceSlow down the buffet line & entrance Each group near 100%Each group near 100%

– One group in dining room, other in cocktail One group in dining room, other in cocktail roomroom

Page 6: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 6

Users, Programs, ProcessesUsers, Programs, Processes

Users have accounts on the systemUsers have accounts on the system Users launch programsUsers launch programs

– Many users may launch same programMany users may launch same program– One user may launch many instances of the One user may launch many instances of the

same programsame program Processes are instances of a programProcesses are instances of a program

– The “program” can really be a set of processesThe “program” can really be a set of processes

Page 7: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 7

Programs As Process CollectionsPrograms As Process Collections

Netscape (output of “ps x”)Netscape (output of “ps x”)– 7253 p0 S 0:19.26 /usr/local/lib/netscape/communicator-4.75.bin -irix-s7253 p0 S 0:19.26 /usr/local/lib/netscape/communicator-4.75.bin -irix-s

– 7280 p0 I 0:00.15 (dns helper) (communicator-4.7)7280 p0 I 0:00.15 (dns helper) (communicator-4.7)

gcc (via “gcc –pipe –v”)gcc (via “gcc –pipe –v”)– /usr/libexec/cpp |/usr/libexec/cpp |– /usr/libexec/cc1 |/usr/libexec/cc1 |– /usr/libexec/as, followed by/usr/libexec/as, followed by– /usr/libexec/elf/ld/usr/libexec/elf/ld

Page 8: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 8

gcc examplegcc example

You launch gccYou launch gcc It first launches cpp, cc1, asIt first launches cpp, cc1, as It then launches ldIt then launches ld

Each instance is a process, and each Each instance is a process, and each program actually exists separatelyprogram actually exists separately– You could launch cc1 manually if you wantedYou could launch cc1 manually if you wanted

Page 9: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 9

So What Is A Process?So What Is A Process?

It’s one instance of a “program”It’s one instance of a “program” It’s separate from other instancesIt’s separate from other instances It can start (“launch”) other processesIt can start (“launch”) other processes It can be launched by themIt can be launched by them

Page 10: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 10

What Does This Program Do?What Does This Program Do?

int myval;int myval;

int main(int argc, char *argv[])int main(int argc, char *argv[]){{

myval = atoi(argv[1]);myval = atoi(argv[1]);while (1)while (1)

printf(“myval is %d, loc 0x%lx\n”,printf(“myval is %d, loc 0x%lx\n”,myval, (long) &myval);myval, (long) &myval);

}}

Page 11: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 11

Here’s The OutputHere’s The Output

Page 12: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 12

Instances Of ProgramsInstances Of Programs

The address was always the sameThe address was always the same The values were differentThe values were different

– Implies that the programs aren’t seeing each Implies that the programs aren’t seeing each otherother

– But they think they’re using the same addressBut they think they’re using the same address

Conclusion: addresses are not absoluteConclusion: addresses are not absolute What’s the benefit?What’s the benefit?

Page 13: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 13

So What’s In A Process?So What’s In A Process?

Information about the hierarchyInformation about the hierarchy– What launched itWhat launched it– What it has launchedWhat it has launched

Information about resourcesInformation about resources– Where is it storing dataWhere is it storing data– What other resources it’s usingWhat other resources it’s using

Various kinds of mappingsVarious kinds of mappings

Page 14: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 14

Consider How To Read a FileConsider How To Read a File

Compare read( ) and fread( )Compare read( ) and fread( ) read(int d, void *buf, size_t nbytes)read(int d, void *buf, size_t nbytes)

read( ) attempts to read nbytes of data from the object read( ) attempts to read nbytes of data from the object referenced by the descriptor d into the buffer pointed to by referenced by the descriptor d into the buffer pointed to by buf. buf.

fread(void *ptr, size_t size, size_t nmemb, FILE *stream)fread(void *ptr, size_t size, size_t nmemb, FILE *stream)

The function fread( ) reads nmemb objects, each size bytes The function fread( ) reads nmemb objects, each size bytes long, from the stream pointed to by stream, storing them at long, from the stream pointed to by stream, storing them at the location given by ptr.the location given by ptr.

Page 15: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 15

Which is a System Call and WhyWhich is a System Call and Why

read(int d, void *buf, size_t nbytes)read(int d, void *buf, size_t nbytes) fread(void *ptr, size_t size, size_t nmemb, FILE fread(void *ptr, size_t size, size_t nmemb, FILE

*stream)*stream)

Both do the same thing, right?Both do the same thing, right? What gets “exposed” in each caseWhat gets “exposed” in each case What about a lying programmerWhat about a lying programmer

– How hard is it to tell he/she is lyingHow hard is it to tell he/she is lying– What other malicious actions can occur?What other malicious actions can occur?

Page 16: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 16

What State Is Implied?What State Is Implied?

Consider the following sequence:Consider the following sequence:

read(int d, void *buf, size_t nbytes)read(int d, void *buf, size_t nbytes)

read(int d, void *buf, size_t nbytes)read(int d, void *buf, size_t nbytes)

read(int d, void *buf, size_t nbytes)read(int d, void *buf, size_t nbytes)

What happens if two programs were doing this?What happens if two programs were doing this?

Page 17: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 17

Some Insight Into OSSome Insight Into OS

Process

Array ofFile Pointers

Actual FileInfo

What do we gain from this?

Page 18: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 18

Some Insight Into OSSome Insight Into OS

Process

Array ofFile Pointers

Actual FileInfo

Process

Page 19: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 19

Examining Those Other ParametersExamining Those Other Parameters

read(int d, void *buf, size_t nbytes)read(int d, void *buf, size_t nbytes) fread(void *ptr, size_t size, size_t nmemb, FILE fread(void *ptr, size_t size, size_t nmemb, FILE

*stream)*stream)

Where is [buf, buf+nbytes)?Where is [buf, buf+nbytes)?

Where is [ptr, ptr+size*nmemb)?Where is [ptr, ptr+size*nmemb)?

Page 20: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 20

Remember This?Remember This?

Application

Portable OS Layer

Libraries

Machine-dependent layer

User space/level

Kernel space/level

Page 21: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 21

Address SpaceAddress Space

One (common) approachOne (common) approach– Kernel is high memoryKernel is high memory– User is low memoryUser is low memory

What restrictions apply?What restrictions apply?

read(f, buf, nbytes)read(f, buf, nbytes)

0xffff….Kernel space

User space0x0000…

Page 22: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 22

Some DefinitionsSome Definitions

Kernel – “heart” of the operating systemKernel – “heart” of the operating system– Like the program file generated by compiling Like the program file generated by compiling

all of the operating system filesall of the operating system files Operating system – usually includes moreOperating system – usually includes more

– Various librariesVarious libraries– Support programsSupport programs

Hard and fast definitions? RarelyHard and fast definitions? Rarely

Page 23: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 23

More Address SpaceMore Address Space

Program segmentsProgram segments– TextText– DataData– StackStack– HeapHeap

Any obvious choices?Any obvious choices?

0xffff….Kernel space

User space0x0000…

Page 24: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 24

One Common LayoutOne Common Layout

Lots of flexibilityLots of flexibility– Allows stack growthAllows stack growth– Allows heap growthAllows heap growth– No predetermined divisionNo predetermined division

So what happens when youSo what happens when youmake a system call? make a system call?

0xffff….Kernel space

Stack

HeapCode & Data

0x0000…

Page 25: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 25

Kernel StackKernel Stack

Kernel contains functionsKernel contains functions– Just like regular functionsJust like regular functions– Automatic variables, formal parameters, etcAutomatic variables, formal parameters, etc– They need a stackThey need a stack

Can we use the user’s stack?Can we use the user’s stack?– Is it possible?Is it possible?– Is it desirable?Is it desirable?

Page 26: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 26

Is The Kernel A Process?Is The Kernel A Process?

Monolithic OSMonolithic OS– Most forms of OS you’ve probably usedMost forms of OS you’ve probably used

Layered systemsLayered systems– THE system (design)THE system (design)– Multics (design + hardware support)Multics (design + hardware support)

Hypervisors/virtual machinesHypervisors/virtual machines Client/Server (microkernels)Client/Server (microkernels)

– MachMach

Page 27: OS Structure & Processes1 Vivek Pai COS 318 September 19, 2002

OS Structure & Processes 27

What Other Options Possible?What Other Options Possible?

Remember the host/hostess scenario?Remember the host/hostess scenario?– What would happen if you had a break between What would happen if you had a break between

coursescourses– Can you apply this logic to the kernel?Can you apply this logic to the kernel?– What are the tradeoffs?What are the tradeoffs?