硬件基础
- BIOS:Basic Input Output System
- PC(program counter) SP(stack pointer)
- CS:IP code segment : instruction pointer.
- .s source code files written in assembly
Overview
Compare of cs61c and cs162
- Processor – Thread
- Memory – Address Space
- Disks,SSDS,… – Files
- Networks – Sockets
- Machines – Processes
Instruction Fetch/Decode/Execute
Four fundamental OS concepts
- Thread: Single unique execution context(Fully desribes program state)
- Address space: set of memory address accessible to program(r/o)
- Process: an instance of a running program(protected address space+ >=1 threads)
- Dual Mode operation/Protection(only the “system” has the ability to access certain resources)
主课
Thread
Concept
- 3 states
- running
- ready – eligible to run, but not currently running
- blocked – ineligible to run (e.g.waiting for an I/O to finish)
- Concurrency vs parallelism
- Concurrency is about handling multiple things at once
- Parallelism is about doing multiple things simultaneously
- Parallel => concurrent, but not the other way round!
Networked servers must handle concurrent requests
Parallel programs must parallelise for performance
Concurrency
-
run two threads concurrently
- Scheduler is free to run threads in any order and interleaving
- Thread may run to completion or time-slice in big chunks or small chunks
-
Multiprocessing vs multithreading
- Multiprocessing: Multiple CPUs(cores)
- Multithreading: Multiple threads/processes
Address Space
Simple Address translation with base and bound
Process
Thread encapsulate concurrency
Address spaces encapsulate protection
Interrupt
Example:web server
UNIX process management
-
fork – system call to create a copy of the current process, and start it running
- No arguments!
-
exec – system call to change the program being run by the current process
- example: shell程序先copy原有shell然后清除
-
wait – system call to wait for a process to finish
-
signal – system call to send a notification to another process
Dual Mode Operation
Unix structure
3 types of user
→
\rightarrow
→kernel mode transfer
- syscall
- process requests a system service,e.g.,exit()
- like a function call, but “outside” the process
- interrupt
- external asychronous event triggers context switch
- e.g.,timer, I/O device
- trap/exception
- internal asychronous event in process triggers context switch
- e.g.,protection violation(segment fault),divide by zero