The lowest layer of the operating system is the kernel (or nucleus) which acts as a regulator for the whole system, controlling the allocation of time slices to users or processes and ensuring that resources are allocated fairly. The kernel is responsible for multi-tasking, process control, exception handling (or error handling) and interrupt processing.
All but the simplest operating systems support some form of multi-tasking, meaning that the computer can run more than one program, or support more than one user, simultaneously. Each program or sub-program capable of seemingly simultaneous execution is known as a process.
The terms multi-tasking and multi-processing are often used interchangeably, but strictly speaking, multi-processing involves the use of more than one processor. Multi-tasking only requires a single processor, but it switches between processes so rapidly that that it appears that all the processes are running simultaneously. There are two distinct types of multi-tasking: cooperative and preemptive.
In cooperative multi-tasking, each process can control the processor for as long as it needs it. If a process is not using the processor, however, it can allow another program to use it temporarily. Early multi-tasking systems consisted of groups of related applications that voluntarily granted time to each other. This approach is rarely used in larger systems, but older versions of Microsoft Windows and Mac OS used cooperative multi-tasking to enable the running of multiple applications simultaneously.
Cooperative multi-tasking has several disadvantages. A cooperatively multi-tasked system relies on each process regularly giving time to other processes. A poorly designed program, or a hung process, can bring the system to a halt. The design of cooperatively multi-tasked programs difficult and may result in inefficient use of system resources.
Preemptive multi-tasking involves the use of a scheduler which allocates processor time to various processes so that they can be performed simultaneously. All processes will get some amount of processor time at any given time. This allows the computer system to guarantee each process a regular time slice and lets the system deal rapidly with external events like incoming data, which might require the immediate attention of some process.
Running processes can be split into two categories: those that are waiting for input or output (I/O bound) and those that are fully utilising the processor (CPU bound). In early systems, processes would enter a wait state while awaiting input. During this time, the process was not performing useful work, but still maintained control of the processor.
With the advent of interrupts and preemptive multi-tasking, these I/O bound processes could be blocked, or put on hold, until the necessary data arrived, allowing other processes to utilise the processor. The arrival of the data would generate an interrupt, allowing blocked processes to return to execution.
Multi-tasking was originally developed to allow multiple users to share a single machine, but it soon became apparent that it was useful regardless of the number of users as it allows a single user to run multiple applications at the same time, or to run "background" processes while retaining control of the computer.
Next: Process Scheduling