OG DECK Flashcards
What is an operating system?
An operating system is the software layer that manages a computer’s resources for its users and their applications.
What happens when you run a program?
CPU:- Fetches instructions stored in exe file- Loads data stored in exe file- Decodes and executes the instructions- Stores result to memory
What are the jobs of an OS?
- Allocates memory- Manages memory- Manages CPU- OS provides process abstraction- Manages devices- Basically manages hardware and provides process abstraction.- OS also allows you to communicate with the computer without knowing how to speak the computer’s language.
What are the design goals of an operating system?
- Convenience| - Efficiency of usage of CPU, memory etc.
Explain short: What is the goal of process abstraction?
The goal of process abstraction is to run multiple processes concurrently, by time sharing the cpu. We then need mechanisms (context switch) and policy(scheduler). This makes the illuision that each program has it’s own isolated machine.
What is virtualization of the CPU?
- It involves a single cpu acting as if it were multiple seperate CPUs- Enables users to run many concurrent programs
What can a program read and update when it is running?
- Memory (Data that the running program reads/writes is in memory)- Register (Because many instructions read/update the registers)
What is I/O?
I/O stands for input and output and is reffered to devices connected to a computer. This could be a mouse and keyboard.
Which states can a process be? Explain them| Give the possible transitions between the three states.
- Running: Process is running on a processor, executing instructions - Ready: process is ready to run , but Os has chosen not to run it at this given moment - Blocked: process har performed some operation that makes it not ready to run until some other event takes place. For example: when a process initiates an I/O request to disk or network, it becomes blocked and thus some other process can use the processor. Running to ready: OS preempts the running process.Running to Blocked: Process makes system call to innitiate IOReady to running: OS schedules process to run next.Blocked to ready: IO requested by process is done.- New- Dead
Which data structure is where the operating system keeps the program counter, stack pointer and other information about a process.
PCB (process control block)
What does a PCB (process control block) contains?
- Process identifier- Process state- Pointers to other related processes (parent)- CPU context of the process (saved when the process is suspended)- Pointers to memory location- Pointers to open files
What does API stand for?
Application programming interface (API)
Why do we have an API in the OS?
- The API contains sets of system calls, including create, wait and destroy.- System call is a function call into OS code that runs at a higher privilege level of the CPU- There are usually interfaces to get some status information about a process as well, such as how long it has run for, or what state it is in.-Makes it possible for all services in the operating system to communicate.
What does fork() do?
- Creates a new child process - All processes are created by forking from a parent - The init process is ancestor of all processes
What does exec() do?
In computing, exec() is a functionality of an operating system that runs an executable file in the context of an already existing process, replacing the previous executable.
What does exit() do?
Exit() terminates a process
What does wait() do?
Wait() causes a parent to block until child terminates/exits or a signal is received.
What happens during fork()?
- A new process is created by making a copy of parent´s memory image- The new process is added to the OS process list and scheduled- Parent and child start execution just after fork (with differnet return values)- Parent and child execute and modify the memory data independently
What happens during wait()?
- Terminated process exist as a zombie.- The parent process is then supposed to execute the wait() system call to read the dead process’s exit status and other information.- This allows the parent process to get information from the dead process. After wait() is called, the zombie process is completely removed from memory.- When a parent calls wait(), zombie child is cleaned up or “reaped”- Wait() block in parent until child terminates (non-blocking ways to invoke wait)- What id parent terminates before child? Init process adopts orphans and reaps them
What happends during exec()?
- A process can run exec() to load another executable to its memory image- So a child can run a different program from parent- Variants of exec() to pass commandline arguments to new executable
What different modes can an OS run a executable from?| Which two modes does the OS have?
User and kernel mode
What is kernel mode?
- It enables the OS to run system calls- Kernel does not trust user stack- Kernel does not trust user provided addressesIn Kernel mode, the executing code has complete and unrestricted access to the underlying hardware. It can execute any CPU instruction and reference any memory address. Kernel mode is generally reserved for the lowest-level, most trusted functions of the operating system. Crashes in kernel mode are catastrophic; they will halt the entire PC.
When is trap function called?
- System call (program needs OS service)- Program fault (program does something illegal, e.g. access memory it doesn´t have access to)- Interrupt as external devices needs attention of OS (e.g. network packet has arrived on network card)
What is a trap function?
It is a software interrupt generated by the user program or by an error when the operating system is needed by it to perform the system calls or an operation
What are the two types of scheduler?
Preemptive and non preemptive
What are the difference between Preemptive and non-Preemptive schedulers?
Non preemtive schedulers are polite: - Switch only if process blocked or terminated - Once resources are allocated to a process, the process holds it till it completes its burst timr or switches to waiting state.Preemptive (non-cooperative) schedulers can switch even when process is ready to continue: - CPU generates periodic timer interrupt and the resources are allocated to a process for a limited time - After servicing interrupt, OS check if the process has run for too long
What is a context switch?
For example when a process switches from user to kernel mode. It then saves context (PC, registers, kernel stack, pointer) of process on kernel stack
What is SJF (shortest-job-first)?
It runs the shortest job available, not preemptive
What is FIFO (first-in first-out)?
It runs the process with the shortest arrival time
What is RR (round-robin), and how does it work?
A scheduling algorithm.| It runs each process on a given time quatum. This could be 2ms.
What is a CPU burst?
The CPU time used by a process in a continuous stretch
Why do we want to have a scheduler?
- Maximize utilization (fraction of time cpu is used)- Minimize average (turnaround time = time from process arrival to completion)- Minimize average (response time = time from process arrival to first scheduling- Fairness: all processes must be treated equally- Minimize overhead: run process long enough to amortize cost of context switch ( 1 microsecond)
What is stride scheduling?
- Every process gets a ticket valueStride = ticket/high number(e.g. 1000 or 10000)Pass += strideValue- OS runs the process with the lowest stride value- If pass-value of multiple processes are equal, the one with the lowest stride value goes first.- If both the pass-value AND stride value is the same, the process that entered the scheduling que first gets to run first.
What is the formula on turnaround time?
Tturnaround = Tcompletion - Tarrival
What is turnaround time?
Performance metric for scheduler policy. Often the better the metric the less fair the scheduler is.Turnaround time is the time from the process arrives at the queue to the time it is done/finished.
What is the formula on response time?
Tresponse = Tfirstrun - Tarrival
Positives and negatives of SJF
- Optimal for turnaround time| - Can get stuck behind a large job (convoy effect)
Positives and negatives of RR
- Good for response time and fairness- Bad for turnaround time- Time quatum > context switch
Why is it difficult to create a good scheduler?
Turnaround time and response time:| Both are bad where the other is good
What is multi level feedback queue(MLFQ)?
It contains different levels of priority that a process is assigned, and each process are ran using RR. First a process is ran at the highest priority and if not done it moves down. This continues to the process is done.If priority A > priority B, A runsIf priority A = Priority B , they run in round robin,
What are some of the problems with multi level feedback queue(MLFQ)?
Starvation: If there are to many interactive jobs they will combine to consume a lot cpu time, preventing long running jobs from getting any cpu time, so they starve.
What can we done in MLFQ to prevent starvation?
Periodically boost the priority level of all jobs. For a given time slice we can move all jobs to the highest priority queue.
What is lottery scheduling?
Each process gets different amount of tickets and an OS chooses a ticket. The process that has that ticket can run for a given time.
How do we calculate fairness in a scheduler?
U = tCompletionA / tCompletionB (1 = perfect)
What is the difference between lottery scheduler and stride scheduler
Stride scheduler is deterministic
What is the advantages and disadvanages of using randomness in a scheduler?
Negative: - May not deliver the exact desired proportions- A major drawback of the lottery scheduling algorithm is that it is inherently unpredictable. Due to the random nature of the scheduler, there is no way for OS designers to know for sure what will happen in lottery scheduling, possibly producing undesirable resultsPositive: - Fairness - Avoid corner cases- Lightweight for the OS
Why do we virtualize memory?
Virtual memory serves two purposes: - First, it allows us to extend the use of physical memory by using disk. - Second, it allows us to have memory protection, because each virtual address is translated to a physical address.
What does virtual address space contain?
Contains program code, heap and stack
Why do we use virtual address space
To be able to locate where in physical memory the data is stored. It is translated from Virtual Address to Physical Address
What component does the translation of virtual to physical address?
MMU (memory-managment unit)
What is the goal of virtualization?
- Transparency: user programs should not be aware of the messy details- Efficiency: minimize overhead and wastage in term of memory space and access time- Isolation and protection: A user process should not be able to access anything outside its address space
Does the OS have its own address space? If not where is it?
- OS is not separate process with its own address space- Instead, OS code is part of the adress space of every process- A process sees OS as part of its code (library)- Page table map the OS addresses to OS code
What does the stack contain?
- Keep track of where the process is in the function call chain- Allocate local variables of functions- Pass parameters to functions- The return value from functions- Return address: Where to continue executions after a function call
What does the heap contain?
- Global variables- Malloc() and free() in C- New() in java/C++/GO
What does malloc() do?
Allocates x amount of memory
What does free() do?
free(x) where x is the pointer to the memory returned by malloc. It frees the allocated memory
What are the procedures during address translation?
- OS tells what base(starting address) and bounds(end address) values- MMU does the calculation- If out of bounds a trap execution is called
What is the role of OS in address translation?
- OS maintains free list of memory- Allocates space to process during creation and cleans up when done- Maintains information of where space is allocated to each process (in PCB)- Sets address translation information in hardware- Updates this information upon context switch- Handles traps due to illegal memory access
What is the role of hardware in address translation?
The CPU provides privileged mode of execution, this makes it so the instructions set has priviliged instructions to set translation information (base and bounds). Then the Hardware(MMU) uses this information to perform translation on every memory access (instruction fetch, load or store)If the translation is illegal, the MMU generates traps to OS(eg, VA is out of bounds)
What is the formula for physical address
PA = base register + VA
What are the problems with base and bounds?
If stack and heap are small, space between them is wasted. This is called internal fragmentation.This is caused by fixed size slots (due to our assumptions as same size address space). - Requires a big chunk of free space in the middle
What differs segmentation from basic address space?
- It gives us the flexability with multiple base/bounds pairs- The idea is one pair for each logical segment of the address space, which includes code, stack and heapNo internal fragmentation in segmentation.
How does the virtual address know which segment contains what (segmentation storing)?
Using the two first bits"00" = Code"01" = Heap"10" = Stack"11" = Unused
How can processes share memory (segmentation)
Protection: - A few extra bits per segment- Read, wrtite, execute- Each process still thinks that is accessing its own private memory- While the OS is secretly sharing their memory- HW must then check if a particular access is permissible
Why do we use segmentation?
- Unused space between stack and heap need not be allocated in physical memory- Allowing for more address spaces in physical memory we can use segmentation
What are the problems with free space managment within segmentation?
Physical memory becomes full of holes of free space (external fragmentation)
What is external fragmentation?
Physical memory becomes full of holes of free space (external fragmentation)
What is a solution to external fragmentation within segmentation?
One solution: - compacting physical memory be rearranging segments- Stop process one by one, move segment, update segment registers (point to new location)- Very memory intensive and use of process time
Is there a better approach to avoid external fragmentation with segmentation?
- Use a free list management algorithm- Keep large extents of memory available for allocation- Ex: best fit algorith - keeps list of free spaces - returns the one closest in size that satisfies desired allocation to the requesterBest fit:Search free list of memory chunk closest to requested size.
What are the benefits of segmentation?
- Support sparse address spaces (address spaces with a lot of emty spaces)- Avoid wasting memory between logical segments of an address space- Fast translation- Code sharing- No internal fragmentation
What are the problems with segmentation?
- Free memory gets left as odd sized pieces (external fragmentation) (does not happen with paging)- Memory allocation difficult (many smart algorithms)- Fundamentally hard to avoid external fragmentation- Not flexible enough, to support fully generalized sparse address space- If heap is sparsely used - must keep entire heap in memory