Home Practice
For learners and parents For teachers and schools
Textbooks
Full catalogue
Leaderboards
Learners Leaderboard Classes/Grades Leaderboard Schools Leaderboard
Pricing Support
Help centre Contact us
Log in

We think you are located in United States. Is this correct?

2.2 Compilers and interpreters

image

image CHAPTER OVERVIEW

Unit 2.1 Types of operating systems
Unit 2.2 Compilers and interpreters
Unit 2.3 Overview of processing techniques
Unit 2.4 Virtual machines and virtualisation

image Learning outcomes

At the end of this chapter you should be able to:

  • describe the various types of operating systems in terms of cost, size, hardware needed and platform
  • explain what language compilers and interpreters are
  • describe and compare three different processing techniques: multi-tasking, multi-threading and multi-processing
  • give the purpose and examples of virtual machines
  • describe virtualisation

INTRODUCTION

Android succeeded in making smartphones useful, everyday tools that anyone could use. It has millions of applications that users can install - most of them free. It allows people to easily connect to the internet and allows people from across the world to access the internet from their homes. Smartphones also replace many devices including phones, digital cameras, alarms, music players and even computers. Finally, it works with a larger number of different devices, many of which are affordable. Thanks to a combination of these factors, Android was installed on 85% of all smartphones in 2018 and 42% of all computers (including desktop computers, notebooks and servers). In contrast, the iOS operating systems (used by iPhone) work on a very small number of expensive devices.

image
Figure 2.1: The first Android-based smartphone, the HTC Dream (photo by Akela NDE)

In this chapter, you will learn more about system software, including operating systems like Android. The chapter will start by looking at operating systems in greater detail, before looking at a few of the different processing techniques that is, memory systems software. The chapter will then look at how application instructions are converted into a language your CPU can understand, before ending with a look at virtual memory and virtualisation.

image
Did you know

A 2015 study found that there were more than 25 000 unique hardware devices running the Android operating system.

Let’s refresh your memory on software and operating systems by reading the Software in a nutshell section.

image
New words

virtualisation: - refers to the act of creating a virtual (rather than actual) version of something

utilities - small programs which help users to maintain their computers

system software - a type of computer program that is designed to run a computer’s hardware and application programs

user interface - the way in which people interact with computer programs or a website

driver - a set of instructions that tells the operating system how to communicate with a specific piece of hardware

stand-alone operating system - a complete operating system that works directly on a computer (or smartphone) to make sure that the tasks of the operating system are completed

network operating system - an operating system that is designed to help other computers on a network

embedded operating system - an object, software or hardware that is independent and does not need an external program or device to run it

SOFTWARE IN A NUTSHELL

Software refers to digital items made up of 1s and 0s that tell your computer what to do. There are many different types of software, including applications, games and utilities. However, the focus of this chapter will be on a category of software called system software, which is responsible for managing your computer. It does this in several important ways, including:

  • translating the instructions from your software to a language your hardware can understand
  • sending these instructions to the correct hardware
  • receiving information from the hardware (such as button presses on a keyboard) and sending it to the software
  • allowing different applications to communicate with each other
  • making sure all the hardware and software on your computer are working correctly.

The most important type of system software is the operating system, which controls your hardware and software, provides a user interface for users to interact with, and manages the resources of the computer.

The operating system has thousands of small tasks that it processes to ensure your computer continues to run smoothly. These tasks can be summarised as:

  • managing and interpreting the signals sent and received by your hardware
  • understanding and communicating with different hardware devices using drivers
  • managing a computer’s memory and storage
  • monitoring your hardware’s performance
  • providing an interface for users to interact with the computer
  • allowing the computer’s hardware to interact with its software
  • allowing computers to connect and communicate over a network.

In Grade 10 you learned that there are three main types of operating systems: stand-alone operating systems, network operating systems and embedded operating systems.

Stand-alone operating systems can work directly on computers (or smartphones, like Android) and make sure that the tasks of the operating system are completed. Almost all home computers, office computers and smartphones use stand-alone operating systems.

Network or server operating systems are operating systems that are not designed to be used on their own, but rather to help other computers on a network. These operating systems form the backbone of the world’s largest network: the internet. Finally, embedded operating systems are operating systems designed to be used on a single device with a very specific purpose (such as a SmartTV or video camera).

Activity 2.1 Revision activity

2.1.1Name the TWO broad categories of software.

2.1.2List two ways software helps manage your computer.

2.1.3What Is an operating system?

2.1.4Briefly explain three tasks that the operating system does to ensure that a computer runs smoothly.

2.1.5Give ONE difference between a stand-alone operating system and a network operating system.

