Understanding Starvation in OS
Understanding Starvation in OS
A semaphore is a synchronization tool used to control access to shared resources in concurrent systems. Semaphores can be of two types: counting semaphores, which allow a certain number of processes to access a resource, and binary semaphores (mutexes), which allow only one process at a time. In the reader-writer problem, semaphores can manage access such that multiple readers or a single writer can access the resource, but not both. A semaphore ensures mutual exclusion by allowing readers to read concurrently, blocking writers, while ensuring that writers have exclusive access when writing, thereby maintaining data consistency .
Demand paging is a memory management scheme whereby pages are loaded into memory only when a process requires them, reducing unnecessary memory usage by not pre-loading all pages. This scheme enhances memory efficiency by freeing up physical memory for active pages, allowing larger programs to run with limited RAM. When a needed page is not in memory, a page fault occurs, triggering the loading of the missing page from secondary storage, which can temporarily slow down processes due to latency. Despite this, demand paging optimizes the use of available memory, especially in systems with many concurrent processes, by reducing redundant storage of idle pages .
The Banker’s algorithm is a deadlock avoidance algorithm that tests the safety of resource allocation by simulating the allocation in advance. It determines if after receiving a resource request, the system can still allocate resources to all processes without leading to a deadlock. The algorithm calculates the needs of each process and checks whether existing resources plus resources to be released can satisfy these demands in some order. If this simulation finds such an order, the system is considered to be in a safe state. Otherwise, if no safe sequence can fulfill all processes’ maximum needs, the resource allocation request is denied .
The critical section problem occurs when multiple processes share a resource in such a way that their concurrent execution could lead to inconsistent outputs. A two-process solution to manage access involves using synchronization mechanisms like semaphores or locks to ensure mutual exclusion, allowing only one process to enter its critical section at a time. A simple solution involves each process checking if a shared variable (lock) is set to indicate if the resource is in use. The process sets the variable before entering the critical section and clears it upon exiting, ensuring that the other process waits its turn .
Deadlock prevention techniques involve strategies to ensure that at least one of the necessary conditions for deadlocks cannot hold. Two primary approaches are: 1. Resource ordering: By assigning a global order to all resource types and ensuring that each process requests resources in a pre-defined increasing order, circular waits can be eliminated. 2. Hold and wait prevention: This technique involves requesting all required resources at once and only initiating execution if all requests are satisfied, thus eliminating the condition where processes hold resources while waiting for others. Implementing such measures requires careful consideration of resource utilization patterns to avoid starvation and ensure efficiency .
Processes are independent execution units containing their own state information and memory space, whereas threads are subdivisions of a process that share resources such as memory space and file handles. Threads allow for efficient execution of concurrent operations within a single process, enhancing performance through parallelism and shared resources. This shared environment leads to efficient inter-thread communication but also demands proper synchronization to prevent race conditions. Processes require more overhead for context switching compared to threads but maintain greater execution isolation, reducing interference and fault propagation among concurrent tasks .
Monolithic architecture in operating systems involves a single-tier structure where all services run in kernel mode, sharing the same memory space. This can lead to efficiency in execution but also makes the system less secure and resilient to faults due to lack of modularization. Layered architecture, on the other hand, organizes the OS into a hierarchy of layers, where each layer provides services to the one above and uses services of the one below. This modular approach enhances error isolation and system security because each layer operates independently. However, this can introduce performance overhead due to context switching between layers .
Multiprogramming is a method where multiple programs reside in memory at the same time, sharing CPU resources. Its primary goal is to improve CPU utilization by organizing jobs so the CPU always has one to execute. However, it does not necessarily provide interactive user sessions. Multitasking, a form of multiprogramming, enhances this by allowing multiple tasks or processes to share CPU time and be performed simultaneously, significantly improving user interaction and system responsiveness. Multitasking requires better scheduling and more sophisticated memory management but optimizes CPU efficiency and user experience .
Context switching is the process whereby the CPU switches from executing one process to another, saving the state of the current process and loading the saved state of the next process. This is necessary for multitasking environments, allowing multiple processes to share the CPU efficiently. However, context switching introduces performance overhead because it involves loading and storing register states, updating the memory map, and possibly switching memory segments. The impact is a trade-off between improved multitasking and the processing time consumed by the switching itself, which can slow down overall system performance if it occurs too frequently .
Belady's anomaly refers to the counterintuitive occurrence where increasing the number of page frames results in an increase in the number of page faults. It typically occurs in certain page replacement algorithms like FIFO (First-In-First-Out) due to lack of information regarding how pages will be used in the future. When more frames are added, the algorithm may evict pages that would be used soon, causing more faults. This anomaly highlights the inefficiency of memory management methods that do not adapt to access patterns or prioritize recent or frequently used pages, contrasting with algorithms like LRU (Least Recently Used) that do not suffer from this problem .