The operating system (OS) of a computer manages all the resources including available space in memory and storage devices, available CPU computing time, available network connections, and so on. OS is in charge of arranging and supervising the work of each hardware and software component in the computer, and is the faithful assistant of computer users.
Any chip in a traditional computer, including the central processing unit (CPU), starts working by receiving electronic signals which could be controlled by a program. However, in a complex system such as a personal computer, if the programmer has to write a program to control all the signals, it is a very heavy and repetitive task. If a certain part of the computer is replaced, or the program is moved another machine, the electronic signals are not the same. Is it necessary to re-write the program?
In order to navigate complex systems, the operating system (OS) becomes an intermediary between the program and the machine. Basically, the OS performs three tasks: first, it prepares the environment for a program to be executed; second, it manages all the available resources in the computer; and third, it acts as an agent between the program and the machine, i.e. the program does not have to understand the details of the machine's electrical signals. The program only has to give commands to the OS, and it controls the devices through it. The translations of the commands into the hardware's electrical signals is taken over by the OS.
If a computer is a mansion or a park, the operating system is the park's chief butler who takes inventory of all the facilities in the park, and direct other servants to keep track of the status of these facilities, including cleaning, repairing, and checking for malfunctions; The program is just like a worker in the park. When the worker goes to work, the butler prepares the desk and all the things he needs, and the worker just needs to sit down in front of the desk, focusing on his unique functions. When the computer needs to change its functions, the chief butler rearranges the environment and empty the desk, so that the next worker can be welcomed.
The role of the operating system in a computer system depends on the complexity of the computer system. If the task of the system is very simple, such as a very simple hardware structure and fixed to execute only a certain program, then the operating system will be very small and simple. If the system is very complex, such as modern personal computers that execute multiple programs at the same time and connect to a variety of peripheral devices, then the operating system will be very large and very complex.
If there is only one user on the system, and only one program is running at the same time, then the task of the operating system is very simple. It only needs to organize the environment, and then hand over the control of the whole machine to the program, and then OS does nothing else until program ends. For example, the MS-DOS system used in the early personal computers, as well as some firmware operating systems used in handheld devices.
If you want a computer system to be able to run many programs at the same time, but the CPU has only one or a small number of cores, the operating system slices the usage time of CPU cores into tiny units, and then schedule these programs to take turns using these time units. The CPU cores will take turns switching between programs to create the "illusion" that these programs are all running at the same time. This is like letting a person do a lot of things at the same time by doing a little bit of each thing. This will exhaust the person, but everything seems to be progressing. Such operating systems are Windows and macOS for personal computers, and Android and iOS for smartphones.
To keep the concurrently running programs from interfering with each other, the operating system completely isolates the memory and other resources used by each program, as if the programs "believe" they are occupying the machine exclusively. The concept of "virtual machine" is the mainstream practice of modern operating systems.
If a computer system will not only run many programs at the same time, but also be used by many users at the same time, for example, it is a host on the network, then the programs run by each user, the storage space used, and so on, must be strictly quarantined. The privilege of each user and the programs used is also limited, so that these users and programs not only cannot interfere with each other.The users and programs should Examples of such operating systems are Linux, UNIX, and Windows Server used by server machines.
In addition, due to the popularity of the Internet, modern mainstream operating systems usually also put great efforts into to information security. Security checks, encrypted connections, and common malware blocking are built in operating systems. In addition, if there are some common functions used by most programs, the operating system often provides built-in software libraries directly, so that programs do not need to re-develop the functions.