All Lectures Flashcards
What are the goals of an OS?
- Allow user to use applications
- Allow applications to use computer resources
- Allow users and applications to interact
What are the three key abstractions of an OS?
Process
-Instance of a program
Memory (Address) Space
-The range of memory locations that a process can access
File
-A stream of data
How does each layer in the system implement its set of services?
It implements its services by using the layer below it and providing its services to the layer above it.
Identify and describe the two modes of the CPU
Supervisor (Kernel) mode:
- Access to all hardware, I/O and memory
- Can execute ALL CPU instructions
User mode:
- Program running on CPU is restricted from accessing all devices or memory
- Can only execute a restricted set of CPU instructions
What is the kernel?
O/S that is loaded into memory when the computer starts up.
Resides in memory at all times
Runs in supervisor mode
What are the roles that the kernel plays?
- protects the hardware and processes
- manages hardware and resources
- provides an execution environment for the processes
- creates and runs processes
- services process requests
Define process
A process is a running instance of a program in memory.
How does the kernel get control back from a process?
Through system calls and interrupts
What happens when there is an interrupt?
CPU switches to kernel mode. CPU uses an interrupt id to index into the interrupt table. Invokes interrupt handler, switches back to user mode, returns to where the process was before the interrupt.
What is the purpose of interrupts?
- Help the kernel gain control of the CPU
- Notify the kernel of I/O
- Help processes make requests to the kernel in a controlled way
- Notify the kernal of errors
How does the kernel get control of the CPU if no interrupts occur?
The timer.
What is the importance of the timer?
The timer allows the kernel to gain control of the CPU on a regular basis. No process can monopolize the CPU because kernel can switch to another process.
How do processes make requests to the kernel?
Using a trap (software interrupt).
What is context switching?
When an interrupt handler runs the current process has to be context switched out and the kernel context has to be context switched in
How does context switching work?
The handler copies all registers from CPU to memory, initializes all registers to what the kernel expects, switches to the kernel stack, runs the handler
To switch back:
Switches to the processes stack, copies registers from memory to the CPU, returns from where the process left off
What is a process composed of?
CPU context
•Memory space
•Thread of executtion
Describe the CPU context of a process
General registers,
Program counter
Special purpose registers
Describe the memory space of a process
Stack: local variables and return addresses
Heap: dynamically allocated memory
Data: global and static variables
Code: program code
Describe the 5 process states.
New: process created Ready: ready to run Running: running on the CPU Blocked: waiting for a service Terminated: killed and needs to be cleaned up
Describe the various process transitions
New->ready: admitted to scheduler
Ready->running: dispatched by the scheduler
Running->ready: interrupt due to timer or I/O
Running->blocked: service request (system call)
Blocked->ready service request completion
Running-> terminated: exit or kill
How is a new process created?
Process creation is initiated by a process and performed by the kernel.
Parent process makes a fork() call and then the kernel
-makes a copy of the parent
-allocates a new PCB and PID
-copies parent’s PCB to new PCB
-sets new PID
-Marks new process as ready
-Sets return value of parent process to child PID
-Sets return value of child process to 0
What is the ready queue?
An abstract queue which stores pointers to PCBs in the order that the processes are scheduled to run
What is a scheduler?
The scheduler is responsible for deciding which process to run next. The scheduler is called by the OS whenever a process related event occurs
What is the goal of the scheduler?
Maximize CPU utilization and Throughput. Minimize turnaround time, waiting time, and response time