Operating Systems - OS3 · • System Calls are the interface the Operating System offers to...

56
Operating Systems Operating Systems - Winter 2012 Andrew S. Tanenbaum Melanie Rieback Arno Bakker Design and Implementation Vrije Universiteit Amsterdam

Transcript of Operating Systems - OS3 · • System Calls are the interface the Operating System offers to...

Page 1: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Operating Systems

Operating Systems - Winter 2012

Andrew S. TanenbaumMelanie Rieback

Arno Bakker

Design and Implementation

Vrije Universiteit Amsterdam

Page 2: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Outline

Vrije Universiteit Amsterdam Slide 4

• Introduction• What is an OS?

• Concepts

• Processes and Threads

• Memory Management

• File Systems

Operating Systems 2012

Page 3: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Chap 1 - Overview

Vrije Universiteit Amsterdam Slide 4

• What is an Operating System?

• Concepts

• System Calls

• Structure

Operating Systems 2012

Page 4: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

What is an OS?

Vrije Universiteit Amsterdam Slide 13

Operating Systems 2012

Page 5: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

2 Views on OSes

Vrije Universiteit Amsterdam Slide 15

• OS as a Virtual Machine

• Extending the HW functionality

• Hides the messy details of programming the HW

• OS as a Resource Manager

• Protects against simultaneous usage of resources

• Fair sharing of resources (scheduling)

• Resource accounting

Operating Systems 2012

Page 6: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

How to View an OSOperating Systems 2011

Vrije Universiteit Amsterdam Slide 16

OS

Program

System calls

Page 7: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Concept: ProcessesOperating Systems 2011

Vrije Universiteit Amsterdam Slide 17

Page 8: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Multiple ProcessesOperating Systems 2011

Vrije Universiteit Amsterdam Slide 18

some_program

init

shell

Page 9: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

System CallsOperating Systems 2011

Vrije Universiteit Amsterdam Slide 27

Hardware

Operating SystemSystem Calls

LibrariesLibrary functions

Applications / Processes

Instruction Set Architecture

• System Calls are the interface the Operating System offers to applications.• Problem: Mechanics of issuing a system call are highly machine dependent• Solution: Provide a library to allow system calls from C programs: libc

Bashlibc

Linux kernel

x86_64

Page 10: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

System Calls: Process Management (1/2)

Vrije Universiteit Amsterdam Slide 28

Page 11: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

System Calls: Process Management (2/2)

Vrije Universiteit Amsterdam Slide 29

Page 12: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

System Calls: SignalsOperating Systems 2011

Vrije Universiteit Amsterdam Slide 30

Page 13: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Concept: Mounting (1/2) Operating Systems 2011

Vrije Universiteit Amsterdam Slide 23

Page 14: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

File System Mounting (2/2) Operating Systems 2011

Vrije Universiteit Amsterdam Slide 24

Page 15: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Special Files (1/2) Operating Systems 2011

Vrije Universiteit Amsterdam Slide 25

Storage devices are mapped into the file tree via mounting. Idea: do this for all devices.

Mechanism: Special files in /dev

Two types:

Page 16: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Special Files (2/2) Operating Systems 2011

Vrije Universiteit Amsterdam Slide 26

Page 17: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

System Calls: FilesOperating Systems 2011

Vrije Universiteit Amsterdam Slide 31

Page 18: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

System Calls: DirectoriesOperating Systems 2011

Vrije Universiteit Amsterdam Slide 32

Page 19: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

System Calls: Implementation Operating Systems 2011

Vrije Universiteit Amsterdam Slide 35

Page 20: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

OS Structure: UNIXOperating Systems 2011

Vrije Universiteit Amsterdam Slide 37

Page 21: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

OS Structure: LinuxOperating Systems 2011

Vrije Universiteit Amsterdam Slide 38

Page 22: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Operating Systems

Operating Systems - Winter 2012

Chapter 2 - Processes

Vrije Universiteit Amsterdam

Page 23: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Chap 2 - OverviewOperating Systems 2012

Vrije Universiteit Amsterdam Slide 1

• Scheduling Processes

• Threads

Page 24: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Recall: Process

Vrije Universiteit Amsterdam Slide 2

Operating Systems 2012

Page 25: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

One CPU, Many Processes

Vrije Universiteit Amsterdam Slide 3

Operating Systems 2012

• Processes share the CPU(s)• A scheduler determines which process to run next• Keeps track of the process state• Following some scheduling policy (random robin, shortest

job first, etc).

