We often hear the word ‘Operating System’ being used when we are buying new phones or laptops, but do we really know what it is? To fully understand what an operating system is, we need to take a deeper look at the hardware of a computer because we can best understand the operating system in relation to this.
So, a computer system is divided into different components. We can group these together into: Hardware, Operating System, Application Programs and Users. The Hardware consists of the physical parts of the computer such as the monitor, keyboard, mouse and memory etc. The Operating System can be seen as a middle layer between the hardware and the application program and it basically controls the use of the hardware between the Application Programs and the users. The application programs are programs or software that can be directly used by the User. Examples of Application Programs are Microsoft Word, Google Chrome, PhotoShop and many others that I’m sure we are all familiar with. Finally, the user is a person like you or me who is using the computer or a user can even be another computer!
When trying to understand Operating Systems, you will often run into a diagram that looks something like this:
This shows the layers of our four components and it also gives us a vague idea of how these layers flow into each other.
The first real operating system was invented by General Motors in 1956. Before this, everything we wanted to do on a computer we had to code. To understand the impact of this, imagine trying to open Microsoft Word to write an assignment by writing code to open the application, writing more code to use the application, and then writing even more code to close the application all the while hoping the machine doesn’t crash! If the thought of this gives you a headache as much as it does to me, then you can understand the great need for an Operating System. The Operating System allows us to abstract from the hardware and allows users to use applications on a computer without having to know all the technical details of how they are stored and run.
Purpose Of The Operating System
The Operating System Allocates Resources. This means that if multiple programs want to access and write to, say, a file in memory, the Operating System decides which one gets to access the file first and the order in which they all do it. This is an important task as if all the program try to access this file and write to it at the same time, it would result in a lot of unwanted results. So for example, say program A needs to write ‘Hello’ to a file and program B needs to write ‘Goodbye’ to the same file. If another program, say program C, wants to read from this file, it is important if it reads from this file after program A writes to it or after program B writes to it, as this will affect the contents of the file. So if the order was Program A write, program C read, program B write. It is vital that program A is allocated access to the file first, then C, then B. So that C will read the correct message ‘Hello’ and not ‘Goodbye’.
The Operating System also controls the execution of programs to prevent any errors. As a result of this, we call an Operating System a ‘control program’.
Okay, so now we have a preliminary understanding of what an Operating System is and what it does. A brief review:
- An Operating System is a program itself.
- It allocates resources.
- It controls the execution of programs.
But, what happens when I turn on my computer? If the Operating System is a program, what makes it run when the computer is turned on? The answer to this is something called a Bootstrap Program. The term ‘bootstrapping’ means a self-starting and self sustaining process. The Bootstrap program the first program to be executed when you startup your computer. It is stored in EPROM or ROM, which stands for Read-Only-Memory. This means that you can read it but you can’t edit it. The Bootstrap Program loads up all aspects of the computer, including the Operating System. It also loads the kernel which is something we should explain before we go any further.
The Kernel
The Kernel is a part of the Operating System and it is loaded by the Bootstrap Program. It is loaded into a special area of memory known as the kernel space that can’t be accessed by users or application programs. It executes process and manages hardware devices. As the kernel is in the kernel space, the user is in the user space. But why is the Kernel separated? If a application program malfunctions or a user (accidently or maliciously) tries to change or access something they shouldn’t and if that caused a malfunction in the kernel, then the whole operating system could crash. To prevent this from happening, the kernel is placed in the protected kernel space so that if a program does malfunction, only that program would crash. A number that is either 0 or 1 tells the Operating System if the system is running in user or kernel mode. This number is called the mode bit. If it is 0, then the system is running in kernel mode otherwise it is in user mode. There are certain instructions which may only execute in kernel mode. This is for the system’s protection and examples of these instructions are I/O operations or memory management. These instructions are known as privileged instructions. But how do we switch into kernel mode? And how would we switch back?
The way to do this is to make a request to the kernel asking it to switch into kernel mode. This request is a System Call. If the kernel grants the request, it will carry out whatever was asked of it in the request and the mode bit is now set to 0. It will then it will return control to user mode when it is complete and the mode bit will be 1 again.
Device Communication
So we have said that the operating system allocates resources and that the kernel is a part of the operating system that helps manage hardware devices. But how do hardware devices communicate with the computer?
So each device is part of a certain device type. You can think of this like a device’s family. And for the device to interact with the computer, the computer and the device need to be able to understand each other. If we continue with the family analogy, then imagine each device family speaks a different language. But the way each device family speaks is through the medium of electrical signals. So now we just need something to interpret these signals, and we call this thing the device controller. The device controller is a piece of hardware and when we connect a device to a computer we does this through a plug and socket. The socket is connected to the device controller. So, now we have a way of getting and interpreting those signals. But how does the Operating System interact with the device without having to know everything about the device family and it’s language? We need an interface that acts as a middle man that the Operating System can talk to. This interface is known as the Device Driver. The device driver is a software interface whereas the device controller is a hardware component. The device driver operates the device on behalf of the operating system. But through what medium do all these things communicate?
There is a set of wires that they device controllers and CPU all have access to, allowing them to communicate through signals. This set of wires is called the bus. This bus also connects to main memory. If you look at the diagram below you can see generally how this works.
As we can see from the diagram, a CPU is also connected to the bus. CPU stands for the Central Processing Unit. The CPU performs the instructions of a program. It can perform basic arithmetic and logic computations. You can think of it as kind of the brains of the computer. A computer can have more than one CPU, and so the bus can be connected to one or more CPUs.
So each device controller has a temporary holding place for data, this holding place is called a buffer. The CPU moves data to and from main memory as well as to and from the buffer of the device controllers. The Input/Output (I/O) operations from data to and from the hardware devices to/from the buffer of the device controllers. If a request comes in from say, a mouse click, then this is interpreted by the device controller. An interrupt is then sent to the CPU to tell it to stop what it is doing and to process the request, it then transfers the data from that back to the device controller who can send a signal back to the mouse. It can then send another interrupt back to the CPU to tell it that the request is complete and the CPU can continue what it is doing.
So we have introduced a new term here; interrupt. An interrupt is basically a signal to the CPU telling it to stop what it’s doing and to start doing something else instead. When the CPU receives an interrupt, the CPU will stop what it is doing and the state of what it was doing, so it can continue from where it left off later. It then executes something called an Interrupt Service Routine (ISR). It does this through a table of values that contains a list of ISR’s and interrupt requests. The entries of the interrupt vector table are called interrupt vectors and they are the address of the ISR. This is how the CPU knows what type of interrupt it is and how to handle it. So there are different types of interrupts. There are software and hardware interrupts. A software interrupt is also known as a trap or exception. This can be caused by an error or a user request. So an operating system is interrupt-driven.
We have said that when an interrupt occurs, the state of the work that the CPU was working on must be saved so that it can continue it after the interrupt has been handled. The Operating System saves the state of this in registers and with a program counter. A program counter just contains the memory address of the next instruction to be executed. This means that when the CPU returns to it, it can check the program counter, and immediately find were it left off in memory. A register is simply a temporary holding place for data but it can be faster to get information to/from a register than from main memory.
So we know what happens to the CPU when an interrupt occurs, but what about the user? There are two options here. The first is that control may only return to the user after the I/O operation is complete. The second is that control may return to the user after the I/O operation begins and the user doesn’t have to wait for completion.
Main Memory
Main memory has been briefly mentioned before, so we will take the time to explain this concept before we continue. Main memory is the only storage form other than registers/buffers that the CPU can access. It is volatile. This means that when you turn off your computer, everything saved in main memory will disappear. You may often hear main memory being called RAM which stands for Random Access Memory. Random Access means that a piece of data can read read or written as fast as any other piece of data, no matter where it is stored in memory. Main memory is primary storage as it is directly accessible by the CPU whereas secondary storage is not. Examples of secondary storage are hard disks and solid state drives (SSD’s). This form of storage is non-volatile, meaning that anything stored here will remain here once the computer is turned off.
Storage Systems
Storage systems are arranged in a hierarchy according to speed, cost and volatility. Before we delve into this, we might want to gloss over a few terms. Caching is transferring information into a faster form of storage so that it can be quickly retrieved again. Main memory can be viewed as a cache for secondary storage.
It is worthwhile looking a little deeper at the cache. As we have already stated, when we want to retrieve information quickly, we can move it to a faster form of storage temporarily. So say I wanted to order a pizza and I need to get the phone number (Do people still call takeaways?) of the pizza place. I search my computer for the phone number and first it will check the cache to see if it’s there and if it is, it can pull it up immediately. If it is not, the phone number will be found and then it will be copied to cache in case it is needed again soon (which it most definitely will!) and can be retrieved more quickly.
Now there are different ways of accessing memory. There is the method we have already looked at in which the CPU transfers data to/from the buffer of the device controller to/from main memory. There is also Direct Memory Access. Direct Memory Access is used for high speed I/O devices. The device controller of the device transfers the block of data from the buffer directly to main memory without the need for the CPU. This means that while I/O operations are occuring, the CPU can continue to do other work. With Direct Memory Access, all the CPU needs to do is start the transfer. Once it has done this, it can go back to doing whatever it was doing while the transfer it occuring. It will then receive an interrupt from a controller when the transfer is complete.
Types of Systems
There are different types of systems based on the CPU.
A multiprocessor is a computer system that has two or more CPUs. Having multiple CPUs in a single machine has a number of benefits associated with it. One of them being increased throughput. Throughput refers to the amount of work that can be done in a given time period and more precisely in computer science, it refers to the rate at which something can be processed or data can be transferred. Another advantage that multiprocessing brings about is Economy of Scale as a single system with multiple processors is often cheaper than multiple systems with single processors. Another benefit is increased reliability. The multiprocessor has more reliability as the workload is balanced over multiple processors and so if one fails or malfunctions, the system as a whole doesn’t fail. There are two types of multiprocessing. These are symmetric and asymmetric. In asymmetric multiprocessing, each CPU is assigned a unique task. This was mainly used before symmetric multiprocessing was developed but is still used today in some cases. With symmetric multiprocessing all CPUs can perform all tasks.
Another type of system is a clustered system, which basically is just multiple systems working together. They can share storage over a network called a shared area network. Clustered systems are good for avoiding failures as, like we saw with the CPUs in multiprocessors, if one computer system fails the clustered system as a whole stays up and therefore they offer more reliability. Some cluster systems are made for high performance computing. High Performance computers do exactly as the name says, perform highly compared to general purpose computers. They can be used for various fields such as quantum mechanics, simulations, environmental research and molecular research but the list goes on. Applications run on high performance computers must be written to be carried out simultaneously. This is known as parallelisation. With parallelisation, a large problem can be broken down into a series of smaller ones. These smaller ones can then be solved simultaneously.
A multiprogramming system is where programs are run interchangeably. For example, If I have 3 programs to run, I might run program A then if that needs to get something from memory, I can run program B. Maybe at some point while it is executing, program B needs to wait for input from an I/O device so then I can start running program C. I can do this until all programs have run. This type of system is very good for efficiency as the CPU is always kept busy. There is always a job for the CPU to execute. In computer science, a job is a unit of work.
In a multiprogramming system, the CPU switches between jobs so frequently that it appears to the user like they are being executed simultaneously.
Process Management
A process is a program in execution. But what is a program then? Let’s us a brief analogy to explain these two concepts. If I write down on a piece of paper:
- Raise left hand.
- Raise right hand.
- Move hands side to side.
And then I give this paper to you and tell you to follow the instructions on it, when you are doing that, you are in the process of executing those instructions. The program in the sheet of paper with the instructions on it before I passed it to you. So a program is just a set of instructions. A process is the acting out of those instructions. Therefore a program is a passive entity as it is acted upon and a process is an active entity as it acts itself.
The Operating System is responsible for these tasks in relation to processes:
- Creating and deleting processes.
- Suspending and resuming processes.
- Providing mechanisms for process synchronisation.
- Providing mechanisms for processes to communicate.
Memory Management
The Operating System also has to look after Memory Management. For a program to be run, it must be in main memory. The data needed by that program must also be in main memory. So managing memory means determining what will be in memory and when it will be in memory.
Storage Management
A file is a logical storage unit. The OS has many activities to perform in relation to file system management. Files are organised into directories on your computer. A directory is just a structure which contains files. The OS must:
- Create and Delete files/directories
- Manipulate files/directories
- Map files to secondary storage
- Backup files
Protection and Security
The OS must control access of processes or users to resources and this is called protection. The OS must also defend the system against internal or external attacks. This is referred to as Security. The system has to distinguish among different users to see who is allowed to do what. Each user will have their own ID which will be used to determine what they have access to, but sometimes a user can change their id to one with more privileges. This is known as privilege escalation.
Services of an Operating System
User Interface:
The Operating System will provide a way for the user to talk to the user. A user interface is the space in which the user and the computer interact. This can be graphical (GUI) or on a command line (CLI).
Program Execution:
The Operating System must execute programs. This means loading the program into main memory, executing the instructions and then terminating it.
I/O Operations:
An Operating System is responsible for I/O operations. If a program needs to conduct an I/O operation then the Operating System must provide a way for it to do this.
File System Manipulation:
Programs will need to read/write/create/delete/search files and so the Operating System must ensure this is possible.
Error Detection:
An Operating System must be aware of possible errors. These can occur in any aspect of the computer. If an error is found, the Operating System must know how to deal with it make sure nothing else is affected.
Resource Allocation:
The Operating System must allocate resources to users or jobs. These resources include memory, I/O devices, file storage and more.
Accounting:
The Operating System keeps track of the users, how much resources each user uses and what resources the user uses.
Protection:
As we have said, the Operating System must control user and process access to resources. It does this by checking the user or process id.
Security:
The Operating System safeguards the system with user authentication and preventing invalid access to I/O devices.
So we have mentioned a Command-Line Interpreter (CLI) and a Graphical User Interface (GUI) but what exactly are these things?
Command-Line Interpreter
A command line interpreter allows you to make direct commands to the Operating System. It receives a commands from the user and executes it. So you interact with the computer through lines of text.
Graphical User Interface
The Graphical User Interface allows you to interact with the computer through visual icons. Using a GUI means that as a user, you don’t have to learn all the commands to be able to use a computer, all you need to do it know what button to press. The desktop metaphor was invented at Xerox PARC. The genius of this is that it resembles an office desk so it made using a computer extremely intuitive. All our files look like files and our folders look like folders.
Most systems now use both a GUI and a CLI.
Types of System Calls
We previously mentioned that a system call is a request to the kernel and it is used to switch between user and kernel space but there are different types of system calls and these align with the different services of the operating system.
So there is:
- Process Control: Responsible for creation/deletion/maintenance of processes
- File Management: To open/read/write/create/delete files.
- Device Management: Request/Release Device, Attach/detach Devices
- Information Maintenance: Get/Set Time/Date/System Data/ Process/File
- Communications: Create connections, send/receive messages
- Protection: Control Resource Access, Allow/Deny User Access
System Programs
System programs are used to program the Operating System and provide services to other programs. We have discussed Application programs which provide services to users. So what do they do?
They allow for:
- File Management
- Status Information: Retrieving the date/time/available memory. Some may also provide performance logs and debugging information. Some systems have a registry which is used to store and retrieve configuration information.
- File Modification: To edit or search contents of files.
- Programming Language Support: Tools to help the system understand a programming language and to provide translation services between that programming language and machine code.
- Program Loading and Execution: Load program into main memory and to run it, creating a process.
- Communications: Providing ways for processes/users/computer systems to communicate with each other.
- Background Services: They launch when the computer has just started up. Some help start up the system and then they will terminate after this. Others will run until the system is shut down again. They run in the user space. They are known as daemons.
- Application Programs: These are run by users and are not part of the OS.
Operating System Design
So we now know a good deal about Operating Systems, how they function, what they are composed of. But how do we design one? What is important for an Operating System to have and how do we decide this?
You start designing an Operating System by deciding on the goals and specifications. What does it need to have? What would you like it to have? There are User and System Goals and these different goals will pertain to the two different viewpoints. Users want a system that is easy to use, convenient, reliable, safe and doesn’t have a steep learning curve to use it. On the other hand, Systems want a system that is easy to design, implement and maintain. It should be flexible, reliable, error-free and efficient.
There are two important principles in the design of Operating Systems. This is the separation of what we are doing from how we are doing it. What we are doing is known as policy whereas how we are doing it is known as the mechanism. This separation is important as it allows for flexibility if policy decisions get changed later. So we should have general mechanisms and specific policies so that if a policy changes, not much changes are needed for the mechanism.
Operating System Implementation
Operating Systems are written in various programming languages. Before we mention any languages, we should understand the different layers and types of languages.

