程序代写 Operating Systems – CSCI 402

Operating Systems – CSCI 402
Ch 1: Introduction Bill Cheng
http://merlot.usc.edu/william/usc/
1
321 0
Copyright ý . Systems – CSCI 402
What are Operating Systems?
Possible definitions:
the code that {Microsoft, Apple, Linus, Google} provides the code that you didn¡¯t write
the code that runs in privileged mode
the code that makes things work
the code that makes things crash etc.
2
321 0
Copyright ý . Cheng

providing an “appropriate” interface for applications but abstraction to what exactly? (next slide)
What¡¯s an “abstraction” anyway?
think about “abstract data types” in a data structures class
it¡¯s data structures and associated functions to make something looks like it has some behavior
A list object has a sort() function
“objects” is the word we use to mean any data types (primitive, data structures, pointers)
can a list really sort itself?
of course not
we need to put the list under some sort of an
“execution context” in order to execute the sort() function
umm… what¡¯s a “context”?
well, it¡¯s hard to say exactly what it is at this time
321 0
Operating Systems – CSCI 402
Abstraction
Operating Systems
3
Copyright ý . Systems – CSCI 402
Hardware
disks
hard drives
optical drives
memory processors network
ethernet
modem
monitor keyboard mouse
Hardware
Disk Disk
Network
Application programs are not allowed to use hardware directly
that¡¯s why we have to provide abstractions
321 0
Copyright ý .
4

Application programs are not allowed to use hardware directly
that¡¯s why we have to provide abstractions
321 0
Operating Systems – CSCI 402
Hardware
disks memory processors network monitor keyboard mouse
OS Abstractions
Operating system
files (file system) programs (processes) threads of control communication windows, graphics input
locator
For those who knows about “processes”, we use the word “program” to mean “process” in the introductory material
5
Copyright ý . Systems – CSCI 402
OS Abstractions
The main focus of this class is about how to provide these abstractions
don¡¯t just “hack” it until it works
we will talk about OS design principles and show how these abstractions can be implemented
this class is more about the fundamentals and is not a “tech” class
Concerns
performance
time, space, energy
sharing and resource management failure tolerance
security
marketability
6
321 0
Copyright ý . Example: Files
Operating Systems – CSCI 402
Memory
Disk Disk
It¡¯s nice to have a simple abstraction
Abstraction did not come for free
it introduces problems that need to be solved and issues to be addressed
7
321 0
Copyright ý . Systems – CSCI 402
Issues With The Files Abstraction
Naming
device-independence
Allocating space on disk (permanent storage)
organized for fast access minimize waste
Shuffling data between disk and memory (high-speed temporary storage)
Coping with crashes
8
321 0
Copyright ý . Example: Programs
Application programmers use the Address Space abstraction: low memory
Operating Systems – CSCI 402
text (code)
data
dynamic (heap)
stack
address
Code
high memory address
Data
9
321 0
Copyright ý . Example: Programs
Application programmers use the Address Space abstraction:
Very important:
our address space is up-side-down (compared with the textbook)
low memory address
Code
Operating Systems – CSCI 402
text (code)
data
dynamic (heap)
stack
low address at the top high address at the bottom memory layout matches
an array
stack looks like a “stack”
our textbook does it the other way
Data
This is not the only possible memory layout
compiler decides!
high memory address
10
321 0
Copyright ý . Example: Programs
Operating Systems – CSCI 402
Memory
Disk Disk
text (code)
data
dynamic (heap)
stack
Application programmers do not have to worry about any sharing that¡¯s going on
11
321 0
Copyright ý . Memory
Does not appear to be very flexible
Operating Systems – CSCI 402
Memory Sharing Option 1
Program 1
Program 2
Program 3
Operating System
12
321 0
Copyright ý . Systems – CSCI 402
Memory Sharing Option 2
Program 1
Program 2
Program 3
Physical Memory
What if programs take up too much space (more than physical memory)?
13
321 0
Copyright ý . Memory
Operating Systems – CSCI 402
Program 1
Memory
Disk Disk
Program 2
virtual memory map
Program 3
Copyright ý . Cheng
part hardware, part OS each program thinks
it has its own full address space
14
321 0

Program 1
VA
VA: virtual address PA: physical address
Virtual Memory
Operating Systems – CSCI 402
PA
Memory
Disk Disk
Program 2
virtual memory map
Program 3
Copyright ý . Cheng
part hardware, part OS each program thinks
it has its own full address space
15
321 0

Operating Systems – CSCI 402
Sharing of Processor: Concurrency
If you only have one processor, how do you run multiple “programs” and every program thinks it owns the processor?
abstraction: threads (or “threads of execution”)
Virtual Processor Virtual Processor Virtual Processor (or thread) (or thread) (or thread)
Processor
How do you suspend a thread (save execution context) so you
can resume its execution later (restore execution context)?
16
321 0
Copyright ý . Cheng

but we need to worry about how well we do resource (processor) management/allocation
Operating Systems – CSCI 402
Sharing of Processors: Parallelism
What if you have a multicore processor or multiple processors?
we don¡¯t distinguish concurrency and parallelism in this class can still use threads
Virtual Processor (or thread)
Processor
Virtual Processor (or thread)
Processor
Virtual Processor (or thread)
Processor
321 0
17
Copyright ý . Cheng