2.1.6Can the committee member load both operating systems? Briefly motivate your answer.

UNIT
2.1 Types of operating systems

Operating systems play a critical role in many different areas of a computer’s functioning, including the computer’s:

  • hardware
  • software
  • processes
  • storage
  • memory
  • networks

In this unit, you will look at the three operating systems (stand-alone, network and embedded) you already know in more detail.

Table 2.1: Comparison between various operating systems

image

image Activity 2.2

2.2.1Fill In the missing words in the crossword puzzle below.

image

image

UNIT
2.2 Compilers and interpreters

Programming languages have been designed so that humans can read and write it more easily.

image
Figure 2.2: Programming languages are designed to be understood by people

image
New words

machine code - The executable instruction code provided by all running computer system programs and applications

binary - describes a numbering scheme in which there are only two possible values for each digit: 0 and 1

hexadecimal - describes a numbering system consisting of 16 digits [0 ... 15]

Most modern programming languages value the importance of programming code that is simple, easy to read and easy to use.

Unfortunately, because programs are made up of lines of code, they are often not as simple to read or understand as you might want them to be. Programs in a modern programming language are still much, much easier to understand than machine code. Machine code refers to the instructions delivered directly to your CPU and is written in binary (or hexadecimal) and gives instructions. This might include references to memory addresses, logical operations or any other instruction for your CPU to complete.

Your CPU can only understand interpreted or compiled code. In this unit you will learn about interpreters and compilers and see how they differ.

INTERPRETER

In computer terms, the programming interpreter reads the first line of the code, interprets it into machine code and sends it to the CPU to be processed. It then interprets the next line and sends that to the CPU, and so on. By interpreting the program line by line, the program can immediately start running. However, since every line needs to be interpreted before it can run, the program will often run a bit more slowly than a compiled program. The source code is interpreted as the program is run, the interpreter (and interpreted language) must be installed on the same computer that the program is running. An example of an interpreted language is JavaScript.

COMPILER

In contrast to an interpreter, the compiler takes the entire source code and translates it into machine code. This translated code is saved as an executable file on the computer that can be opened on any computer without requiring the computer to have a compiler. Examples of compiled languages include BASIC, C++, Delphi and Java.

image
Video

Animation comparing an interpreter and a compiler.

Interpreter looks at line of text, converts it to random binary, then sends it to CPU. It does this line for line and the application shows on a monitor. Compiler reads all the lines, then converts all lines to random binary, then sends the whole bunch to the CPU. While all this is happening, a monitor shows a loading sign.

The following table summarises the main differences between interpreters and compilers.

Table 2.2: Summary of the main differences between interpreters and compilers

image

Follow the QR link in the margin to watch an old but very simple video explaining the difference between compilers and interpreters.

image Activity 2.3

2.3.1List TWO differences and similarities between programming code and machine code.

2.3.2You are interested in IT and are work-shadowing at a friend’s IT business for the holidays. You know that programming language is a lot easier for people to read. Unfortunately, your CPU cannot understand this program since it only understands machine code. To solve this problem, you need an interpreter or compiler.

a.What is an interpreter?

b.Explain how an interpreter works.

c.List TWO ways how a compiler is different from an interpreter.

d.List ONE advantage a compiler has over an interpreter.

image
QR CODE

UNIT
2.3 Overview of processing techniques

On very old operating systems, you could only load one program into the computer’s memory at a time. This means you could only run one program at a time! When this program was not doing anything, the CPU would also not be doing anything. Today, most people would not be happy with a computer that could only run one task at time; they want to be able to multitask!

On a computer, multitasking allows you to run multiple tasks (also called processes or applications) at the same time. For example, you may want to listen to music while browsing the internet on your computer. More than this, you want your computer to continue running all its background services like checking for emails, updating applications and managing your network at the same time.

image
Figure 2.3: Modern operating systems allow you to open multiple tasks at the same time

Example 2.3.1 How many processes are you running?

On Windows 10, you can see a list of all these tasks running in the background by opening the Task Manager. To open the Task Manager.

  • Open your Start Menu and enter the words “task manager”.
  • Open the Task Manager desktop application that is found.

You can also open the Task Manager by pressing the CTRL-SHIFT-ESC hotkey on your keyboard. Once opened, you will see a list of every process running on your computer. On most Windows 10 computers, there will be more than 50 applications and processes running at any time.

image
Figure 2.4: Example of searching for ‘task manager’ in the start menu

So how can a single CPU complete various tasks for dozens of different processes at the same time? The CPU completes tasks using the following techniques:

  • multitasking
  • multiprocessing
  • multithreading.

Let’s look at each of these processing techniques.

