5.1 Operating Systems

Specification

  • Explain why a computer system requires an Operating System (OS)

  • Explain the key management tasks carried out by the Operating System

    • Including memory management, file management, security management, hardware management (input/output/peripherals), process management

  • Show understanding of the need for typical utility software provided with an Operating System

    • Including disk formatter, virus checker, defragmentation software, disk contents analysis/disk repair software, file compression, back-up software

  • Show understanding of program libraries, including

    • software under development is often constructed using existing code from program libraries

    • the benefits to the developer of software constructed using library files, including Dynamic Link Library (DLL) files

Be sure to read the 'General software definitions' page.

Introduction to Operating Systems

An operating system (OS) is the most important piece of software on your computer. It is the program that runs and manages your computer. This involves quite a few different jobs.

  • It makes sure all of the hardware and peripherals are working together without a problem.

  • It organises the software and files on your computer.

  • It manages you RAM so that programs are run successfully.

  • It is responsible for keeping your computer secure.

  • It provides you with a user interface, so you can actually use the computer.

You probably know the names of some operating systems. These include Windows (Windows XP, Windows Vista, Windows 7, Windows 8), Linux, Ubuntu, iOS, Android, Chrome OS, Chromium OS and so on. If you do a search online, you can find out about lots of them and the strengths and weaknesses of each type of operating system compared to other the types.

Booting up your computer and your user interface

When you boot-up your computer, the program in ROM carries out the Power On Self Test (POST) to check your computer is working correctly. Then it finds the operating system on the hard drive, copies it into RAM and hands over control to the operating system. The operating system then takes over. Some programs e.g. your virus checker, you have probably set to start automatically, so the operating system will start that program running. It will then display a 'user interface' on your monitor. It will display buttons and icons and words that you can click on, double-click, right-click and so on. You can now access the computer. We don't know how any of those complicated bits of hardware work, but we do know how to use a keyboard and mouse and click on things - that's what the user interface lets you do. It's the mouse, the keyboard, the touchscreen and what you see on your screen, all working together.

Making the hardware work together

The operating system makes all of the hardware work together. If there is a problem, it will try to fix it or give you an error message to help you fix it. If you decide to plug a new piece of equipment into your computer e.g. a printer or a pen drive, the operating system will detect that you have done this, check it can work with it, load up any additional software it needs and then tell you that you can use it.

Organising applications and files

When you load up software, the operating system organises where they will be stored on the hard disk. You might tell the computer what folder to put some software in, but ultimately, in the background, the operating system is organising it all. It's the same with your files. When you save a file, you might put it in a folder. That's you using the user interface but in the background, the operating system is actually deciding where and how to organise your work. You see your 'human' view of organised folders and files but the operating system works in the background to save things as it needs to.

Running programs

You might have lots of different programs running at once. These might include a virus checker, a music program, a chatroom, a web browser and so on. As you know, programs must be in RAM for the CPU to be able to run them. They must be organised in RAM in such a way so that they don't interfere with each other and make a program or the computer crash. Guess what? It's the operating system's job to manage the memory so that programs and files are nicely organised when they are copied into RAM.

Interrupts

Interrupts are central to operating systems, as they provide an efficient way for the operating system to interact with and react to its environment. Interrupt-based programming is directly supported by most modern CPUs. Interrupts provide a computer with a way of automatically saving local register contexts, and running specific code in response to events. Even very basic computers support hardware interrupts, and allow the programmer to specify code which may be run when that event takes place.

When an interrupt is received, the computer's hardware automatically suspends whatever program is currently running, saves its status, and runs computer code previously associated with the interrupt; this is analogous to placing a bookmark in a book in response to a phone call. In modern operating systems, interrupts are handled by the operating system's kernel. Interrupts may come from either the computer's hardware or the running program.

