OS Structure & Processes Vivek Pai COS 318 September 20, 2001

Download Report

Transcript OS Structure & Processes Vivek Pai COS 318 September 20, 2001

OS Structure & Processes
Vivek Pai
COS 318
September 20, 2001
OS Structure & Processes
1
Foodundgedank



You’re the host/hostess of a banquet hall that has
accidentally been double-booked. It has three
rooms – the large dining room, the cocktail room,
and a small buffet line room.
If each guest is given a card with the room layout
with table numbers, and the guest’s own table
number, how can you solve this problem?
What issues are involved regarding the sizes of the
two groups?
OS Structure & Processes
2
Administrative

First precept happened, more to come
– Room scheduling not finalized, but 103 likely
– Friday may be at 3:30 instead of 3:00
Politely remind me if I’m running late
 I’ve forgotten about the feedback paper
 Next reading assignment: 1.4, 1.5

OS Structure & Processes
3
A Friendly Deception
Hiding information
 Giving out different information while
appearing to be the same
 Stalling when necessary

Drawback? Maybe lots of extra work
 Benefit: makes life easier for user

OS Structure & Processes
4
Host/Hostess Problem

Each group < 50%
– Have two sets of cards with different
numbering schemes

Each group slightly above 50%
– Slow down the buffet line & entrance

Each group near 100%
– One group in dining room, other in cocktail
room
OS Structure & Processes
5
Users, Programs, Processes
Users have accounts on the system
 Users launch programs

– Many users may launch same program
– One user may launch many instances of the
same program

Processes are instances of a program
– The “program” can really be a set of processes
OS Structure & Processes
6
Programs As Process Collections

Netscape (output of “ps x”)
– 7253 p0 S
– 7280 p0 I

0:19.26 /usr/local/lib/netscape/communicator-4.75.bin -irix-s
0:00.15 (dns helper) (communicator-4.7)
gcc (via “gcc –pipe –v”)
–
–
–
–
/usr/libexec/cpp |
/usr/libexec/cc1 |
/usr/libexec/as, followed by
/usr/libexec/elf/ld
OS Structure & Processes
7
gcc example
You launch gcc
 It first launches cpp, cc1, as
 It then launches ld


Each instance is a process, and each
program actually exists separately
– You could launch cc1 manually if you wanted
OS Structure & Processes
8
So What Is A Process?
It’s one instance of a “program”
 It’s separate from other instances
 It can start (“launch”) other processes
 It can be launched by them

OS Structure & Processes
9
What Does This Program Do?
int myval;
int main(int argc, char *argv[])
{
myval = atoi(argv[1]);
while (1)
printf(“myval is %d, loc 0x%lx\n”,
myval, (long) &myval);
}
OS Structure & Processes
10
Here’s The Output
OS Structure & Processes
11
Instances Of Programs
The address was always the same
 The values were different

– Implies that the programs aren’t seeing each
other
– But they think they’re using the same address
Conclusion: addresses are not absolute
 What’s the benefit?

OS Structure & Processes
12
So What’s In A Process?

Information about the hierarchy
– What launched it
– What it has launched

Information about resources
– Where is it storing data
– What other resources it’s using

Various kinds of mappings
OS Structure & Processes
13
Consider How To Read a File

Compare read( ) and fread( )

read(int d, void *buf, size_t nbytes)
read() attempts to read nbytes of data from the object
referenced by the descriptor d into the buffer pointed to by
buf.

fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
The function fread() reads nmemb objects, each size bytes
long, from the stream pointed to by stream, storing them at
the location given by ptr.
OS Structure & Processes
14
Which is a System Call and Why


read(int d, void *buf, size_t nbytes)
fread(void *ptr, size_t size, size_t nmemb, FILE
*stream)
Both do the same thing, right?
 What gets “exposed” in each case
 What about a lying programmer

– How hard is it to tell he/she is lying
– What other malicious actions can occur?
OS Structure & Processes
15
What State Is Implied?

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)
What happens if two programs were doing this?
OS Structure & Processes
16
Some Insight Into OS
Array of
File Pointers
Process
Actual File
Info
What do we gain from this?
OS Structure & Processes
17
Some Insight Into OS
Array of
File Pointers
Process
Actual File
Info
Process
OS Structure & Processes
18
Examining Those Other Parameters


read(int d, void *buf, size_t nbytes)
fread(void *ptr, size_t size, size_t nmemb, FILE
*stream)
Where is [buf, buf+nbytes)?
Where is [ptr, ptr+size*nmemb)?
OS Structure & Processes
19
Remember This?
Application
Libraries
User space/level
Kernel space/level
Portable OS Layer
Machine-dependent layer
OS Structure & Processes
20
Address Space

One (common) approach
– Kernel is high memory
– User is low memory

What restrictions apply?

read(f, buf, nbytes)
OS Structure & Processes
0xffff….
Kernel space
User space
0x0000…
21
Some Definitions

Kernel – “heart” of the operating system
– Like the program file generated by compiling
all of the operating system files

Operating system – usually includes more
– Various libraries
– Support programs

Hard and fast definitions? Rarely
OS Structure & Processes
22
More Address Space

Program segments
–
–
–
–

Text
Data
Stack
Heap
Any obvious choices?
OS Structure & Processes
0xffff….
Kernel space
User space
0x0000…
23
One Common Layout

Lots of flexibility
– Allows stack growth
– Allows heap growth
– No predetermined division

0xffff….
Kernel space
Stack
So what happens when you
make a system call?
OS Structure & Processes
Heap
Code & Data
0x0000…
24
Kernel Stack

Kernel contains functions
– Just like regular functions
– Automatic variables, formal parameters, etc
– They need a stack

Can we use the user’s stack?
– Is it possible?
– Is it desirable?
OS Structure & Processes
25
What Other Options Possible?

Remember the host/hostess scenario?
– What would happen if you had a break between
courses
– Can you apply this logic to the kernel?
– What are the tradeoffs?
OS Structure & Processes
26