Function of Operating Systems
Features & Components (3.1.a, 3.1.f)
There are several different types of operating systems. Obviously, different operating systems have different features, however all operating systems have some key features:
Error reporting - functionality for storing details of errors which occurred in the operating system other software, so that developers can fix the causes of these errors ("bugs").
Memory management - the allocation of memory for use my various programs, as well as the storage and retrieval of data from memory.
Resource management - the management of limited resources, including CPU time, memory, hard disk space, electrical power, external devices, and I/O operations.
I/O management - the management of I/O devices.
Device management - the management of all devices, such as storage devices and graphics cards (including I/O devices).
Interrupt management - the management of interrupts.
User interface(s) - the management of user interfaces - for example a GUI for the end user and a command line interface for a technician to diagnose faults.
File Allocation Table (FAT) - a map of where files are stored. Also contains various metadata, such as file names, access rights, and file sizes. It is used by the operating system when files are saved, deleted and accessed.
Boot File - used while the operating system is loading, when the computer is switched on, after POST (Power On Self Test - a form of self-diagnostics), to provide personal settings.
Some tasks are more important than others. For example, consider a school computer rendering a video file. If the user moves the mouse, then the screen has to be updated, to move the mouse pointer. However, the processor can only work on one task at a time (the screen cannot be redrawn with the new mouse position at the same time as rendering video). Therefore, interrupts are used - to tell the processor to stop what it is doing because there is something more important which needs dealing with.
Before the Fetch Decode Execute cycle, the CPU checks the contents of the interrupt register. This contains the details of any pending interrupts. If the interrupt in the interrupt register has a higher priority than the current task (which could be another interrupt), then the interrupt is processed, otherwise the current task continues processing. Note: the current task could have a higher priority than the interrupt, especially if the current task is another interrupt!
When servicing an interrupt, the data from the registers is pushed to the stack. It then loads the program counter with the address of the start of the Interrupt Service Routine, and the FDE cycle continues. The last instruction of the Interrupt Service Routine is an Interrupt return instruction that brings the original data back into the registers.
Scheduling & Job Queues (3.1.c)
A scheduling algorithm has 4 "goals":
- To make efficient use of processor time
- To make efficient use of resources
- To maximise the number of users without apparent delay
- To maximise the throughput of the CPU
A scheduling algorithm should also ensure all tasks are processed, by changing the priorities if necessary.
There are a number of popular scheduling algorithms:
- Round Robin - each task is given a small "time slice" - perhaps of a few milliseconds. After the time is up, the processor moves on to the next task.
- Shortest Job First - the shortest job is processed first. Although this leads to lots of jobs being done quickly, it can lead to some longer jobs never getting processed.
- Shortest Time Remaining - the job with the least time remaining is processed first. This is similar to shortest job first, although it is considered sightly superior because long jobs will slowly "bubble up" until they have the shortest time remaining.
- First Come First Served - the first job to be ready for processing is processed.
- Multi-Level Feedback Queues - a number of queues are set up. If a task actively uses large amounts of processor time, it is placed in a lower priority queue, until it reaches the "base" queue, which operates in a round robin fashion.
Memory Management (3.1.d)
All operating systems need memory management software.
- To allocate memory to allow separate processes to reside in memory and then run at the same time.
- To reallocate memory when necessary, for example reallocating the memory space of a closed program.
- To protect processes and data from each other by blocking access to the memory space of another program.
Segmentation & Paging
There are two ways to divide memory (for swapping between RAM and virtual memory) - segmentation and paging. Segmentation is where each task has a whole "segment". The whole segment has to be moved to and from virtual memory, however segmentation avoids the need to split up a program. Paging is where a program is split into pages, which all have the same size. Individual pages can be swapped in and out of virtual memory, which can lead to more efficient use of RAM. However, programs have to be split into individual pages.
A computer will only have a limited amount of RAM. When the RAM is full, virtual memory has to be used, based on secondary storage (such as the hard disk). This allows programs to run that need more memory than is available. However, if virtual memory is overused, then the processor could end up spending more time moving segments or pages between RAM and virtual memory. This is known as disk threshing, and can result in the computer performing sluggishly, or "hanging".
Spooling is used when the rate the processor can send data is faster than the rate a peripheral device can output it. For example, consider a printer. It might be able to print 20 pages per minute, a third of a page per second. However, the processor is cable of sending pages much faster than this. This is known as speed mismatch.
To prevent the processor from being "held up" by the printer (or another peripheral), the print data is saved to secondary storage. It is then retrieved and sent to the printer when the printer is ready - in the mean time the processor can work on higher priority tasks.