Operating System Midterm Exam 2025
Operating System Midterm Exam 2025
A process is a program in execution, which includes the program code, current activity represented by the program counter, and the contents of the processor's registers. It is an active entity, with a lifecycle managed by the operating system, and can be in states such as running, waiting, or terminated. A program, on the other hand, is a passive entity that consists of executable instructions stored on a disk. It does not have a state and cannot change on its own. The relationship is such that a single program can be the source of multiple processes in a multitasking environment.
System calls provide an interface between the operating system and user applications, allowing programs to request services from the operating system such as file operations, process control, and communication. They act as a way for programs to interact directly with the hardware for functionalities that are abstracted by the operating system. Examples include the 'open()', 'read()', 'write()', 'close()', which manage file operations, and 'fork()', 'exec()', 'exit()', which handle process creation, execution, and termination.
The main components of an operating system include the kernel, process management, memory management, file system, and device management. The kernel acts as the core interface between the hardware and processes. Process management handles the execution, scheduling, and termination of processes, ensuring efficient usage of CPU. Memory management keeps track of each byte in a computer's memory and allocates/deallocates memory spaces as needed. The file system organizes and stores information on storage devices. Device management provides I/O operations by interacting with hardware devices. These components interact to provide a stable and efficient operating environment by coordinating hardware resource access, managing running applications, and maintaining system integrity.
Multiprogramming improves system efficiency by allowing multiple processes to reside in memory at the same time, enabling the CPU to switch between tasks without waiting for I/O operations to complete. This leads to better CPU utilization as it always has a process to execute, thereby reducing idle time. It organizes jobs so that the CPU remains busy executing one program while others are waiting for I/O operations to complete, maximizing throughput and system performance.
The Round-Robin scheduling algorithm gives each process an equal time slot in a cyclic order, which prevents any process from monopolizing the CPU. Its advantages include simplicity and fairness, as every process gets a chance to execute. It is particularly effective in time-sharing systems where the goal is to ensure a responsive system for all users. However, the disadvantages include higher context-switching overhead, which can degrade performance if the time quantum is too small. Conversely, if the time quantum is too large, it can lead to poor response times for short processes. Round-Robin needs careful tuning of the time quantum to balance performance and responsiveness.
Paging divides memory into fixed-size units called pages, solving external fragmentation by allowing programs to be non-contiguous in memory. This enhances memory utilization and simplifies allocation but can lead to internal fragmentation if the last page is partially filled. Address translation involves page tables, making it complex and can introduce overhead. Segmentation, on the other hand, divides programs into logical units or segments. It reflects the logical structure of programs, such as functions or arrays, aiding programmer understanding. It can, however, suffer from external fragmentation, as segments are of varying sizes and need contiguous space in memory. Each method's pros and cons depend on the type of applications and the system's memory management needs.
The four necessary conditions for deadlock to occur are mutual exclusion (resources cannot be shared), hold and wait (processes holding resources can request additional resources), no preemption (resources cannot be forcibly taken from a process), and circular wait (a closed loop of processes exist, each holding resources the next process needs). To prevent or manage deadlocks, we can apply techniques such as eliminating one or more of these conditions. For instance, deadlock prevention involves negating one of the conditions, whereas deadlock avoidance uses algorithms like Banker’s algorithm to ensure safe resource allocation sequences. Deadlock detection and recovery involves allowing deadlocks to occur, detecting them, and corrective actions.
A Process Control Block (PCB) is a data structure in the operating system kernel, containing the necessary information about a process. It includes process identification numbers, process state (e.g., running, waiting), CPU registers, memory management info, accounting information, and I/O status. The PCB acts as the repository of all data required by the OS to manage processes, facilitating context switching, scheduling, and basic process management functions by maintaining the state and context for each process in the system.
The Banker's Algorithm operates on the principle of resource allocation based on a particular sequence, ensuring that even in maximum demand scenarios, system resources remain allocated in a safe sequence without causing deadlocks. Each process declares maximum resources it may need. When a process requests resources, the system temporarily grants the resources and tests if the system stays in a safe state by simulating this allocation. If it does, the allocation is confirmed; otherwise, the process must wait. This method allows the system to adapt dynamically to varying resource demands while maintaining overall system stability and preventing deadlocks.
Mutual exclusion ensures that no two processes access critical sections of code simultaneously, preventing conflicts from occurring when shared resources are accessed concurrently. It is crucial to maintain data integrity and prevent inconsistent data states. Two methods to achieve mutual exclusion include: 1) Peterson’s solution, a software-based protocol that ensures mutual exclusion for two processes using a lock variable and two additional flags; 2) Semaphores, which involve special variables that are manipulated atomically with operations like wait() and signal() to synchronize process execution and access to critical sections, preventing concurrent access effectively.