An Operating Systems is a program that manages the computer hardware.
It also provides a basis for application programs and acts as an intermediary between the computer user and the computer hardware.
The operating system provides the means for proper use of these resources in the operation of the computer system.
A modern general-purpose computer system consists of one or more CPUs and a number of device controllers connected through a common bus that provides access to shared memory
Each device controller is in charge of a specific type of device (for example, disk drives, audio devices, and video displays). The CPU and the device controllers can execute concurrently, competing for memory cycles. To ensure orderly access to the shared memory, a memory controller is provided whose function is to synchronize access to the memory.
For a computer to start running-for instance, when it is powered up or rebooted-it needs to have an initial program to run. This initial program, or bootstrap program tends to be simple. Typically, it is stored in read-only memory or electrically erasable programmable read-only memory known by the general term firmware within the computer hardware.
The CPU can load instructions only from memory, so any programs to run must be stored there. General-purpose computers run most of their programs from rewriteable memory, called main memory or RAM.
Computers use other forms of memory as well. Because the read-only memory (ROM) cant be changed, only static programs are stored there. The immutability of ROM is of use in game cartridges. EEPROM cant be changed frequently and so contains mostly static programs. For example, smartphones have EEPROM to store their factory-installed programs.
All forms of memory provide an array of words. Each word has its own address. Interaction is achieved through a sequence of load or store instructions to specific memory addresses. The load instruction moves a word from main memory to an internal register within the CPU, whereas the store instruction moves the content of a register to main memory. Aside from explicit loads and stores, the CPU automatically loads instructions from main memory for execution.
A typical instruction-execution cycle first fetches an instruction from memory and stores that instruction in the instruction register. The instruction is then decoded and may cause operands to be fetched from memory and stored in some internal register. After the instruction on the operands has been executed, the result may be stored back in memory.
Ideally, we want the programs and data to reside in main ncemory permanently. This arrangement usually is not possible as main memory is small and volatile i.e. loses its contents when power is turned off or otherwise lost.
In order to ensure the proper execution of the operating system, we must be able to distinguish between the execution of operating-system code and user defined code. The approach taken by most computer systems is to provide hardware support that allows us to differentiate among various modes of execution.
we need two separate modes of operation: user mode and kernel mode. A bit, called the "mode bit" is added to the hardware of the computer to indicate the current mode: kernel (0) or user (1).
At system boot time, the hardware starts in kernel mode. The operating system is then loaded and starts user applications in user mode. Whenever a trap or interrupt occurs, the hardware switches from user mode to kernel mode (that is, changes the state of the mode bit to 0). Thus, whenever the operating system gains control of the computer, it is in kernel mode. The system always switches to user mode (by setting the mode bit to 1) before passing control to a user program.
The OS does not allow a user program to go into infinite loop or fail to call system services and never return control to the OS. This is done by use of the Timer.
A timer can be set to interrupt the computer after a fixed or a variable period. A variable timer is implemented using a fixed rate clock or a counter.
The operating system sets the counter. Every time the clock ticks, the counter is decremented. When the counter reaches 0, an interrupt occurs. For instance, a 10-bit counter with a 1-millisecond clock allows interrupts at intervals from 1 millisecond to 1,024 milliseconds, in steps of 1 millisecond.
A program does nothing unless its instructions are executed by a CPU. A program in execution, as mentioned, is a process.
A process needs resources such as CPU time, memory, files and IO devices to run.
These resources are either given to the process when it is created or allocated to it while it is running. In addition to the various physical and logical resources that a process obtains when it is created, various initialization data (input) may be passed along.
A single threaded process has one program counter specifying the next instruction to execute. The execution of such a process must be sequential. The CPU executes one instruction of the process after another, until the process completes. Further, at any time, one instruction at most is executed on behalf of the process. Thus, although two processes may be associated with the same program, they are nevertheless considered two separate execution sequences. A multi-threaded process has multiple program counters, each pointing to the next instruction to execute for a given thread.