Uploaded by Saim Sayin


Lecture 1
Cover two topics:
1. Operating Systems ‣how does the operating system help you run programs on the computer?
2. Architecture ‣how does computer hardware help you run programs on the computer?
Four Components of a Computer System
Hardware – CPU, memory, input/output devices.
OS – Controls use of hardware among various applications and users.
Application programs – Defines the ways in which the system resources are used to solve the
computing problems of the users. Word processors, compilers, web browsers, etc.
OS controls all
User 1 wants to add
1 to data but user
two wants to
subtract 2. Reads the
data, updates the
data and writes it
Lecture 2
What is an OS – A program that acts as an intermediary between a user of a computer and the
computer hardware.
OS goals: Execute user programs and make solving user problems easier. At the user level we select
the print command from the dropdown menu, and it prints the document. There are several things
that happen behind the scenes. The printer needs exclusive access to the communication system so
that all the data can go from the memory to the printer. The printers address needs to be
determined because if a computer is attached to a network then there may be several printers.
Therefore, the correct printer needs to be determined so that data can be sent to the right printer.
The OS does all this. It makes the computer system convenient to use and uses the computer
hardware in an efficient manner. The OS allows you to use multiple processes at once.
What an OS does – Depends on point of view. Users want convenience, ease of use and good
performance. They don’t care about resource utilisation. But shared computers such as mainframe
or minicomputer must keep all users happy. Users of dedicated systems such as workstation have
dedicated resources but frequently use shared resources from servers. Handheld computers are
resource poor, optimised for usability and battery life. The OS hides the lack of processing power
with these two (usability and battery life). Some computers have little or no interface, such as
embedded computers in devices and automobiles (washing machines, microwaves).
OS definition
OS is a resource allocator. It manages all resources and decides between conflicting requests for
efficient and fair resource use. OS is a control program. It controls execution of programs to prevent
errors and improper use of the computer
Computing environments – traditional
Stand-alone general-purpose machines. But blurred as most systems interconnect with others, i.e.
the internet. Portals provide web access to internal systems. Network computers (thin clients) are
like web terminals. There is nothing stored locally. Everything over the internet. Mobile computers
interconnect via wireless networks. The first two are wired. Networking become ubiquitous – even
home systems use firewalls to protect home computers from internet attacks.
Computing environments – mobile
Handheld smartphones, tablets etc. Functional difference between them and a laptop: worse
battery, mobiles have GPS, allows new types of apps like augmented reality. Smartphones have
cellular data and IEEE 802.11 wireless.
Computing environments - Distributed
Collection of separate, possibly heterogeneous, systems networked together. Network is a
communications path. Internet, Cloud computing, LAN, Personal area network. If you execute a
program in a distributed environment the program may not be executed in a single physical
machine. It will be broken up. Network OS provides illusion of a single system across network.
Computing environments – virtualisation
Allows an OS to run as an application within another OS. You may use this for exploration or
compatibility. You may want to develop an iOS app from windows with virtualisation. Pc’s can run
Linux as guest and windows as host. You can execute and manage compute environments within
data centres.
Computing environments- Real-time embedded systems
Real time embedded systems most prevalent form of computers. They have special purposes that
are limited. They have real-time OS’s. Many other special computing environments as well. Some
perform tasks without an OS to save time. They need to process very fast. The OS must fit in a chip
Lines and lines of code isn’t needed.
Open source OS
OS available in source-code format rather than binary closed-source. They are free to use, modify
and redistribute. Counter to the copy protection and Digital Rights Management (DRM) movement.
Examples include Linux and Android. You can use virtualisation to explore open-source OS.
Computer System Structure
How to manage concurrent operations of all these elements? An OS is interrupt driven. An interrupt
is a signal sent to the OS. For example, hardware interrupts by one of the devices, Software
interrupts are generated by user requests and Trap or Exception generated by user error.
Interrupts in a multi core processor – there’s a
queue of interrupts for that entire processor single
core or multi, then the OS sends the interrupt to a
different core or the OS handles the interruption.
Dual-Mode Operation
Dual-mode operation allows OS to protect itself
and other system components. User mode and
Kernel mode. User mode is mode where all the
user programs are executed. However, the user
programs will need to use resources at some
point, so a shift to the kernel mode is needed.
Only the user handles the kernel mode. Hardware
supports switching between modes.
Transition from user to kernel mode
The user process is going on and then there is a system call (e.g. reading from memory location),
then the OS goes in to kernel mode to check if it can do it safely without errors. In the kernel mode
the mode bit that was equal to 1 becomes equal to 0. Once the system call is over (e.g. reading from
the memory location), the OS returns to the user mode.
Process management
A process is a program in execution. It is a unit of work within a system. Program is a passive entity,
process is an active entity. Process needs resources to accomplish its tasks (e.g. CPU memory,
initialisation data). Process termination requires reclaim of any reusable resources. Operating
system is responsible for creating and deleting both user and system processes and suspending ad
resuming processes.
Storage-Device Hierarchy
Memory management
Management of primary storage. To execute a program, all (or part) of the instructions must be in
memory. All (or part of the data must be in memory. Memory management determines what is in
memory and when
Memory management activities
Keep track of which parts of memory are currently being used and by whom. Allocate and deallocate
memory space as needed.
Storage management
Management of secondary and tertiary storage. Data that does not fit in main memory. Data that
must be kept for a long period of time. OS provides uniform, logical view of information storage.
Abstracts physical properties to logical storage unit: file.
Different storage media (e.g. disk drive, tape drive) have different characteristics, e.g. access speed,
capacity data transfer rate, access method (sequential or random).
File system management activities: Organise files into directories, Create, update and delete files
and directories.
Protection and security
Protection – any mechanism for controlling access of processes or users to resources defines by the
Security – defence of the system against internal and external attacks. Huge range, including DOS,
worms, viruses, identity theft and theft of service.
Systems need to distinguish users to determine who can do what. User identifies (User IDs) include
name and associated number, one per user. User ID then associated with all files, processed of tat
user to determine access control.
Lecture 3
OS structures
OS services - OS provides an environment for the execution of programs and services to programs
and users. Two sets of operating system services:
Functions that are helpful to the user,
Functions to ensure the efficient operation of the system itself.
User Services
: User Interface - Almost all operating systems have a user interface (UI). E.g. windows. By touching
the touchscreen and typing, this is how you’re accessing the user interface.
Types of user interfaces:
Command Line Interface (CLI) or command interpreter allows direct command entry. When you
type a command to open a file, the CLI it takes that command and loads up the memory with that
particular program rather than executing it itself. The OS executes it for you.
Graphical user interface (GUI): User-friendly desktop metaphor interface. The first GUI on a Xerox
ALTO: 1973. GUI is a point and click device. You use your mouse or other input devices to access
services, open files etc. Interacting with OS.
Invented at Xerox Parc - 1973
Touchscreens: GUI with new challenges (no mouse, no keyboard)
Program execution - The system must be able to load a program into memory and to run that
program, end execution, either normally or abnormally (indicating error). When you run a program
and submit it, the OS takes the program and loads it into the main memory because the program
must be in the main memory to execute, and then reads the program line by line.
Input/output (I/O) operations - A running program may require I/O, e.g. using files or I/O devices.
When you type into the keyboards, its an input. It takes in this input and provides certain
services to do that input. Output into your standard output like into a monitor or file. The OS
provides the services to do this.
File-system manipulation - Programs need to read and write files and directories, create and delete
them, search them, list file information, manage permissions. Every OS provides you with a file
system. There are different types and each one has different services. NTFS, FAT ETC. Hierarchal file
systems are common. You have a folder on top, within that file there are other files, and then within
that you have more folders of files. The lowest level only has files.
We create a new file and that’s it. But it involves making a note that a certain type of file was
created. Then there is the formation of each file that is recorded.
Communications – Processes may exchange information, on the same computer or over a network.
They can share memory. The output of one process is saved in one memory. The other process reads
from that memory. Another way of communicating is message passing. Networks do this.
Error detection – OS needs to be constantly aware of possible errors... Whether you’re opening a file
or putting a usb stick in your pc there are a lot of error that can happen, and a lot of checks happen
by the OS. When you open a file, the OS checks if you have permission to open the file. If you don’t
then that’s an error and the OS will let you know. If you create a file that has the same name as
another, then it is an error and the OS will tell you.
May occur in the CPU and memory hardware, in I/O devices, in user program
For each type of error, OS should take the appropriate action to ensure correct and consistent
Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the
System services
Resource allocation - When multiple users or multiple jobs running concurrently, resources must be
allocated to each of them.
The CPU time is divided in to chunks. Each of these chunks are CPU cycles. These cycles are allocated
to processes. The way it is allocated is that there are algorithms like the first in first out algorithm.
The first process that is submitted to the OS is the first process that is executed. However, these
processes have priorities. The ones with more priority need to be processed first. The FIFO algorithm
got more complicated then we got different cues for different priorities. Cues with higher priority is
served first.
Many types of resources – CPU cycles, main memory, file storage, I/O devices.
Accounting - To keep track of which users use how much and what kinds of computer resources.
Protection and security - Control use of information, concurrent processes should not interfere with
each other.
Protection: access to system resources is controlled
Security of the system from outsiders: user authentication, defending external I/O devices from
invalid access attempts.
System Calls
Programming interface to the services provided by the Operating System. System calls are the ways
we can use the services of the OS. We submit these system calls using API. Interfaces that are
available to us to submit it.
Mostly accessed by programs via a high-level Application Programming Interface (API)
Three common APIs are
Win32 API for Windows
POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X)
Java API for the Java virtual machine (JVM)
API – System Call – OS Relationship
System Call Implementation
How does the operating system provide system calls?
The system call interface
invokes the intended system call in OS kernel
returns status of the system call + return values
The caller need know nothing about how the system call is implemented
Just needs to obey API and understand what OS will do as a result of the call
Most details of OS interface hidden from programmer by API
Example: printf() in C
C program invoking printf() library call, which calls write() system call
Example: Copy File Contents
System call sequence to copy the contents of
one file to another file. Every line = system call
Types of System Calls
You are likely to find these types of system calls in every OS!
Process control, File management, Device management, Protection, Information maintenance,
System Programs
System programs use system calls to provide the functionality to the user
They can be divided into:
File manipulation, Status information, Programming language support, Program loading and
execution, Communications
Most users’ view of the operating system is defined by system programs, not the actual system calls.
Operating System Design Goals
Specifying and designing an OS is highly creative task of software engineering
First step in designing operating system: define goals and specifications
Affected by choice of hardware, type of system. Below that, the design then depends upon the
goals. The user goals, such as convenience, and system goals, such as
User goals vs. system goals
User goals – operating system should be convenient to use, easy to learn, reliable, safe, and fast
System goals – operating system should be easy to design, implement, and maintain, as well as
flexible, reliable, error-free, and efficient. You want it to be easy to debug and maintain.
These are not scientific goals. It is difficult to pinpoint what good performance is. Changes from
person to person. Difficult to design OS to serve the goals it’s supposed to.
Design Strategy: Mechanism vs. Policy
Important design strategy: separate policy and mechanism
Policy: What will be done? How much time is there in the processor for processes? The OS has a
mechanism to find that the processor has been using the process for 2 nanoseconds. At the end of
the 2 nanoseconds, it can either the process is brought out and the processor is allocated to another
process, or it can allow the process to keep on processing.
Mechanism: How to do it? How is this implemented.
Allows maximum flexibility if policy decisions are to be changed later (example – timer)
Mechanism can give priority to certain types of programs
Policy decides which types of programs to prioritize
Monolithic Structure
General-purpose OS and is a very large program
Simplest way to structure is monolithic structure
Example: MS-DOS
written to provide the most functionality in the least space
Not divided into modules
Interfaces and levels of functionality are not well separated. Difficult to debug from the millions of
codes. Not very flexible. To add a new function, you would have to compile the one huge program
However, since it is a large program it is efficient because you don’t have to hand control over from
one prgram to another program.
Layered Structure
The operating system is divided into several layers (levels)
Each layer is built on top of
lower layers.
The bottom layer (layer 0)
is the hardware; the highest
(layer N) is the user interface.
Each layer uses functions
(operations) and services of
only lower-level layers.
Memory, interprocess management,
security etc. around hardware.
Layer 2 uses functions of layer 1 to
develop more complex functions. Layer 2 doesn’t interact with hardware. It interacts with
layer 1 and layer 1 interacts with hardware. Very minimal functionalities. Very small program
in the inner most layer. The layer above will use the functions of the layer below.
Easy to debug. Less lines of code. Layer one is a small program, less lines of code. Write the program
and make sure there are no errors/bugs. Then in the next layer, layer 2, if you develop the
program if there are any errors you are sure that its not in the code of layer 1 since you
already made sure that layer 1 is error free. Shell after shell like an onion. You can add
functions easier from the top layer.
However, you how to move down the layers the layers to do any work. When running a program,
you use hardware, for any function you need to come down the layers. The performance
and efficiency drops. To deal with this you can make the layers less. That’s what Unix does. It
has two layers, the huge kernel in between, on top of that there are the system programs.
Microkernel Structure
Moves as much as possible from the inner core/kernel into user space. Only keep absolute core
functions in internal kernel, making the programs in the internal kernel less. This kernel runs in the
kernel mode. Whatever else in the OS, we have pushed it out to the user.
Easy to extend
Benefits: Easier to extend, more reliable (less code is running in kernel mode), more secure
But: performance overhead of user space to kernel
space communication
Loadable Kernel Modules
Many modern operating systems implement loadable kernel modules
Uses object-oriented approach
Each core component is separate
Each talk to the others over known interfaces
Each is loadable as needed within the kernel. Like layers but more flexible
Hybrid Systems
Most modern operating systems are hybrid systems
Hybrid systems combine multiple approaches to
address performance, security, usability needs
Linux: monolithic kernel plus modules
Windows: monolithic plus microkernel
Android: layered stack of software on top of Linux
Operating-System Debugging
Debugging is finding and fixing errors, or bugs
Term was coined by Grace Hopper in 1947 while working on the Harvard Mark II computer
OS generates log files containing error information
Failure of an application can generate core dump file capturing memory of the process
Operating system failure can generate crash dump file containing kernel memory
Kernighan’s law: “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.”
System Boot in Three Steps
1. When system is powered on, execution starts at a predefined memory location
Firmware ROM (read-only memory) holds initial bootstrap loader
2. Operating system must be made available to hardware so hardware can start it
Bootstrap loader locates the kernel, loads it into memory, and starts it
Bootloader GNU GRUB allows selection of kernel from multiple disks, versions,
kernel options
3. Kernel loads and system is then running