Page 26: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Process States

Vrije Universiteit Amsterdam Slide 5

Operating Systems 2012

Page 27: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Context SwitchingOperating Systems 2011

Vrije Universiteit Amsterdam Slide 39

Page 28: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Process ImplementationOperating Systems 2011

Vrije Universiteit Amsterdam Slide 7

ProcessTable: ps -ef

Page 29: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

ThreadsOperating Systems 2011

Vrije Universiteit Amsterdam Slide 10

Page 30: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Threads: Minimal SupportOperating Systems 2011

Vrije Universiteit Amsterdam Slide 11

Page 31: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Threads – Some ProblemsOperating Systems 2011

Vrije Universiteit Amsterdam Slide 12

Page 32: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Mutual ExclusionOperating Systems 2011

Vrije Universiteit Amsterdam Slide 15

Page 33: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Operating Systems

Operating Systems - Winter 2012

Chapter 4 – Memory Management

Vrije Universiteit Amsterdam

Page 34: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Chap 4 - OverviewOperating Systems 2012

Vrije Universiteit Amsterdam Slide 1

• Memory Management

• Paged Memory

• Virtual Memory

• Segmentation

Page 35: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Memory Management – SimpleOperating Systems 2012

Vrije Universiteit Amsterdam Slide 2

Page 36: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Memory Management - ComplexOperating Systems 2012

Vrije Universiteit Amsterdam Slide 10

Multiple processes in the same memory

Page 37: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Paged Memory Systems (1/2) Operating Systems 2012

Vrije Universiteit Amsterdam Slide 15

Page 38: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Paged Memory Systems (2/2)

Vrije Universiteit Amsterdam Slide 17

Page 39: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Virtual Memory Operating Systems 2012

Vrije Universiteit Amsterdam Slide 24

• Idea: Not all virtual pages have to be in physical memory• Instead stored on disk -> cheap storage• In swap partition• Much more memory available• Works if not all pages are used at the same time

Page 40: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Segmentation Operating Systems 2012

Vrije Universiteit Amsterdam Slide 35

Stack

Data

Code

N

0Code Data Stack

N

0

• Segments can grow independently• Hardware helps to map segments to virtual memory• Hardware helps to protect: read-only, no-execute

Page 41: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Operating Systems

Operating Systems - Winter 2012

Chapter 5 – File Systems

Vrije Universiteit Amsterdam

Page 42: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Chap 5 - OverviewOperating Systems 2012

Vrije Universiteit Amsterdam Slide 1

• Files

• Directories

• File system implementation

• UNIX/MINIX filesystem

Page 43: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Directories

Vrije Universiteit Amsterdam Slide 5

Operating Systems 2012

i-node

Page 44: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

File Attributes

Vrije Universiteit Amsterdam Slide 4

Operating Systems 2012

Page 45: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Directories – Pathnames

Vrije Universiteit Amsterdam Slide 6

Operating Systems 2012

Page 46: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

File System Design

Vrije Universiteit Amsterdam Slide 7

Operating Systems 2012

Page 47: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

File Storage: Disk Layout

Vrije Universiteit Amsterdam Slide 8

Operating Systems 2012

Page 48: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

File Storage – Inodes

Vrije Universiteit Amsterdam Slide 11

Operating Systems 2012

Page 49: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

File Storage – UNIX

Vrije Universiteit Amsterdam Slide 13

Operating Systems 2012

Page 50: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

File Storage – Name Resolution

Vrije Universiteit Amsterdam Slide 14

Operating Systems 2012

Page 51: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Disk Space Management (1/2)

Vrije Universiteit Amsterdam Slide 15

Operating Systems 2012

Page 52: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

File System Consistency

Vrije Universiteit Amsterdam Slide 18

Operating Systems 2012

Page 53: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Buffer Cache

Vrije Universiteit Amsterdam Slide 20

Operating Systems 2012

Page 54: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

Log-Structured File Systems

Vrije Universiteit Amsterdam Slide 21

Operating Systems 2012

Page 55: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

MINIX Filesystem

Vrije Universiteit Amsterdam Slide 31

Operating Systems 2012

Page 56: Operating Systems - OS3 · • System Calls are the interface the Operating System offers to applications. ... File System Mounting (2/2) Operating Systems 2011 Vrije Universiteit

MINIX Superblock

Vrije Universiteit Amsterdam Slide 32

Operating Systems 2012