When a hardware device triggers an interrupt, the operating system's kernel decides how to deal with this event, generally by running some processing code. The amount of code being run depends on the priority of the interrupt (for example: a person usually responds to a smoke detector alarm before answering the phone). The processing of hardware interrupts is a task that is usually delegated to software called a device driver, which may be part of the operating system's kernel, part of another program, or both. Device drivers may then relay information to a running program by various means.

A program may also trigger an interrupt to the operating system. If a program wishes to access hardware, for example, it may interrupt the operating system's kernel, which causes control to be passed back to the kernel. The kernel then processes the request. If a program wishes additional resources (or wishes to shed resources) such as memory, it triggers an interrupt to get the kernel's attention.

Security

The operating system will try to keep the computer safe and keep everyone's files safe. It might do this with some extra 'helping' software like a virus checker but ultimately, it's responsible for security. One job it does, for example, is to allow you to set up different accounts on the same computer, each with their own login and password. When someone logs in, they will only be able to see their own files and software and any that are public. They won't be able to see anyone else's files. The computer will also be set up with the settings for that user, so that it looks the way they want it. For example, it will have their own personal wallpaper as the background on the monitor.

The kernel (including memory management)

The kernel is the central part of the operating system software. It is loaded into the main memory when a computer is first booted-up and stays in the memory until the computer is powered down. It can be thought of as the main program that controls all of the other programs in a computer along with the hardware. It provides and manages the resources in a computer system, allowing applications to access and use these resources. The applications can never request these resources directly. They must go through the kernel. This protects the resources from any inadvertent accidents by the applications.

