The term multitasking refers to the ability of an operating system to perform multiple tasks concurrently. In general, the processor also offers supporting hardware structures for this. The various processes are activated alternately at such short intervals that the impression of simultaneity is created. Multitasking is thus a variant of a time-multiplexing process. If a computer has several CPU cores so that it can perform several tasks at the same time, this is called multiprocessing. In modern computers, both methods are used in combination.
Apparent or actual concurrency, depending on the number of processors, is the result of the rapid alternation of execution of processes present in memory. Switching execution from one process to another is called context switching. These switches can be initiated by the programs themselves (cooperative multitasking) or by the operating system during external events (preemptive multitasking).
Purpose of Multitasking
Multitasking can be useful for various needs, especially when optimizing utilization and balancing or prioritizing resource allocation depending on the objective.
---
The basic idea behind the optimization of the load is that in an average computer, the majority of the computing time cannot be used because it is often necessary to wait for relatively slow, external events (for example, for the next keystroke of the user). If only one process were running (for example, the waiting word processor), this waiting time would be lost completely unused. However, by multitasking, the waiting time of one process can be used by other processes.
If, on the other hand, a computer or its computing time is largely utilized, for example by individual computationally intensive processes, several users or processes can still receive proportionate computing time instead of having to wait for the end of another process. This is particularly beneficial for interactivity.
Since the system can take priorities into account for the various processes at the same time, a corresponding weighting is possible, depending on the objective. For example, a server may prefer the services it is supposed to offer, but prioritize direct user interactions. Conversely, a desktop PC will prefer the inputs and outputs from/to the user, and will put background processes on the back.
Discussion
Preemptive multitasking is more robust than cooperative multitasking: one task cannot block the entire system. The operating system can also make more efficient use of available resources, for example if data is available via an input device, the process to process this data can be activated immediately.
In addition, a task waiting for data will not consume CPU time before its data is actually available.
Although multitasking was originally designed to allow multiple users to use the same computer, it quickly became apparent that it was very convenient even for a single user. Using your favorite word processor while browsing the web is a must-have feature these days.
Another utility of multitasking comes from the fact that it is easier to design and write several simple programs, rather than a single program that can do everything and then make them cooperate to perform the necessary tasks.
The algorithms implementing multitasking have been refined over time. Modern systems can handle processes with different priorities as well as computers with one to a few hundred processors.
Threaded technology was made possible by the presence of advanced memory managers. Lightweight processes share some or all of the memory of an existing process. This sharing allows, among other things, faster context switching and more efficient data sharing between lightweight processes. On the other hand, such programs can be more complex and difficult to develop.
Another key innovation was the introduction of privilege levels: processes with a low privilege level cannot perform certain operations, such as writing to portions of memory vital to system security.
If such a process performs a prohibited operation, the program is interrupted and a supervising program (often the operating system) preempts the current process and then stops it permanently. This technique makes it possible to create virtual machines where the “real” system emulates the operation of one or more virtual machines, for example to increase security (a virtual machine cannot interfere with another virtual machine).