So at the core is the hardware upon which the machine code interacts with it. Machine Code instructions can be directly executed by the CPU. The machine code instructions are written in binary (1’s and 0’s) or hex (0-F). Above this, we have assembly language which is a low level programming language. The assembly code instructions are converted into machine code instructions by an assembler. This language is closer to human language in terms of our understanding but is still not quite there. Above this we have our high level programming languages. This is highly abstracted from the hardware. It can look very similar to human language and so is easier to understand and write.
So in the implementation of an Operating System, many languages have been used. Most early ones were written in assembly language and then they were soon written in system programming languages. System programs used to be written in assembly but then a high level language was used for system programming. Not included in the diagram above are mid-level languages which are similar to high level languages in terms of human language elements but they also have more direct access to the hardware and machine code. So, system programs were used to implement the Operating System programs and these system programs were written in assembly language or a mid-level language.
Higher level languages are easier to port to other hardware as they are more abstracted from it and so don’t require much changes based on the hardware details. Porting just means adapting software to run in another computing environment. Emulation allows one computer system (the host) to behave like another computer system (the guest). This is done via an emulator. This means that systems can run software that was not designed for that system.
Debugging
Debugging is the process of finding and fixing errors in software. The Operating system will keep records of the errors that it finds in the system. If an application program fails, it will generate a file called a core dump. If the Operating System itself fails, it will generate a file called a crash dump. The Operating system will also keep records to improve performance. The Operating does this by periodically checking the program counter (remember, this contains the address of the next instruction to be executed) and recording it so that it can be analysed for statistical trends. This is called Profiling. The Operating System can also keep records of program execution. These are called trace listing and these records can also be used to improve performance.
There is a principle I find amusing called Kernighan’s Law which states that “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
So this concludes our explanation of Operating Systems, but we are not quite done yet. Soon we will be delving into topics such as processes and memory which will build upon what we learnt here.
Leave a comment