Operating Systems
Prepared by:
Thomas Swango
September 8, 1999
Operating Systems
An operating system (OS) is a collection of programs that manages the resources of the computer, and provides an interface between the user, hardware, and software applications.
There are many types of Operating Systems, the complexity of which varies depending upon what type of functions are provided, and what the system is being used for. Some systems are responsible for interfacing with people and others control hardware devices like petrol pumps.
A very simple Operating System for a security control system would be stored in Read Only Memory (ROM, a computer chip which holds instructions for a computer), and gain control at power-on. Its first task would be to reset, and probably test, the hardware sensors and alarms, then enter a continual monitoring routine of all the input sensors. If the state of any input sensor changed, it would branch to an alarm generation routine.
In a large multi-user computer system with many terminals, the Operating System is much more complex. It must manage and run all user requests, ensuring they do not interfere with each other. It must manage are resources and devices amongst all those requesting them. The OS would be stored on disk, and portions of it loaded into computer system memory, RAM, as needed.
In addition, the OS would need to present each user with an interface, which accepts, interprets, and then executes user commands or programs. This interface is commonly called a “SHELL” or command line interpreter “CLI”. In some systems this might be a simple text mode line-by-line entry using keywords such as MSDOS or UNIX, and in other systems it might be highly graphical using windows and a pointing device such as a mouse.
An operating system for a large-scale computer which is used by many people at once is a very complex system. It contains many millions of lines of instructions. To make operating systems easier to write, they are constructed as a series of modules, each module responsible for one function. Typical modules in a larger multi-user OS could be, kernel (also known as the executive), process manager, scheduler, and file manager.
The “Kernel is the core of all Operating systems. Some of the functions performed by the kernel are, switching between programs, hardware device control and programming, memory management, process management, scheduling, inter-process communication, and processing of exceptions and interrupts.
Our simple security monitoring system would not have all of the above, as it would probably be a single task system, running only one program. As such, it would not need to perform scheduling of more than one program or allow communication to take place between programs (called inter-process communication). Memory management would be unnecessary, as the program would reside permanently in EPROM (a special programmable form of ROM) or ROM.
An Operating System designed to handle a large number of people would need a real-time executive, which performs all of the above. User programs are generally stored on disk, thus need to be loaded into memory before being executed. This presents the need for memory management, as the memory of the computer would need to be searched for a free area in which to load a user program into. When the user was finished running the program, the memory consumed by it would need to be freed up and made available for another user when required.
Process scheduling and management is also necessary, so that all programs would be executed and run fairly. There is no point one program by a specific user run to such an extent that it denies the running of any other programs, making every other user wait. In addition, some programs might need to be executed more frequently than others, for example, checking network communications or printing. Some programs may need to be temporarily halted, then restarted again later, so this introduces the need for inter-program communication.
In operating systems we talk more of a process than a program. This is because in modern operating systems, only a portion of a program is loaded at any one time. The rest of the program waits in storage unit till it is needed. This saves memory space.
Processors execute computer programs; a processor is a chip in the computer, which executes program instructions. Processors execute millions of instructions per second.
A process or task is a portion of a program in some stage of execution. A program can consist of several tasks, each working on their own or as a unit (perhaps periodically communicating with each other).
A thread is a separate part of a process. A process can consist of several threads, each of which execute separately. For example, one thread could handle screen refresh and drawing, another thread printing, another thread the mouse and keyboard. This gives good response times for complex programs. Windows NT is an example of an operating system which supports multi-threading.
Some systems run only a single process at a time, other systems run multiple processes at once. Most computer systems are single processor based, and a processor can only execute one instruction at a time, so how is it possible for such a single processor system run multiple processes? The simple answer is that it doesn’t. The processor of the computer runs one process for a short period of time, then is switched to the next process and so on. As the processor executes millions of instructions per second, this gives the appearance of many processes running at once.
In a computer system, which supports more than one process at once, some mechanism must be used to switch from one task to another. There are two main methods used to perform this switching.
Co-operative switching means that a task, which is currently running, will voluntarily give up the processor at some time, allowing other processes to run. The problem with co-operative switching is one process could hang and thus deny execution of other processes, resulting in no work being done. An example of a co-operative system was Windows 3.1.
Pre-emptive switching means that a running task will be interrupted and forced to give up the processor to another waiting process. Pre-emptive scheduling is better. It gives more response to all processes and helps prevent (or reduce the number of occurrences of) the dreaded machine lockup. Windows NT is an example of such as operating system.
Only 32bit programs in Windows 95 are pre-emptive switched. 16 bit programs are still co-operatively switched, which means it is still easy for a 16-bit program to lock up a Windows 95 computer.
When the processor is switched from one process to another, the state (processor registers and associated data) must be saved, because at some later date the process will be restarted and continue as though it was never interrupted. Once this state has been saved, the next waiting process is activated. This involves loading the processor registers and memory with all the previously saved data and restarting it at the instruction, which was to be executed when it was last, interrupted.
The process of switching from one process to another is called context switching. A time period that a process runs for before being context switched is called a time slice or quantum period. Deciding which process should run next is called scheduling, and can be done in a wide variety of ways.
Co-operative schedulers are generally very simple, as the processes are arranged in a ROUND ROBIN queue. When a running process gives itself up, it goes to the end of the queue. The process at the top of the queue is then run, and all processes in the queue move up one place. This provides a measure of fairness, but does not prevent one process from monopolizing the system.
Pre-emptive scheduling uses a real-time clock, which generates interrupts at regular intervals (say every 1/100th of a second). Each time an interrupt occurs, the processor is switched to another task. Systems employing this type of scheduling generally assign priorities to each process, so that some may be executed more frequently than others.
The OS may be loaded into the computers memory in two ways, it is already present in ROM or it is loaded from disk when the computer is turned on. If the OS is already present in ROM (for systems like industrial controllers, petrol pumps etc), it will gain control immediately the processor is powered on. For more complex systems, the OS is usually stored on secondary media (such as disk), and is loaded into RAM when the computer is powered on. Advantages of this type of system are that changes to the OS are easier to make and implement.
Describes the task of initially loading the operating system from disk into RAM. A small routine stored in ROM, called the BOOTSTRAP LOADER or IPL (Initial Program Loader), reads a special load routine from the diskette. In floppy based system, this routine is normally located on Track 00, sector 00 (or 01), and is called the boot sector. The code contained in the sector is transferred into RAM, and then executed. It has the sole responsibility for loading the rest of the operating system into memory.
Operating systems are divided into categories, which define their characteristics. Modern systems may use combinations of those described below.
The earliest type, allowed only one program to run at a time. The program was entered into the computer, then run till completed. The data used by the program could not be modified whilst the program was running. Any errors in the program or data mean starting all over again.
During the mid 1950s through the mid 1960s computers used this earliest type of operating system, know as a batch system. A batch system is one in which jobs are bundled together with the instructions necessary to allow them to be processed without intervention. While batch systems moved work from the operator to the computer the turn-around time could be quite large from a users viewpoint. In addition, the lack of a protection scheme allowed a batch job to affect pending jobs.
The solution to this was a simple protection scheme, where certain areas of memory (e.g. where the monitor resides) were made off-limits to user programs. This prevented user programs from corrupting the monitor. To keep user programs from reading too many (or not enough) cards, the hardware was changed to allow the computer to operate in one of two modes: one mode was for the monitor and one for the user programs. IO requests could only be performed in monitor mode, so that IO requests from the user programs were passed to the monitor. In this way, the monitor could keep a job from reading past it's end of job card. In addition, to prevent an infinite loop, a timer was added to the system and the end of job card was modified so that a maximum execution time for the job was passed to the monitor. The computer would interrupt the job, and return control to the monitor when this time was exceeded.
One difficulty with simple batch systems is that the computer still needs to read the deck of cards before it could begin to execute a job. This means that the CPU is idle (or nearly so) during these relatively slow operations. Since it is faster to read from a magnetic tape than from a deck of cards, it became common for computer centers to have one or more less powerful computers in addition to there main computer. The smaller computers were used to read a deck of cards onto a tape, so that the tape would contain many batch jobs. This tape was then loaded on the main computer and the jobs on the tape were executed. The output from the jobs would be written to another tape, which would then be removed and loaded, on a less powerful computer to produce any hardcopy or other desired output. This was referred to as Spooling Batch Systems and started around the mid 1060s and continued through the mid 1970s.
It was a logical extension of the timer idea described above to have a timer that would only let jobs execute for a short time before interrupting them so that the monitor could start an IO operation. Since the IO operation could proceed while the CPU was crunching on a user program, little degradation in performance was noticed.
Since the computer could now perform IO in parallel with computation, it became possible to have the computer read a deck of cards to a tape, drum or disk and to write out to a tape printer while it was computing. This process is called Simultaneous Peripheral Operation On-Line or Spooling for short.
Spooling batch systems were the first and are the simplest of the multi-programming systems. One advantage of spooling batch systems was that the output from jobs was available as soon as the job completed, rather than only after all jobs in the current cycle were finished.
As machines with more and more memory became available, it was possible to extend the idea of multiprogramming (or multiprocessing) as used in spooling batch systems to create systems that would load several jobs into memory at once and cycle through them in some order, working on each one for a specified period of time. Thereby growing to the point that the monitor began to resemble a modern operating system. The monitor was responsible for starting user jobs, spooling operations, IO operations, switching between user jobs, and ensuring proper protection while doing all of this.
In the early days when computers had little or no operating system to speak of, the programmer had complete access to the machine. As hardware and software was developed to create monitors, simple and spooling batch systems and finally multi-programmed systems, the separation between the user and the computer became more and more pronounced.
To satisfy the programmers and users desire to get to the “machine without having to go through the batch process the idea of multi-pprogramming was extended to allow for multiple terminals t be connected to the computer, and each was allowed to control its own job. The operating system was responsible for switching between the jobs, or, as we now call them, processes. If the context-switches occurred quickly enough, the user had the impression that he or she had direct access to the computer.
Interactive processes were given a higher priority so that when IO is requested, the associated process is quickly given control of the CPU so that it can process it. This was usually done through the use of an interrupt that caused the computer to realize that an IO event had occurred. The second way that programmers and users got back at the machine was the advent of personal computers around 1980. Finally computers became small enough and inexpensive enough that an individual could own one, and hence have complete access to it.
Real-time, multi-processor, and distributed/networked systems. A real-time computer is one that executes programs that are guaranteed to have an upper bound on tasks that they carry out. Usually it is desired that the upper bound be very small. Examples included guided missile systems and medical monitoring equipment. The operating system on real-time computers is severely constrained by the timing requirements.
Dedicated computers are special purpose computers that are used to perform only one or more tasks. Often these are real-time computers and include applications such as the guided missile mentioned above and the computer in modern cars that controls the fuel injection system.
A multiprocessor computer is one with more than one CPU. The category of multiprocessor computers can be divided into various sub-categories:
- shared memory multiprocessors have multiple CPUs, all with access to the same memory. Communication between the processors is easy to implement, but care must be taken so that memory accesses are synchronized.
- Distributed memory multiprocessors also have multiple CPUs, but each CPU has it's own associated memory. Here, memory access synchronization is not a problem, but communication between the processors is often slow and complicated.
- Related to multiprocessors are the following:
- Networked systems consist of multiple computers that are networked together, usually with a common operating system and shared resources. Users, however, are aware of the different computers that make up the system.
- Distributed systems also consist of multiple computers but differ from networked systems in that the multiple computers are transparent to the user. Often there are redundant resources and a sharing of the workload among the different computers, but this is all transparent to the user.
- Inter-active systems allow the modification and entry of data whilst the program is running. Typical systems are airline reservations and languages such as BASIC.
- Time-sharing and multi-user systems share the computer system amongst more than one user, and employ pre-emptive scheduling techniques.
- Multi-tasking is executing more than one process at a time. The processor is switched rapidly between the processes. A user may run more than one process at a time.
- Real-time systems are primarily used in process control, telecommunications, etc. The OS monitors various inputs which affect the execution of processes, changing the computers model of the environment, thus affecting the outputs, within a guaranteed time period (usually < 1 second).
In conclusion, a computer is a set of resources for the movement, storage, and processing of data. The operating system is responsible for managing these resources. The operating system is nothing more than a computer program, and like other programs it provides instructions for the CPU. The only difference is in the function of the instructions. The operating system directs the CPU in the use of the other system resources and in the timing of the execution of the other programs.