[The section on virtual memory and paging has now moved to 3.4.1.

Backing store management and the file system. The kernel is in charge of moving data from secondary storage devices such as a USB flash drive or a hard disk into main memory, and back again. It also keeps a file system for each storage device up-to-date so that it can find existing files, allocate space to new ones and keep track of all available space.

Hardware access. The kernal provides an interface between an application needing access to e.g. the DVD player and the actual DVD player itself. It does this by forwarding requests from the application to the software drivers that control whatever hardware is needed. A driver is simply the software program that controls a particular hardware device and acts as a buffer between the application and the kernal. Every hardware component has a driver that sits between the operating system kernal and the actual hardware device.

Interrupts, processes and multi-tasking. The kernel sets up the interrupt system so that the CPU can do many things apparently at the same time. An interrupt is a signal sent to the CPU that tells the CPU that an event has happened, so it needs to stop what it is doing and service the event. Typical events that might cause some software or hardware to send an interrupt include a piece of hardware suddenly not working, a printer needing a bit more data from a file that it is printing out or a signal from a piece of software that tells the CPU it needs do a bit more processing using the CPU. The system of interrupts set-up by the kernel allows the CPU to work on many jobs (called 'processes') at apparently the same time, called 'multi-tasking'. The key word here is apparently because the CPU can only ever work on one job at a time. However, it is so fast, and can switch between dozens of jobs so quickly, that it can seem like the CPU is doing many jobs at the same time. Every time the CPU gets an interrupt, it first of all decides whether it will work on the interrupt (depending on what it is currently doing, what other interrupts it has received and how important the interrupt is). Then it saves whatever it is doing in an area of memory called a 'process block'. Then it works on the routine that services whatever interrupt has happened and finally it loads back in whatever it was doing before the interrupt happened and carries on from wherever it was up to.

Operating system versus kernel?

It can be a little confusing understanding the difference between the operating system and the kernel at first. The kernel is the central part of and owned by the operating system. Everything that the kernel does is therefore part of what the operating system does. The kernel provides and manages the hardware resources in a computer system, allowing applications to access and use these resources. It does this by allocating memory, managing backing storage, controlling access to hardware and dealing with interrupts, managing processes and managing how the CPU is used.

An operating system is a collection of programs, including the kernel, that mange the whole computer. There are programs that are part of the operating system but not part of the kernel, including the program that provides the user interface, the program that provides automatic system updates, system reporting, developer tools and translators and so on.

Features of an Operating System

An operating system is a piece of software that looks after the management of a computer system. The actual facilities provided by an operating system will very much depend upon the design and type of facilities needed by a particular set-up. The needs of the following systems will all vary.

  • A batch processing system such as a bank-statement producing system.

  • A real-time system such as a system controlling a plane.

  • A personal computer.

  • An embedded system as found in, for example, a microwave or dishwasher.

  • A network with many users, as found in many schools.

For example, a real-time operating system may not have any need for memory management routines because the program and data to run a washing machine are held in ROM. There is no need to transfer data between RAM and secondary storage.

The features of personal computer operating systems

A PC operating system is a collection of programs and utilities. These manage the computer's hardware and software. The operating system looks after the basic functions of the computer. A computer is made up of a number of different components that have been connected together. Once connected to make a 'computer', however, the components don't start working together until an operating system takes control.

The operating system, then, is a piece of software that manages the basic functions of the computer. The jobs done by an operating system can be summarised using the following diagram.


These basic functions of an operating system include the following:

  • Making sure all the parts of the computer can work together.

  • Making sure that the user can interact with the computer by providing an interface.

  • Ensuring that any errors in the computer are reported to the user, usually with messages on the VDU.

  • Managing files on the hard drive and in memory and allowing the user to manage files by providing a file management utility program.

  • Making sure that data can be entered into the computer, displayed or saved by providing software that allows data input and output.

  • Providing utility programs such as FORMAT DISK, FILE MANAGEMENT or DEFRAG.

  • 'Scheduling’. The operating system provides programs that ensure the resources of the computer such as CPU time, are used as efficiently as possible by all the different users and the different jobs.

This Wikipedia page has an excellent section (under components), which list specific areas in detail. Some of which was used in the lesson's PP slides.

Utility Software

Operating systems come with a range of what is know as 'utility programs' for the user or computer to use. A utility program is simply a program that is part of the operating system which performs a commonplace task. We will have a look at some common ones in this section.

Anti-virus Software

Anti-virus software is used to help protect your computer against viruses. A virus is a program written by someone and distributed across the Internet, by email or by sharing storage devices. They are sometimes designed to do nothing more than annoy (like making your keys beep each time you press one on your keyboard) but they often do a lot of damage such as wiping your hard drive clean or allowing your computer to be accessed by a hacker remotely. As thousands of new viruses are written every week, it is important to ensure that virus patterns are kept up-to-date. This can usually be done automatically. There are free versions of anti-virus software and there are also many paid-for versions as well. These often come with many additional features and support if there is a problem. Sometimes, anti-virus programs are classed as an 'application' because some do many different things. Other times, they are very focussed on destroying viruses so are classed as a utility program.

Spyware protection

Spyware is software that installs itself on your computer and then gathers information about passwords, what Internet sites you visit and other confidential information with the aim of transmitting it to criminals to use. You can download spyware programs unwittingly when you download open source or free applications from the Internet so it is always a good idea to only download software from trusted web sites. There have even been instances of criminals setting up sites that look like they are offering free anti-spyware programs so you need to be careful. Anti-spyware applications are available from the Internet. One that has been around for a long time is Ad-Aware.

Firewalls

A Firewall is a program designed mainly to allow only authorised users access to a network and to stop worms and other malware from spreading across networks. A Firewall, according to the British Computing Society's 'A Glossary of Computing Terms', "is a computing program used in a large computing system to prevent external users (even if authorised) getting access to the rest of the system. Network users' access is restricted to a small part of the system and the firewall software prevents a user (including unauthorised users) accessing data or executing any programs in the rest of the system".

Formatting utility

Operating systems come with a utility that allows you to format devices when you connect them to your computer. Before you first use a storage device such as a hard drive, an SD card, a DVD or a pen drive, they have to be set-up for use. This is called 'formatting'. You will be storing lots of files on the device and they have to be organised so that the operating system can find them again. When you 'format' a disk, you are creating a table that will be stored on the storage device itself. As you add and delete files, the operating system updates this table and therefore keeps track of where everything is. Sometimes, these media come pre-formatted and sometimes, you have to do it yourself using the format utility program. Formatting will also check the disk for bad sectors and mark them as such, so they are not used. It is not unusual for disks to grow more unreliable or their performance drop as they are used, and this is where other disk utilities come in useful, such as degragmentation, backups and disk checking software (which do a similar job of scaning for bad sectors, but without wiping data), etc.

File transfer utility

Operating systems have a commonly used program to copy files across from one device to another. When you plug in a pen drive into a computer, the operating system detects that you have done this. Then, if you want to save a file to it, this utility program opens and takes over the moving of the file.

Defragmentation utility (usually known as 'defrag')

When you save a file or program on your hard disk or other storage device, it is tempting to think that it is all saved together. Unfortunately, that is not usually the case. When you save a file, the operating system looks at what space it has free on the hard drive and then breaks up the file into chunks. It then stores these chunks all over the hard disk, in whatever spaces are available. As long as the operating keeps track of where these chunks are, it isn't usually a problem because of the speed the CPU works at. Over time, however, if too many files are spread over a disk, it will start to take a long time to read those files back. The hard drive is a mechanical device that has moving parts. These moving parts have to move to collect each chunk of a file when you want to open it so that it can rebuild the file.The operating system has a defragmentation utility program that will reorganise these chunks so that they are next to each other or as close to each other as possible on the storage device. This will make it faster to get back files and also free up bigger spaces for files you save in the future.

System information, diagnosis and repair

Sometimes, you will want to know how much storage space is free on a hard drive, or how much RAM is stored, or what software you have installed and what hardware is working correctly. The operating system has tools that allows it to produce a range of reports to both report the current status of a computer as well as tools to help resolve any problems you have. If you do have a problem, you may find that your operating system has wizards which can help walk you through finding a possible solution. for example, if you are having problems accessing areas on a storage device, you could run the disk repair utility as that may solve the problem.

System clean-up tools

When you remove files and programs from a computer, you often leave behind bits of the files and programs that aren't required anymore or are out-of-date. By running your operating system's clean-up tools regularly, you can ensure that there are no unwanted pieces of software left on the computer, taking up space and possibly causing problems. When you use the Internet, many web pages you visit and programs you use will be downloaded and stored locally on your computer and you will also generate temporary files just by using your operating system. You can properly delete them all by using your operating system's clean-up tools. When you delete files, they are usually moved into a Recycle bin of some sort. This can then be periodically emptied as well.

Automatic updating

As problems are discovered with your operating system and with software and solutions found, and as newer versions of software become available, you should download and install them. In some cases it won't matter when you do it but in other cases, which involve security issues with your computer, it is important to download them as soon as they become available. You can set up your operating system to notify you when updates become available and to download and install them as well. This will ensure that necessary jobs are done in a timely fashion and not constantly put off.

File compression

File compression means that you take a file, some files or a folder and you give it to some compression software that 'squashes it'. This makes it much smaller than the original size. This is sometimes known as zipping up a file or folder. What file compression software actually does is to look at each file you want to compress and see if it can construct rules to reduce the size of the file. There are a number of reasons why you might want to compress documents. Compressed files and folders take less time to transmit across the Internet than the original files, because they are smaller. If you had, for example, video files or music files to send, which can be very large, this might be important. If you were the BBC and wanted to 'stream' video (where people watch the video at the same time the BBC is sending it) then you need your large files to be as small as possible or the video will slow or stop from time to time. You can store more files, programs and data on any storage device such as your pen drive if they are compressed. If you want to send ten files by email, an efficient way to send them is to first put them in a zip folder. The zip folder can be attached to an email in the same way that a file can be attached to an email. (Note, however, that you can't attach a normal folder to an email usually.)

There are lots of free data compression programs available and some that you have to pay for. Windows comes with a free utility program in the File Manager, just right-click and then select 'New' folder by 'Compressed Folder'. 7-Zip is open source and very good, as is the Hamster Free Zip application. You can also download and try out an evaluation copy of WinZip, another well-known compression utility.

Backing up data

Have you ever lost work you have done on the computer? Do you backup your work onto a pen drive every time you do some work on the computer? If you don't, you should! Given the amount of coursework you probably have to do, it is a wise approach keeping up-to-date backup copies of work that goes towards your final course grades! Your teacher would have told you to do this many times and you will get little sympathy from anyone if you lose work! Companies must also back up their work. If you lose your work, you can start again - not much fun but possible. If a company loses files they could go out of business. People could lose livelihoods. Data is valuable to an organisation. It takes companies years to build up a customer base. Getting data into a computer takes time. Businesses today are run on computers.

Operating systems usually come with utility programs to allow you to take back-ups. Typical options include the ability to take an entire 'snapshot' of your hard drive (called a 'system image') so that if your hard drive fails, you simply replace it, and then run a recovery program on a pen drive or CD that loads the system image onto your new hard drive. Another option is to schedule back-ups so that back-ups happen automatically at a particular time of day. You can also tell your computer to do a full back-up (all of your data files), only back-up files that have been added or altered since the last time you did a back-up (called an 'incremental back-up') or only back-up files from certain folders. Most people used to back-up to an external hard drive but it is becoming more common to back-up to cloud storage now.

The last point about back-ups to make is that an untested back-up should not be depended upon. You should periodically test files being backed up to see if the process has been working correctly. Unfortunately, some people do not do this and find out that their system has not been backing things up correctly only when their hard drive fails! This can be a disaster, of course.


Library Programs

Advantages of creating and using progam libraries

Top-down programming design for procedural languages

When faced with any complex problem, finding a solution may well appear a daunting task at first. However, with the right systematic approach, complex problems can be reduced to many far simpler problems. Each of these simpler problems can then be solved. They can then be re-combined back up to the original problem. Before you know it, that unsolvable, complicated task that you had to find a solution for has been solved! This approach has been around for years and is suitable for any problem that is going to be solved using a procedural programming language. This is a type of programming language that makes a lot of use of self-contained blocks of code that then interact with each other. It is not the best approach to use for other types of languages that you will learn about, such as object-oriented languages. The approach to use for this type of language will be discussed in much more detail later in the book.

In top-down programming, a programmer takes a task and then breaks it down into smaller tasks. They then take each smaller task and break it down further into sub-tasks. They continue to do this until each sub-task is simple enough to understand and program and, ideally, each sub-task performs only one job. The sub-tasks are then programmed as self-contained modules of code. When a problem is broken down into modules, the relationship between one module and the next is clearly defined. If we break down one module into three modules, for example, the relationship between the three modules is clearly defined so that together, they perform in exactly the same way that one big module of code would have performed.

Consider a module that calculates a salesman's commission. You could have one module that does this, but because it performs a number of different tasks, it will be split into three modules. This is shown in the next diagram.

  1. The first module is now responsible for initialising the program and reading in values. That is all it does. Its relationship with the main program is that it passes sales figures out to the program.

  2. The next module is responsible for doing the calculations. Its relationship with the main program is that it reads in sales figures and passes back commissions due.

  3. The third module is the display and print module. Its relationship with the main program is that it reads in commissions due.

The above design could be improved further. We have already said that ideally modules should perform only one function. The 'Initialise and read in data' module could be split into an 'Initialise' module and a 'Read data' module. The 'Display and Print' module could also be split into two modules, one called ‘Display’, which will be in charge of displaying results on a VDU, and one called 'Print' which will be responsible for printing out results.

Once modules have been identified, they can then be written. Remember, each module is a block of code that should be self-contained, perform one very specific task and will usually have an interface with the main program.

Different names for ‘modules of code’

Do note that different programming languages call modules of code by different names although they all (very broadly speaking) mean the same thing. One language might, for example, call a self-contained block of code a ‘module’ of code. Another one might talk about ‘procedures’ and ‘functions’. A third one might use the word ‘subroutine’.

Look at the next program. It has the name ‘commission’. Three procedures are written. The actual program is at the end of the code and is simply made up of calls to the procedures that have been written.

If you looked at the 'shape' of the final code for the problem just described, it might look something like this:

Program commission

Procedure InitialiseAndRead //procedure responsible for initialising variables and reading in data.

Begin

-------

-------

End

Procedure Calculate //this procedure is responsible for calculations.

Begin

-------

-------

End

Procedure DisplayAndPrint //procedure responsible for displaying & printing the output.

Begin

-------

-------

End

Begin //this is the program. It is made up of calls to the various procedures.

InitialiseAndRead

Calculate

DisplayAndPrint

End

The benefits of top-down programming design, including developing and using a library of code

Programs written using a top-down approach produce modules of code. We sometimes refer to this approach as ‘modular design’ or ‘modular programming’. Whether the modules are called procedures, functions, objects or anything else, they have some distinct advantages when compared to writing one big block of code.


  1. Splitting up a problem into modules helps get the job done more efficiently because modules of code can be worked on at the same time by different programmers. In addition, it helps because easier modules can be given to less experienced programmers while the harder ones can be given to more experienced ones.

  2. Splitting up a problem into modules helps program testing because it is easier to debug lots of smaller self-contained modules than one big program.

  3. Splitting up a problem into modules helps program readability because it is easier to follow what is going on in smaller modules than a big program.

  4. Splitting up a problem into modules improves a company's efficiency because self-contained modules can be re-used. They can be put into a library of modules. When a module is needed to, for example, display some values, you don't need to get the programmers to write and test a module for this again. You just re-use a module from the library. Over time, this will save a company a lot of time and money.

  5. Splitting up a problem into modules improves a Project Manager's ability to monitor the progress of a program. Modules can be 'ticked off the list' as they are done and this will demonstrate some progress. This is far harder for a Project Manager to do if the program has not been split up into modules.

  6. Splitting up a problem into modules is good for future program maintenance. If a program needs to be changed for any reason, it may be possible simply to remove one module of code and replace it with another.

Dynamic Link Libraries (DLLs)

Introduction

A DLL is a collection of executable programs.

What is a Dynamically Linked Library (DLL)?

These provide functions that can be called and used by Windows-based applications. An application that wants to use a particular function needs to create a link to the DLL. If the DLL is missing, then a message will pop up saying that it ‘cannot find XXX.dll’ or ‘call to undefined dynalink’. This can also happen if a program is trying to call a DLL that is not compatible with the operating system. This might happen because the DLL being called is too old for that latest operating system you have recently upgraded your computer to!! If this happens, you will need to locate the correct DLL on the Internet and install it. There are lots of sites that you can go to and download the DLL you need.

A DLL is, then, a shared program library that enables code to be saved separately from the main .EXE file. While this doesn't necessarily save space, it makes updating the program easier as you only have to replace a DLL file, not the entire program. As described below, DLLs are only loaded into memory when needed which can save space. Any processes making use of the DLL access a single instance, in that the DLL is only loaded once, even if used by a number of processes.

The lesson's slides give a number of advantages and disadvantages of using DLLs.

Device drivers are sometimes packaged as DLL files. (A computer's operating system needs a device driver if it wants to communicate with a peripheral such as a printer or a scanner). The system of having Dynamically Linked Libraries stored on the hard drive means that they do not have to be loaded into RAM until the point that they are needed. If you wanted to print a document, for example, then your application, for example, Word, would load the DLL only when you actually wanted to print something out. This saves space in RAM. Not only that but it also means that any Windows-based program can simply call the DLL. The developers of a new Windows-based application don’t have to re-write the DLL or some other code for printing, for example. By using existing DLLs, the developers are:

  • Saving space on the hard drive.

  • Ensuring RAM is used as efficiently as possible.

  • Saving time in development costs.

The ability to reuse modules of code is one of the benefits of modular programming. You can find out a lot more about DLL files by searching for What is a DLL in Google.