Midterm review Flashcards
What are the key roles of an operating system?
To hide the complexity of the underlying hardware from applications (abstraction), manage the state of that hardware according to predefined policies (arbitrate), and ensure that those applications are isolated and protected from one another.
What is an OS abstraction? Give examples.
OS abstractions are techniques used to hide the underlying details of hardware by providing an API that is simpler to reason about than reasoning about the underlying hardware directly. Examples: process, thread, file, socket, memory page
What is an OS mechanism? Give examples.
Mechanisms are functionality provided by the operating system to do certain things with the hardware that can be used to implement policies. A mechanism is how something can be done. Examples: create, schedule, allocate
What are OS Policies? Give examples.
Policies are the behavior defined for the operating system to have that can be implemented using the operating system’s provided mechanism. A policy is what/which should be done. Examples: least recently used (LRU), earliest deadline first (EDF)
What does the principle of separation of mechanism and policy mean?
This entails a separation between how we specify what should be done and how it is done. This separation is important for flexibility, because policies are likely to change. Mechanisms insensitive to policy changes are more desirable because they allow for policy to change more easily.
What does the principle of the “optimize for the common case” mean?
Operating systems are likely to be used for a specific use case. By knowing more information about this use case, one can design the system in such a way that this use case performs well. There is more benefit in trying to make this use case run as smoothly as possible than trying to write a system that is not aware of this use case and does not take advantage of its details. There is an opportunity to improve performance by knowing how the system will be used and selecting policies accordingly.
What happens during a user-kernel mode crossing?
This crossing is done when a user program attempts to execute a privileged instruction. This will cause a trap to occur.
What are some of the reasons why user-kernel mode crossing happens?
Because the privileged instructions are only allowed to the OS. User process doesn’t know how the hardware resources are managed and if it want to directly access and modify the hardware state, it is most likely to affect other processes in bad way. Because of this reason, such attempts are forbidden and must go through the OS to do the work on behalf of the user process. Such action is done by system call and the system calls require the user-kernel boundary crossing.
What is a kernel trap?
A kernel trap is when a user application is interrupted, and control is switched to the kernel at a specific location.
Why does a kernel trap happen?
A trap is caused by a user program’s attempt to perform a privileged instruction.
What are the steps that take place during a kernel trap?
During a kernel trap, the kernel switches control to the OS and the OS checks why the trap occurred, and determines whether to execute the instruction that caused the trap, or to terminate the process.
What is a system call?
A system call is an interface provided by the OS for providing privileged instructions on behalf of a user program.
How doe a system call happen?
To make a system call, an application must write arguments to a well defined location and use the specific system call number to make the call.
What are the steps that take place during a system call?
During a system call, the kernel will execute a privileged instruction on behalf of the user. System calls are expensive because any user application data will be removed from the cache and replaced by kernel data, i.e. context switch occurs each time the boundary is crossed.
What are the pros and cons of a monolithic OS design?
Pros: single codebase allows for compile-time optimizations. Cons : customization, portability, manageability, memory footprint, performance
What are the pros and cons of a modular OS design?
Pros: more maintainable than a monolith, smaller footprint, less resource intensive, customization Cons: indirection can impact performance, maintenance can still be an issue
What are the pros and cons of a microkernel OS design?
Pros: small, lower overhead, better performance, easy to verify and test Cons: low portability, specialized, leads to software complexity, frequent user/kernel crossing
Describe the distinctions between a process and a thread.
A process is represented by its address space (i.e. code/data/files). The process is also represented by its execution context (i.e. regs/stack) that contains information about the values of the registers, the stack pointer, program counter, etc. A thread is very much like a separate process, except for one difference: they share the same address space and thus can access the same data.
Compare a process context switch to a thread context switch
Because threads share an address space, the context switch among them happens faster than processes. So, processes take longer to context switch. Both threads and processes have their execution context described with stack and registers. Because threads share the virtual address space, it is more likely that when multiple threads execute concurrently, the data that’s needed by one thread is already in the cache, brought in by another thread. So, they typically result in hotter caches.
What states are there in the lifetime of a process?
Running, Ready, Blocked(Wait), also New and Terminated
Describe the process state: Running
In the running state, a process is running on a processor. This means it is executing instructions. Being moved from ready to running means the process has been scheduled. Being moved from running to ready means the process has been descheduled.
Decribe the process stage: Ready
In the ready state, a process is ready to run but for some reason the OS has chosen not to run it at this given moment.
Describe the process state: Blocked (or Waiting)
In the blocked state, a process has performed some kind of operation that makes it not ready to run until some other event takes place. A common example: when a process initiates an I/O request to a disk, it becomes blocked and thus some other process can use the processor.
Describe the process state: New
Process is created. OS performs admission control. If it is determined to be OK, OS allocates and initializes PCB.
Describe the process state: Terminated
The process has completed its work or ends up with an error.
Draw the process lifecycle
Describe the lifetime of a thread
Describe all the steps which take place for a process to transition from a waiting (blocked) state to a running (executing on the CPU) state.
Once a process has become blocked (e.g., by initiating an I/O operation), the OS will keep it as such until some event occurs (e.g., I/O completion); at that point, the process moves to the ready state again (and potentially immediately to running again, if the OS so decides).
What are the pros-and-cons of message-based vs. shared-memory-based IPC.
Message-based IPC
Pros: OS managed, messages share APIs and system calls
Cons: overhead, all information that we want to pass is copied
Shared-memory-based IPC
Pros: OS is not in the path of communication, no OS overhead
Cons: no fixed and well defined APIs, more error prone