Operating Systems

Wikipedia HowStuffWorks Introduction to Linux
Film: Hardware & OS Basics    

How Stuff Works

1. Introduction

Operating systems in a wide range of devices: PCs, phones, wireless access points.

Operating system purpose is to control hardware and software. This part of the OS is known as the 'kernel'. OSs have two modes, supervisor and protected. Supervisor mode is used by the kernel for low level tasks that need unrestricted access to hardware such as memory and disks. Protected mode is used for almost everything else e.g. applications cannot access hardware directly, only through the kernel.

Make a 'virtual machine': in Turing's terms this is (almost) 'U', the universal machine that can run any valid program. The OS contributes to the creation of U by controlling the hardware on which application programs run.

2. Which Devices Have Operating Systems?

Not all devices that run software have operating systems. Single-purpose device e.g. microwave oven has no need for an OS. OS needed when device: has a number of purposes; interacts with users in complex ways; changes over time e.g. upgrade or hardware changes. Device can be modified by changing the system software so it can accept new peripherals, support a new user interface, take on new libraries, take on new utilities e.g. security.

3. What an OS Does

OS controls hardware: CPU, memory, storage I/O devices. Also controls application software: make sure they get resources such as I/O and memory e.g. graphics-TWAIN. Challenge is to keep OS flexible to support thousands of peripherals and applications.

4. Type of OS:

Real-time: for machinery, scientific equipment, industrial systems, aeroplanes. Little need for interface but must be capable of executing a particular process in exactly the same time every time; must not wait for attention of CPU for execution of a process as the process may be critical.

Single-user, single task: one thing at a time for one user e.g. PalmOS

Single-user, multi-tasking: common on PCs e.g. Windows, MacOSX: user can run several programs at once; aided by multi-core CPUs.

Multi-user: many users can access a computer at the same time e.g. mainframe, super computer. This is still a widely used approach to computer processing e.g. scientific number crunching by super computers: users access computer time from a terminal.

Network OS: layer of software added that intercepts and processes commands that refer to resources beyond the local computer. A networked computer may have a real-time function such as controlling a process so the OS is real-time networked. Computers may be booted from a network (WOL: wake on LAN).

Distributed OS: manages a group of computers as if they were one; may be distributed a long way apart.

Embedded OS: e.g. on hand held devices: compact and efficient.

5. OS Boot

Power On Self Test (POST) done first: checks CPU, memory and BIOS. Boot program (bootstrap loader) kept in ROM: starts to load OS from disk into RAM where it can run. Boot routine loads drivers for I/O devices such as disc, keyboard & monitor. Sets up sections of memory that hold OS, user information & applications and signals, flags & sempahores.

The OS manages CPU, memory, devices, storage, the application interface and the user interface.

6. Processor/CPU management

Ensure each process and application receives enough time to function

Use as many cycles as possible for real work

OS controls processes rather than applications. Each application can initiate a number of processes e.g. anti-virus, network, memory, disk; e.g. to access memory and I/O

In single tasking the OS starts the application and uses interrupts to service hardware drivers such as the keyboard and storage.

Interrupts provide a way of stopping one process and starting another e.g. refresh the screen when required. Interrupts have priorities and masks to enforce them; when a process of a high priority is running it cannot be interrupted by a process of lower priority. Some interrupts are non-maskable due to their importance and they will always be processed.

In multi-tasking the OS must give the impression that many applications are running at once when in fact 0nly one process (and remember each application initiates many processes) has access to the CPU at a time. With more than one processor/CPU, as in multi-core processor chips, an application may have control of its own CPU. The operating system switches between processes at a rapid rate, thousands or millions of times per second.

7. Process Control Blocks

The information required by the OS to keep track of switching between processes is stored in a process control block (PCB). The PCB typically contains:

Each process has a status: running, waiting, suspended. The process of swapping PCBs itself consumes CPU cycles as the register contents and other data must be saved and the details of the new process are loaded. If too many applications and processes are started then the OS may be too busy switching between processes to actually run any of them: this is called  'thrashing' and may eventually lead to a system crash..

Threads are  called by processes to deal with CPU tasks only, avoiding I/O and other parts of a PCB. Threads may share CPU resources such as cache memory and should lead to more effective use of CPU cycles - hence terms like 'hyper-threading' in the technical description and marketing of CPUs (a technique that involves the OS creating two virtual CPUs for each physical one; hyper-threading must have symmetric multiprocessing for the technology to work).

A symmetric OS divides itself between the various processors available and balances demand  against CPU availability. An asymmetric OS uses one CPU for itself and uses the other processors for applications.

8. Memory Management

Memory management: each process must have enough memory and the different types of memory available must be used effectively (RAM (main memory), cache, virtual (disk store or secondary memory)

An OS may occupy RAM at the 'top' of memory and drivers may occupy memory at the 'bottom'. In between is the memory for applications, which is allocated in blocks of a fixed size. The start and finish address of each application must be kept so that one does not run over into another (memory leak). When RAM is full of programs and data the OS will use the disk as virtual memory, swapping unused processes onto the disk to make way for some other process that has to run. The unit of memory that is swapped in and out is called a page. Page swapping can also result in thrashing if there are too many swaps.

9. Device Management and Drivers

Device management: path between OS and hardware not on the motherboard goes through a driver. Function of a driver is to allow hardware to communicate with the computer and to allow applications to make use of devices e.g. printer: to convert electrical signals into binary that the OS and CPU can understand and process. When hardware changes the driver will be updated, hence the need to download the latest drivers from a support web page. Thus the OS does not need to be updated, only the driver. Drivers are generally the responsibility of the third party manufacturer rather than that of the OS producer.

I/O is managed through buffers and queues, which take a stream of bits from the device driver and forward them to the CPU at a suitable rate. Subsystems such as graphics and sound may have their own processors, taking the processing load off the computer's  CPU. When an I/O process is suspended the CPU may allow the device to keep sending data to its input buffer so it has data in memory to process when the process starts running and does not have to wait for the device to send data.

For a real-time OS, which does not manage users through a particular interface, this may be all that is required to process I/O from connected devices such as sensors.

10. API

Application Programming Interface (API): allow programmers to use features of the OS without having to understand how the OS controls the CPU and other hardware: call functions that use OS processes.

For example: an instruction to create a file might specify the type of file (serial, direct access), a name and a size parameter (fixed, variable).

OS finds an empty point on the hard disk to start the file; makes an entry in the file system giving the start, finish, name, length/size of the file, permissions and archive status; the OS writes information in the first few locations of the file to identify it. Thus the programmer is shielded from the full details of managing the disk drive by calling a function fro the API.

11. User Interface

User interface does the same job for a user as an API does for a programmer: provides a consistent way to interact with the computer.

Main distinction in UIs is between command line interfaces (CLI) and graphical user interfaces (GUI).

UI sits as a layer above the core or kernel of the OS. Links between OS kernel and UI, utilities and other software define many of the differences in operating systems.

Open source (Linux) vs. proprietary (MS, Apple): former allows/encourages individuals to extend & improve the OS. Some OSs on devices like mobile phones may prevent access.