*What is an operating system
OS objectives for design
program that manages computer hardware,
intermediary between user and pc hardware.
Provides a basis for application programs
-Convenient (easy to use)
-Efficient( resources )
-Ability to evolve -> permits effective development testing and introduction of new system functions
Role of operating System
Resource Allocator - OS must divide resources among programs and users efficiently(CPU time, file storage space)
Control Program - manages the execution of user programs to prevent errors and improper use of the various input/output devices
-Prevents 2 programs accessing CPU at same time
How does multiprogramming work
multiple programs can run simultaenously sharing CPU
-Subset of all available jobs is kept in memory, job runs until it requires I/O,. Then OS switches to next job which is selected by process scheduler
Multitasking
Difference between multiprogramming and multitasking
Execute multiple jobs by cycling through them quickly(used in interactive systems)
Multiporgramming usally switches program when I/O request recieved.
Multitasking regularly switches program at predefined , short intervals
Interrupts
Why they are important
Signal than an event has occured which needs to be dealt with
Interrupts are a way to start the OS running on the CPU so that it can take appropriate action.
Interrupts are typically used by user programs to specify a system call. For user program to ask the operating system to do a operation on its behalf.
Also interrupts can come from user programs if they do an illegal instruction.
Memory Sharing problem
How to ensure it
Applications should be protected from each other so they cannot change/read the data of another
Use memory mapper - checks the boundary of the program it is assign to in memory and ensures boundary is not violated. Uses memory manager to pass info
Protection of resources
user state- limited access to instruction set, memory and peripherals(resumes user programs to enter state). Applications run in this mode
special state - unrestricted access to the instruction set, memory and peripherals. OS runs in this mode
types of special states
-non interrutable state(time critical, technical reasons)
-interruptible (supervisor state)
System calls
Mechanism to allow user programs to convey their requirements to OS as user programs prevented from having access to many facilities of computer system
System calls are needed to ensure dangerous operations can only be done by OS.
How does OS control access to Processor?
Main memory of computer?
Peripheral devices
Processor can only be used by one program at a time and thus must be allocated failry to different programs.
System timer periodically causes a hardware interrupt, allowing the OS to run and take back control from program hogging cpu time.
-Main memory of computer must be protected since we dont want another program to be able to read/write another programs data. The memory mapper is hardware that each program does not violate its assigned memory bounds.
-Peripheral devices need control access as only certain Applications/groups should be able to perform dangerous instructions. Therefore user programs run in user state tp emsire they cannot interract with peripherals directly and must make a system call on the OS to access them.
How do programs in main memory work
What is base address
What is real address
What is limit value
each program resides in own memory section
They have real and virtual address.
Base address number where program start in memory
Real address is base address + virtual address
Virtual address is between 0 and size of program
The range size(amount of memory assigned to program)
Process placement techniques
OS maintains a table indicating which parts o fmemory are free/occupied
First Fit technique
Best Fit
Worst Fit
Place new program in the first large enough position in memory
Place in smallest hole large enough to hold program(leaves small leftover holes)
Place new program in largest hole.
What to do if there is no large enough space for new programs
Compaction : Move current programs to one contiguous block
Swapping : Existing program can be swapped temporarily out of main memory to backing store
Segmentation and advantages
Splitting program into segments(logical units)
Each program will have its own segment table which gives info about each egment(limit value, real adress)
Can run a program without having all its segments in memory
how to get real address
base adress + offset
Memory protection for segmentation
another advantage is each segment given own set of access rights
X - exectue ( this is like code)
R - read(Constants, Variables)
W - write(Varaibles)
Disadvantages of segmenttations
requires each individual segment occupies a contiguous area of memory so external fragmentation still occurs
Paging
program split up into pages and can contain any combination of instruction
All pages have same size
Virtual memory
Memory divided into fixed-size blocks called pages
Physical memory divided into fixed-size blocks called frames.
One page fits in one frame therefore avoids external fragmentation
How to load pages into memory
Each virutal address has 2 parts, virtual page # and offset into that page
The virtual page # are mapped to the physical page numbers using the page table.
States a program can be in
Running - Program Running. Can become blocked. Can become runnable if scheduler stops it.
Runnable- program could run if selected from schedulor. Cannot become blocked
Blocked - unable to run at this time. Could be waitiing for I/O operation to completed.
Tasks of the scheduler
Scheduler has list of all processes in main memory. (runnable ,blocked)
Scheduler scans list to find next program marked as Runnable.