Download COP4610 Operating Systems Exam 1 Study Guide and more Exams Social Sciences in PDF only on Docsity!
COP4610 EXAM 1 STUDY GUIDE
Operating system - Answer -- Acts as an intermediary between the user and the computer hardware.
- Software that manages the computer hardware.
- Purpose is to provide an environment in which a user can execute programs in a convenient and efficient manner.
- A virtual machine that hides the complexity and limitation of hardware from application programmers History Phase I: Expensive Hardware, Cheap Humans - Answer - Hardware: mainframes OS: human operators
- Handle one job (a unit of processing at a time.
- Computer time wasted while operators walk around the machine room. Batch system - Answer - Collects a batch of jobs before processing them and printing out results.
- collection, processing, and printing out results can occur concurrently. Job - Answer - A unit of programming Batch System - Answer - Collects a batch of jobs before processing them and printing out results Timeshares - Answer - Each user can afford to user terminals to interact with machines OS Design goals: - Answer - Efficient use of the hardware More efficient use of human resources Allow a user to perform many tasks at one time Ease of resource sharing between machines Four phases of OS history - Answer - Hardware expensive, humans cheap Hardware cheap, humans expensive Hardware very cheap, humans very expensive Distributed systems Multiprocessing - Answer - The ability to use multiple processors on the same machine
Multitasking - Answer - Ability to run multiple programs on the same machine Multiprogramming - Answer - Multiple programs can run concurrently Benefits of concurrency - Answer - Can run multiple programs simultaneously Better resource utilization Better average response time Better performance Thread - Answer - A sequential execution stream Address space - Answer - Contains all necessary states to run a program Process - Answer - An address space and at least one thread of execution Difference between process and program - Answer - A program is just a collection of statements, a process is a running instance of a program. Uniprogramming - Answer - Running one process at a time Multithreading - Answer - having multiple threads per address space Dispatching loop - Answer - Run thread Save States Choose new thread Load states from new thread Context switch - Answer - Switching the CPU from one thread/process to another Thread state diagram - Answer - Ready - > Running - > Blocked - >Ready etc. Ready-> Running: Scheduled Running-> Ready: yield, timer Running - > Blocked: I/O request Blocked - > Ready: IO complete Amdahl's Law - Answer - S = %of sequential computations N = cores x = 1/(S + (1-S/N)) Booting sequence - Answer - Jump Load from BIOS
Round Robin - Answer - Jobs take predetermined length turns on the CPU. Shorter response time, fair sharing of cpu not all jobs preemptive, not good for jobs of the same length Preemptive Shortest Job first - Answer - Non preemptive Runs whichever job is shortest first. Runs best when jobs are usually short, degradation for longer jobs. Turns into FIFO if jobs are the same length. Shortest time remaining first - Answer - Preemptive version of shortest job first. Short jobs do not get stuck behind anything under SRTF Multilevel Feedback Queue - Answer - Uses multiple queues with different priorities Round robin: Run highest priority jobs first. Jobs start in highest priority. If time expires they go down, if time does not expire they go up. Approximates SRTF, CPU jobs lose priority, I/O jobs stay near the top. Counter measure: Aging Lottery Scheduling - Answer - Adaptive approach to address fairness. Every process is given a number of tickets based on its size, shorter jobs get more. Every time slice a random "ticket" is chosen. Each job gets at least one ticket Atomic operation - Answer - An atomic operation runs to completion, it is all or nothing Race conditions - Answer - occur when threads share data and their results depend on the timing of their executions Independent Threads - Answer - No states shared with other threads Deterministic computation Reproducible Cooperating threads - Answer - Shared states Non deterministic Non reproducible Why?
Shared resources Speedup from using different resources Modularity Mutual Exclusion - Answer - Ensures one thread can do something without the interference of other threads Critical section - Answer - A piece of code that only one thread can execute at a time Code verification - Answer - Test arbitrary interleaving of locking and checking locks. Difficult to verify as two threads have different code, difficult to generalize to N threads Busy Waiting - Answer - Hogging CPU cycles while a thread is waiting for a lock. Can be avoided with a waiting queue Ways to implement locks - Answer - High level atomic operations: locks, semaphores, monitors, send/receive Low level atomic operations: load/store, interrupt disables, test and set Semaphore - Answer - Type of generalized lock consisting of a nonnegative integer value and two operations P() waits for the semaphore to become positive then decrements it by one V() increments semaphore by 1 and wakes up a thread at P() Semaphores vs Integers - Answer - No negative values Only operations are P() and V() Operations are atomic. Two uses of semaphores - Answer - Mutual exclusion Scheduling, semaphore usually has an initial value of 0 Safety - Answer - Mutual exclusion, only one thread is in the critical section at a time Shared resources protected Locks are acquired at entrance to Liveness - Answer - Progress. If more than one thread is interested in executing the critical section, some processes will eventually do so (deadlock free)
- address of the block passed as a parameter in a register
- Stack
- parameters placed, or pushed, onto the stack by the program
- popped off the stack by the operating system Execve System Call on Linux - Answer - 1. Store syscall number in tax
- Save arg 1 in ebx, arg 2 in ecx, arg 3 in edx
- Execute int 0x80 (or sysenter)
- Syscall runs and returns the result in eax Types of System Calls - Answer - 1. Process Control
- File Management
- Device Management
- Information Management
- Communications Operating System Structures: - Answer - 1. Simple Structure
- Layered Structure
- Modules
- Microkernel System Structure
- Research Structure: exo-kernal, multi-kernal Simple Structure - Answer - No Structure at all!
- written to provide the most functionality in the least space Layered Structure - Answer - 1. The OS is divided into a number of layers (levels)
- Each layer on top of lower layers
- The bottom layer (layer 0), is the hardware
- The highest layer is the UI UNIX - Answer - 1. Limited by hardware functionality, the original UNIX had limited structure
- UNIX OS consists of two separable layers
- systems programs
- the kernel: everything below the system-call interface and above physical hardware
- a large number of functions for one level: file systems, CPU scheduling, memory management ...
- Interdependency of components makes it impossible
to structure kernel strictly in layers Modules - Answer - Most modern operating systems implement kernel modules:
- uses object-oriented design pattern
- each core component is separate
- some are loadable as needed Overall, similar to layers structure but more flexible Microkernel System Structure - Answer - Microkernel moves as much from the kernel (e.g., file systems) into "user" space Communication between user modules uses message passing Benefits:
- easier to extend a microkernel
- easier to port the OS to new architectures
- more reliable (less code running in kernel mode)
- more secure Detriments:
- performance overhead of user space to kernel space communication Virtual Machines - Answer - 1. A VM takes layered approach to its logical conclusion
- a virtual machine encapsulates the hardware and whole software stack
- VM provides an interface identical to the underlying hardware
- Host creates the illusion that the guest has its own hardware
- Each guest is provided with a virtual copy of underlying computer
- Multiple (different) operating systems can share the same hardware
- each VM is isolated from each other
- sharing of resource can be permitted and controlled
- commutate with each other and other physical systems via networking
- Benefit
- consolidate low-resource use systems to fewer busier systems
Process Scheduling - Answer - To maximize CPU utilization, kernel quickly switches processes onto CPU for time sharing Process "scheduler" selects among available processes for next execution on CPU Kernel maintains scheduling queues of processes:
- job queue: set of all processes in the system
- ready queue: set of all processes residing in main memory, ready and waiting to execute device queues: set of processes waiting for an I/O device Schedulers - Answer - 1. Long-Term Scheduler (Job Scheduler)
- selects which processes should be brought into the ready queue
- invoked very infrequently
- controls the degree of multiprogramming
- Short-Term (CPU Scheduler)
- selects which process should be executed next and allocates CPU
- invoked very frequently
- sometimes the only scheduler in a system
- Mid-term Scheduler
- swap in/out partially executed process to relieve memory pressure Scheduler needs to balance the needs of:
- I/O-bound process
- spends more time doing I/O than computations many short CPU bursts
- CPU-bound process
- spends more time doing computations
- few very long CPU bursts Context Switch - Answer - When the kernel switches to another process for execution Steps:
- Save the state of the old process
- load the saved state for the new process Note: CPU does no useful work during context switch so overhead is introduced. Context switch time depends on hardware support
Process Creation - Answer - Parent process creates children processes, which, in turn create other processes, forming a tree of processes The process is identified and managed via a process identifier (pid) Design Choices for Process Creation - Answer - 1. Resource Sharing
- three possible levels: all, subset, none
- Parent and children's address spaces
- Execution of parent and children
- fork creates a new process
- exec overwrites the process' address space with a new program
- wait waits for the child(ren) to terminate Forking Separate Process Program: - Answer - #include <sys/types.h> #include <studio.h> #include <unistd.h> int main() { pid_t pid; pid = fork(); if (pid < 0) { fprintf(stderr, "Fork Failed"); return - 1; } else if (pid == 0) { /* child process / execlp("/bin/ls", "ls", NULL); } else { / parent process */ wait (NULL); printf ("Child Complete"); } return 0; } Process Termination - Answer - 1. Process executes last statement and asks the kernel to delete it (exit)
- OS delivers the return value from child to parent (via wait)
- process' resources are deallocated by operating system Parent may terminate execution of children processes (abort), for example: - Answer -
- child has exceeded allocated resources
- task assigned to child is no longer required
Require parent-child relationship between communicating processes Named Pipes - Answer - 1. Named pipes are more powerful than ordinary pipes
- communication is bidirectional
- no parent-child relationship is necessary between the processes
- several processes can use the named pipe for communication Why Threads? - Answer - 1. Multiple tasks can be implemented by threads
- Process creation is heavy-weight while thread- creation is light-weight
- Threads can simplify code and increase efficiency Threads - Answer - A thread is an independent stream of instructions that can be scheduled to run as such by the kernel Threads exist within the process, and shares its resources Each thread has its own essential resources Access to shared resources need to be synchronized Threads are individually scheduled by the kernel Each thread has its own independent flow of control Each thread can be in any of the scheduling states Thread Benefits - Answer - 1. Responsiveness
- Resource Sharing (efficient communication)
- Economy (more light-weight than a process)
- Scalability (better utilization) Implementing Threads - Answer - Threads may be provided either at the user level, or by the kernel Multithreading models: ways to map user threads to kernel threads Many-to-one model:
- Many user-level threads mapped to a single kernel thread
- thread management is done by the thread library in user space (efficient)
- entire process will block if a thread makes a blocking system call
- multiple threads are unable to run in parallel on multi-processors One-to-one model: Each user-level thread maps to one kernel thread
- It allows other threads to run when a thread blocks
- Multiple thread can run in parallel on multiprocessors
- Creating a user thread requires creating a corresponding kernel thread, but creates overhead Most OS implementing this model limit the number of threads Many-to-many model: Many user level threads are mapped to many kernel threads
- It solves the shortcomings of 1:1 and m:1 model
- Developers can create as many user threads as necessary
- Corresponding kernel threads can run in parallel on a multiprocessor Pthreads - Answer - A POSIX standard API for thread creation and synchronization Threading Issues - Answer - 1. Semantics of fork and exec system calls
- Thread cancellation of target thread
- Signal handling
- Thread pools
- Thread-specific data
- Scheduler activations Thread Cancellation - Answer - Asynchronous cancellation: terminates the target thread immediately
Throughput: # of processes that complete execution per time unit Turnaround time: the time to execute a particular process from the time of submission to the time of completion Waiting time: the total time spent waiting in the ready queue Response time: the time it takes from when a request was submitted until the first response is produced Scheduling Algorithms - Answer - First-come, first-served scheduling Shortest-job-first scheduling Priority scheduling Round-robin scheduling Multilevel queue scheduling Multilevel feedback queue scheduling Thread Scheduling - Answer - OS kernel schedules kernel threads System-contention scope - Answer - competition among all threads in system Multiple-Processor Scheduling - Answer - Approaches to multiple-processor scheduling: Asymmetric Multiprocessing
- only one processor makes scheduling decisions
- other processors act as dummy processing units Symmetric Multiprocessing
- scheduling data structure are shared
- needs to be synchronized
- used by common operating systems Multicore Processors - Answer - Multicore processor has multiple processor cores on same chip Multicore processor may complicate scheduling due to memory stall Memory Stall - Answer - when access memory, a process spends a significant amount of time waiting for the data to become available Solution: multithreaded CPU core
- share the execute unit, but duplicate architecture states (registers) for each CPU thread Solaris - Answer - Priority-based scheduling with six available classes:
- time sharing (default)
- interactive
- real time
- system
- fair share
- fixed priority Each class has different priorities and scheduling algorithms Higher numbers indicates a higher priority Linux Scheduling - Answer - Algorithm Evaluation - Answer - How to select a CPU-scheduling algorithm for an particular system? Evaluation Methods:
- Deterministic Modeling
- take a particular predetermined workload
- define the performance of each algorithm for that workload
- Queueing Models
- using queueing network analysis
- Simulation
- trace tape: monitor a real time system and record sequence of actual events and use it to drive the simulation Critical Section - Answer - Each process has a critical section segment of code to change common variables, update tables, write file...etc Only one process can be in the critical section Solution to Critical-Section - Answer - Mutual Exclusion:
- only one process can execute in the critical section Progress:
- if no process is executing in its critical section
- there exist some processes that wish to enter their critical section
- these processes cannot be postponed indefinitely
- only these processes participate in the decision of who to enter CS
Priority Inversion - Answer - a higher priority process is indirectly preempted by a lower priority task Bounded-Buffer/Producer-Consumer Problem - Answer - Two processes, the producer and the consumer share n buffers:
- the producer generates data, puts it into the buffer
- the consumer consumes data by removing it from the buffer The problem is to make sure:
- the producer won't try to add data into the buffer if its full
- the consumer won't try to remove data from an empty buffer Solution:
- n buffers, each can hold one item
- semaphore mutex initialized to the value 1
- semaphore full initialized to the value 0
- semaphore empty initialized to the value N Producer-Consumer Solution Code - Answer - The producer process: do { //produce an item ... wait(empty); wait(mutex); //add the item to the buffer ... signal(mutex); signal(full); } while (TRUE) The consumer process: do { wait(full); wait(mutex); //remove an item from buffer ... signal(mutex); signal(empty); //consume the item ... } while (TRUE); Readers-Writers Problem - Answer - A data set is shared among a number of concurrent processes readers: only read the data set; they do not perform any updates
writers: can both read and write The readers-writers problem:
- allow multiple readers to read at the same time (shared access)
- only one single writer can access the shared data (exclusive access) Monitors - Answer - Monitor is a high-level abstraction to provide synchronization Monitor is an abstract data type:
- similar to classes in object-oriented programming
- internal variables only accessible by code within the procedure Only one thread may be active within the monitor at a time!!! Monitor Problems - Answer - Monitor can provide mutual exclusion
- only one thread (process) can be active within a monitor Threads may need to wait until some condition P holds true Busy waiting in monitor does not work
- only one thread can be active within a monitor ➱
- if it busy-waits, others cannot enter monitor ➱
- condition P may rely on other thread's operations Solution: condition variable Condition Variable - Answer - a waiting queue in monitor, on which a thread may wait for some condition to become true Two operations on a condition variable:
- wait: suspend the calling thread until signal
- signal: resumes one thread(if any) waiting on the CV Protection - Answer - Ensures that OS object is accessed correctly and only by those processes that are allowed to do so A computer consists of a collection of objects, in hardware or software. Each object:
- has a unique name
- can be accessed through a well-defined set of operations