image
Did you know

One reason why your smartphone’s battery discharges even when the screen is turned off and you are not using it, is that your CPU is still running tasks. This includes checking for updates, looking for and downloading messages and emails, and making sure you are connected to an internet-enabled network.

MULTITASKING

Figure 2.5 shows an example of the Windows Task Manager application. As the image shows, only 3% of the CPU is being used. This means that there are times when the CPU is idle and waiting to receive new instructions.

image
Figure 2.5: Only 3% of this CPU’s capacity is being used

image
New words

multitaskin - the ability of the OS to quickly switch between many computing tasks to give the impression the different applications are executing simultaneously

multithreading - operations within a single application are divided into threads. Each of the threads can run in parallel. The OS divides processing time among each thread within the application

threads - a way for a program to split itself into two or more simultaneously running tasks

Rather than waiting for a single program to send new instructions, processor multitasking allows the operating system to send instructions from different processes to a single processor. If the instructions are sent and completed quickly enough, the processor can complete all the instructions from multiple applications without causing any of the applications to slow down. In this way, you can run multiple applications (or processes) on one processor seemingly at the same time.

MULTIPROCESSING

Where both multitasking and multiprocessing use the same processor to quickly swap between different tasks or threads, multiprocessing uses multiple processors to complete tasks. Today, many CPUs (including smartphone CPUs) are made up of more than one processor (called a core). Each core is then able to complete program instructions on its own.

image
Did you know

In 1975, the computer scientist, Fred Brooks, said that just because it takes one woman nine months to make a baby, it does not mean that nine women can make a baby in one month. This is known as Brooks’ law and it is also true for multiple processors!

Technically, a CPU with four cores should be able to complete four times as many instructions as the same CPU with only one core. However, in practice this is not always the case. For example, in most applications the instructions need to be executed one after the other. When this is the case, it does not make sense for one core to complete the first instructions while another core completes the last instructions.

image
QR CODE

image
QR CODE

Multi-core processors therefore allow you to process multiple threads or multiple processes more quickly but may not improve the performance on any single process.

Example 2.3.2 How are the processors being used?

The Task Manager can also show how each of the processors is being used. To see the processor utilisation:

  • Open the Task Manager and go to the Performance tab.
  • Right click on the graph and hover over the Change graph to option.
  • Select the Logical processors option.

The graph should change from a single graph to a few smaller graphs with each graph showing the utilisation of one of the processors. The Ryzen 5 1600X CPU has twelve logical processors, so the figure below shows how much each of these processors has been used over the last 60 seconds.

image
Figure 2.6: Utilisation of a computer’s twelve logical processors

MULTITHREADING

Where multitasking allows your computer to complete the instructions for different processes by quickly switching between them, multithreading completes the instructions for multiple different tasks inside the same program (called threads) by quickly switching between them. Instructions from the same program are divided into multiple threads. Each thread can be run independently and executed when the CPU has time available between tasks.

Imagine that you are browsing the internet and decide to download a large file. If a program could only run one task at a time, you would have to stop browsing the internet while your browser downloads this file, and you would only be able to continue browsing the internet once the download has completed.

Fortunately, multithreading allows your computer to split this task into separate threads, with one thread managing the downloads while another thread manages your browsing. Your CPU can then quickly swap between these threads, so that both your downloads and your browsing continue without interruption.

Example 2.3.3 How many threads are you running?

The Task Manager not only shows the number of processes open on your computer, but also the number of threads running. To see the number of threads:

  • Open the Task Manager
  • Click on the Performance tab at the top of the Task Manager
  • Select the CPU graph from the panel on the left

In the main window you will see a graph showing how much of the CPU’s total capacity has been used over the last 60 seconds. Right underneath that is a lot of numbers, including the number of processes (211 in Figure 2.6) and threads (2 723 in Figure 2.6). Based on the figure, there are therefore roughly 13 threads open for each process.

image
Figure 2.7: The processes and threads are shown in the Performance tab

The following table highlights the differences between multiple threads and multiple processes.

image
New words

multiprocessing - the use of two or more CPUs within a single computer system

core - the processing unit that receives instructions and performs calculations or actions based on those instructions

image
Did you know

Multithreading is simply multitasking within the same program!

image Case Study Virtual memory

A technique used by the OS to increase the capacity of the RAM by creating a temporary or dedicated file on the hard disk drive. This allows the user to execute applications, which require more RAM than is physically availabe on the computer. This file is called a page file. When this happens, your computer can become incredibly slow as it is constantly busy moving data between your RAM and virtual memory. If this issue becomes serious enough, your computer can get stuck in a loop where it takes so long to load data into your RAM, that by the time the data has been loaded, it immediately needs to unload that data to make space for new data. This is called thrashing.

