Object-Oriented Programming
Operating Systems
Lecture 1b
Dr Ronald Grau School of Engineering and Informatics Spring term 2018
Previous Lecture
A brief introduction to operating systems
A bit of history:
How operating systems came about and developed over time
A few basics about operating systems
They offer a virtual machine abstraction to work with diverse hardware
They make computers easier to program
They manage resources for programs
They offer protection for programs (and their users), and themselves
1
Today
Operating system architectures
Abstractions
Basic design principles
Basic architectures
2
Abstractions: Overview
3
Image: Silberschatz, pg. 54
Abstractions: Overview
Let’s talk about:
Processes
Virtual memory
Files
System call interface
4
Process abstraction
A process is a program in execution
Operating system duties:
Process creation:
Load the executable file from secondary storage into primary memory (RAM)
Handle concurrency
Scheduling
Coordination of resource requests
Synchronisation
Signalling of events (e.g. I/O)
Inter-process communication (IPC)
5
Process list in Windows 7 (Task manager)
Virtual memory abstraction
Memory can be provided to processes irrespective of the actual
organisation and size of the physical memory available.
Virtual Memory provides each process with its own address space.
Operating system duties:
Address translation
Memory management:
CPU can only address main memory
Data is only partially in memory (paging)
Memory protection
Process can only access its “own” memory segments
Provision of shared memory
6
Virtual address spaces (Source: microsoft.com)
File abstraction
Files provide persistent storage of data
Files have names and can be hierarchically organised
The operating system can restrict access to files in various ways
Files are accessed as sequences of bytes (allows consistency checking)
Operating system duties:
Provide a uniform interface for different devices
Manage efficient access (e.g. caching)
Protect storage device from being damaged/corrupted
In UNIX systems I/O devices are files
7
System call interface
The SCI contains the functions the kernel provides for
Process control
File management
System information (date, time, etc.)
Inter-process communication
E.g.
Win32 API: windows.h, Unix API (POSIX, IEEE Std 1003): unistd.h
For programming languages, these calls are wrapped by libraries
8
A few examples: Windows and Unix 9
How can we protect the OS?
Kernel Mode vs User Mode
In principle, system calls execute in kernel mode
10
How to implement protection?
Kernel Mode vs User Mode
How to implement security for kernel mode?
Requires hardware support
Disallows certain instructions in user mode
trap instruction / exception: software-initiated interrupt
11
Quick recap: Interrupts 12
System call example
UNIX SC read (fd, buffer, size)
fd: The file to read from (file handle)
buffer: Memory address to store the
data in
size: number of bytes to be read
Returning a number >= 0: bytes read
Returning -1: there was a problem!
13
System call example
UNIX SC read (fd, buffer, size) – sequence
1, 2, 3: Push parameters onto system stack
4: Call the library procedure read
5, 6: Place this system call in a special
register and call trap to switch modes
7, 8: Run correct system call handler
9: Pass control back to the user space
procedure
10: Return to user program
11: Increment stack pointer
… next instruction
14
Operating System Architectures
Why the need for an architecture?
Modern operating systems tend to be complex because
They provide many services and have many functions
There is a wide range of hardware that must be supported
15
Architectures help us cope with complexity
Design principles
Separation of interface and implementation
Interfaces should be simple, complete, and stable:
A published interface is hard to change
Encapsulation: keep internals opaque.
E.g. indirection via naming
16
Design principles
Separation of policy and mechanism
Policy: The what
Mechanism: The how
Mechanism should be general and efficient
Orthogonality: concepts can be combined independently
17
Design principles
Portability
Hardware abstraction layer
Word sizes, endianness, alignment, time, etc.
18
Design principles
Coherence
Adherence to coding conventions
Operating systems are huge software development projects that often stretch over
many years
19
OS Implementation
Languages used
IBM 360: Assembly language
MULICS: PL/1
Linux, Windows: Mostly C (plus small parts in Assembly language)
20
Why not just implement everything in Assembly language?
Architectures
Layers
Each layer provides
a service interface
Higher layers use services
of lower layers
21
Architectures
Modules
Each module provides
a service interface
Modules support encapsulation
and can be replaced and
changed easily
Potentially complex dependencies
22
Monolithic Kernel vs. Microkernel
Overview
23
Monolithic Kernel
Entire operating system runs in kernel mode
All components can talk directly to each other
Extending the operating system can be difficult
Good performance but errors can be difficult to trace
24
Microkernel
Kernel provides minimal services
A lot of message-passing
communication
(impact on performance)
Very general mechanisms
that allow a wide range of
policies to be implemented
Modules run in user mode
Extensible, portable, scalable
25
What type of architecture is this?
Example: Windows NT
26
What type of architecture is this?
Example: UNIX
27
What type of architecture is this?
Example: Android
28
What type of architecture is this?
Example: Linux
Interactive map of
the Linux kernel
(explore on Study Direct)
29
Summary
Operating system architectures
Abstractions
Processes
Virtual memory
Files
System call interface
30
Basic design principles
Separation of interface and implementation
Separation of policy and mechanism
Portability
Coherence
Basic architectures
Layers & modules
Monolithic kernels
Microkernels
Read
Tanenbaum & Bos., Modern Operating Systems
Chapter 1
Silberschatz et al., Operating System Concepts
Chapter 2
31
Prepare
For your labs next week, review the basic content on
Microarchitectures,
Instruction set architectures,
Machine code and
Assembly language
from your Year 1 module “Introduction to Computer Systems“.
Don’t forget to work on your question sheet!
32
Next Lecture
Introduction
Operating System Architectures
Processes
Threads
Process Scheduling
Process Synchronisation
33
Deadlocks
Memory Management
File Systems
Input / Output
Security and Virtualisation