Operating Systems

Introduction to Resource Allocation

A computer has a limited amount of resources, such as CPU time, primary memory, secondary storage and I/O devices. Multiple processes may require these resources at the same time, so one of the responsibilities of the operating system is to manage and allocate these resources between processes.

Primary memory is limited, so not every program and all of its data can necessarily be held in primary memory at the same time. The operating system therefore manages the use of primary memory and determines which memory is available to processes.

Modern operating systems also use virtual memory. Rather than requiring an entire program and all of its data to be loaded into physical memory before execution, the operating system can load the required pages into primary memory as they are needed. If a process attempts to access a page that is not currently in primary memory, a page fault can occur and the operating system can load the required page from secondary storage. Operating systems may also use techniques such as prefetching to load pages that are expected to be required soon.

Long-Term Scheduler

The long-term scheduler, also known as the job scheduler, determines which jobs or processes are admitted into the system for execution. By controlling how many processes are admitted, the long-term scheduler can control the degree of multiprogramming.

The long-term scheduler does not determine which individual parts or pages of a program should be loaded into primary memory. Decisions concerning pages and virtual memory are handled by the operating system's memory-management mechanisms.

Medium-Term Scheduler

The medium-term scheduler determines which processes should be temporarily suspended and which suspended processes should be allowed to return to active execution. It is therefore associated with the Suspended Ready and Suspended Waiting/Blocked process states.

A process may be suspended when the operating system needs to reduce the number of active processes competing for resources, particularly primary memory. Traditionally, this can involve swapping some or all of the process's memory out of primary memory and storing it on secondary storage. Suspending processes can therefore reduce the degree of multiprogramming and make primary memory available for other processes.

When resources become available and the operating system decides that a suspended process should become active again, the medium-term scheduler can allow the process to be resumed. A Suspended Ready process can return to the Ready state once the required memory and resources are available. A Suspended Waiting/Blocked process must also wait for the event that caused it to become blocked before it can become ready to execute.

Unlike the short-term scheduler, the medium-term scheduler does not decide which Ready process should execute on the CPU next. Its role is instead to control which processes are actively participating in the system and which are temporarily suspended.

Short-Term Scheduler

The short-term scheduler, also known as the CPU scheduler, determines which process in the Ready state should be given access to the CPU next. Unlike the long-term scheduler, which is concerned with admitting processes into the system, the short-term scheduler runs frequently because the CPU may switch between processes many times during their execution.

The process selected depends on the CPU scheduling algorithm being used. For example, First-Come, First-Served (FCFS) selects processes according to their arrival order, while Shortest Job First (SJF) attempts to select the process with the shortest expected CPU burst or job length. Other scheduling algorithms may consider factors such as priority, response time or fairness.

Operating System and User Space

The operating system itself requires memory in order to operate. The kernel, which is the core component of the operating system, remains resident while the system is running and contains code and data required to manage processes, memory, devices and other system resources.

Modern operating systems generally distinguish between kernel space and user space. Kernel space is a protected region of the virtual address space used by the operating system kernel, while user space is where ordinary application processes execute. Applications such as Vim and VLC execute in user space and must request privileged operating system services through mechanisms such as system calls.

This separation helps protect the operating system from application processes. A process executing in user space cannot normally directly access protected kernel memory or perform privileged operations.