image Activity 2.4

2.4.1On a computer, multitasking allows you to run multiple tasks at the same time. Look at the image below and answer the questions that follow.

a.How many tasks are running at the same time based on this image?

b.Give another name for a task that runs on a computer.

c.Give TWO advantages of multitasking on computers.

d.Give ONE disadvantage of multitasking.

2.4.1Do the following tasks on a computer that runs Windows 10. Using what you have learnt. Determine the following:

a.How many processes are running on the computer’s operating system?

b.How many threads are running on the computer’s operating system?

image

UNIT
2.4 Virtual machines and virtualisation

Virtualisation is the act of creating a virtual device. Each virtual device acts as a node and is allocated its own virtual hardware, CPU, RAM and storage space.

These virtual machines behave in the same way as a real computer. For a virtual machine to be created, the host machine has to be capable of hosting a virtual machine. A virtual machine must have its own operating system and its own applications installed. The different virtual machines also do not have access to the host computer or any of the other virtual machines.

image
QR CODE

USES OF VIRTUAL MACHINES

The following list gives some of the most popular reasons for using virtual machines:

  • Virtual machines allow users to install operating systems. If you wanted to test out an open source operating system like Ubuntu, then a virtual machine allows you to do so without interferring with your computer.
  • Virtual machines can be used to install an application that might contain a virus. Testing it on a virtual machine will allow you to see if the application contains a virus. If it does, you can simply delete the entire virtual machine.
  • The image of the virtual harddrive can be used to back up your computer, or to transfer all your data to a new computer.
  • Virtual machines enable mobile developers to develop applications for different versions of Android and iOS without having to own hundreds of different devices.

image
QR CODE

If you want to see how to create your own virtual machine, you can follow the QR code in the margin.

image
Figure 2.8: Screenshot on how to set up a virtual machine

image
QR CODE

image Activity 2.5

Discuss the following in groups

2.5.1What is a virtual machine?

2.5.2What can virtual machines be used for?

2.5.3From what you have learned, what are the advantages AND disadvantages of such machines?

CONSOLIDATION ACTIVITY Chapter 2: Software

1.Choose the correct answer.

a.Which is NOT an example of a type of processing?

A. Multithreading

B. Multitasking

C. MultiRAM

D. Multiprocessing

b.Which one of the following is a function of software?

A. Translating the instructions from your software to a language your hardware can understand

B. Sending these instructions to the correct hardware

C. Making sure all the hardware and software on your computer are working properly

D. All of the above

c.Which one of the following best describes a Stand-alone system?

A. To provide a service to or manage computers connected to the same network.

B. To manage the hardware and software of a computer and to provider a user interface for computer users.

C. To run the software for a specific appliance or tool.

D. To connect different computers and present them as a single computer

d.Which one of the following converts programming language for humans to understand?

A. Compiler

B. Convertor

C. CPU

D. Python

e.What is a task also known as?

A. Process

B. Application

C. Network

D. A and B

2.Choose the answer and write ‘true’ or ‘false’ next to the question number. Correct the statement if it is FALSE. Change the underlined word(s) to make the statement TRUE. (You may not simply use the word ‘NOT’ to change the statement.)

a.With processor multitasking, a single processor splits its time between different processes.

b.Distributed operating systems are almost always sold as part of the hardware devices.

c.Machine code refers to the instructions delivered directly to your CPU

d.Windows 10 is an example of an open source operating system

e.Virtual machines help you to write and test programs for different operating systems.

3.What is system software?

4.List TWO ways system software allows your computer to run smoothly.

5.What is a network operating system?

6.Give TWO principles that all Python programmers should follow.

7.Briefly explain how an interpreter works in a computer.

8.List THREE different processing techniques a CPU uses to complete a task.

9.Briefly explain how virtual machines can allow multiple people to use the same computer at the same time.

10.In the IT workshop there is a lot of debate that goes on. One of the junior technicians who is just out of school starts asking questions.

a.He has heard of multitasking and asks what it is. Describe in your own words what you understand by the term multitasking.

b.Explain how multithreading works and give an example.

11.Having the world at your fingertips through Internet so commonly used nowadays, you and your cousin decide to take your entrepreneur business to the next level. Your computer has a single core CPU. State if the following processing techniques will be able to take place. Motivate your answers

a.Multi-tasking

b.Multi-processing

12.List TWO differences between multi-processing and multi-threading.

13.In need of more memory, you decided to make use of virtual memory.

a.What is virtual memory?

b.How does the computer make use of virtual memory?