cs 326 operating systems introduction

37
CS 326 Operating Systems Introduction Greg Benson Department of Computer Science University of San Francisco

Upload: others

Post on 25-Apr-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 326 Operating Systems Introduction

CS 326Operating Systems

IntroductionGreg Benson

Department of Computer ScienceUniversity of San Francisco

Page 2: CS 326 Operating Systems Introduction

Today’s Topics

• Course overview and logistics

• What is an operating system?

• A brief history of operating systems

• Some OS concepts

• Roadmap for this semester

2

Page 3: CS 326 Operating Systems Introduction

Brief summary of OS

• Operating systems are everywhere and essential to everything we do on computers

• We will learn how operating systems are designed and implemented

• We will learn by coding large parts of a real operating system

3

Page 4: CS 326 Operating Systems Introduction

Course Information

• Lecture in Kudlick classroom

• Tue and Thu 1:30pm to 3:15pm

• Lab section in PC Lab (Harney 535)

• Thu 3:15pm to 5:00pm

• Midterm: TBA

• Final: Wed 12/14 12:00pm

4

Page 5: CS 326 Operating Systems Introduction

Course Resources

• Class website

• http://www.cs.usfca.edu/benson/cs326

• Class mailing list:

[email protected]

• Subscribe to mailing list at:

• https://cs.usfca.edu/mailman/listinfo/cs326

5

Page 6: CS 326 Operating Systems Introduction

Prerequisites

• Desire to learn something complicated

• Assembly Language (CS 210)

• Binary and hexadecimal representation

• Addresses, stacks, interrupts

• Data Structures and Algorithms (CS 245)

• Linked Lists, queues, trees, hash tables

• Good C programming skills

• Most operating systems are written in C

6

Page 7: CS 326 Operating Systems Introduction

Operating Systems ConceptsSeventh Editionby Silberschatz, Galvin, and Gagne

John Wiley & SonsISBN: 0471694665

A comprehensive book, we will read a large portion

Books: Main Text

7

Page 8: CS 326 Operating Systems Introduction

Programming in Cby Kochan

SamsISBN: 0672326663

Good treatment of pointersGood language and library reference

Books: C Reference

8

Page 9: CS 326 Operating Systems Introduction

Books: Optional

9

Advanced Programming in the UNIX Environmentby Stevens and Rago

The C Programming Languageby Kernighan and Ritchie

Page 10: CS 326 Operating Systems Introduction

Development Platform

• Linux

• C compiler (gcc)

• Debugger (gdb)

• x86 emulators and virtual machines

• VMware, QEMU, Bochs

• Source code control (subversion)

10

Page 11: CS 326 Operating Systems Introduction

Assignments and Exams

• Projects (5 total)

• Programming problems

• Design document and results

• Interactive grading

• Code qaulity

• Midterm, Final (comprehensive)

11

Page 12: CS 326 Operating Systems Introduction

Grading

12

Breakdown

PolicyAbsolute Scale

Midterm 1 20%

Final 30%

Projects 50%

A- 90%

B- 80%

C- 70%

D- 60%

Page 13: CS 326 Operating Systems Introduction

Course Policies

• Due dates and lateness

• Late assignments will NOT be accepted

• Turn in what you have for partial credit

• Disputes only considered within 1 week of returned work

• Missed exams: call or email me ahead

• Class and lab attendance

• Not required, but ...

13

Page 14: CS 326 Operating Systems Introduction

Cheating and Plagiarism

• Just don’t do it -- work hard and you can do well

• What is cheating?

• Copying source code or parts of code

• Having someone tell you how to solve a problem

• Telling someone how to solve a problem

• What is acceptable discussion?

• Discussing existing or given code

• Discussing the project requirements

• Discussing techniques given in class and lab

• Consequences - you will get an F in the class

14

Page 15: CS 326 Operating Systems Introduction

How to do well

• Have fun!• Read the book and given code• Keep up: start the projects early• Learn by doing• Come to lecture and labs• Come to office hours• Post to class mailing list• Ask lots of questions!!!

15

Page 16: CS 326 Operating Systems Introduction

What you get

• A deep understanding of how an OS works

• How the OS kernel manages hardware

• Relationship between applications and the OS

• Kernel hacking experience (can apply to Linux, BSD, Mac OS X, Windows)

• UNIX systems programming

• How to deal with concurrency

• Needed in many apps: databases, games, servers

• Debugging skills

16

Page 17: CS 326 Operating Systems Introduction

Lecture/Lab Format

• Lecture (roughly)• 50 mins lecture• 10 mins break• 45 mins lecture

• Lab• Special coverage• Help with projects• Interactive grading

17

Page 18: CS 326 Operating Systems Introduction

What is an Operating System?

• The OS is software that sits between applications and the hardware

18

Firefox

Operating System

CPU Memory Network Disk

Vi Half-Life

Page 19: CS 326 Operating Systems Introduction

Why is an OS so special?

• Most people take the OS for granted

• Not many people really understand how it work (e.g. running programs, files)

• Except USF CS students!

• Operating systems are very complicated

• Is there a bug-free OS?

• Windows, Linux, Others

19

Page 20: CS 326 Operating Systems Introduction

Dealing with OS complexity

• Abstraction

• It’s needed everywhere in CS

• Modularity

• Keep common functionality together

• Iterative design

• OSes do pretty well given the complexity

20

Page 21: CS 326 Operating Systems Introduction

Some OS Tricks

• Program loading and linking

• E.g. clicking on Firefox, the OS does:

• Transfers executable from disk to memory

• Links the executable with required libraries

• Some libraries may be in memory, some on disk

• Running two or more programs at the same time

• Many computers have only one processor

• Multiple programs can run simultaneously

• The OS must switch between programs allowing each to make progress

21

Page 22: CS 326 Operating Systems Introduction

More OS Magic

• Programs expect a large, uniform address space

• Perhaps need more memory than physical memory

• Disk space is used to augment physical memory

• If the OS is smart, only infrequently used data will be pushed to disk

• Storing information

• Files must be saved to or retrieved from a disk

• Must be able to easily locate files (hierarchy and search)

• Must be able to reuse freed disk space

• Files must be exact

• All of these operations must be fast

22

Page 23: CS 326 Operating Systems Introduction

Conflicting Goals

• Protection

• Programs should not interfere with each other

• Programs cannot touch each other’s memory

• One program cannot prevent another from running

• Some files should not be accessible by others

• Sharing

• Programs need to share resource (e.g. network, disk, display)

• We want some files to be shared

• All users can run the same “ls” program

• Need shared read access to /etc/passwd, libraries

23

Page 24: CS 326 Operating Systems Introduction

What is an OS? Definition

• An extended machine or virtual machine

• Programs utilize OS services through system calls

• A resource manager

• The OS manages: CPU cycles, memory, disks, network cards, etc.

• The OS provides multiprogramming: multiple programs executing simultaneously on the same machine

• In general, an OS is the software that bridges the gap between the hardware and application programs

24

Page 25: CS 326 Operating Systems Introduction

A very brief history of OSes

• No OS

• The OS as a library

• The OS as a job controller (one at a time)

• Multiprogramming

• Multiuser

• Multiprocessor

• Distributed

• Others: embedded, real-time, secure

• See book

25

Page 26: CS 326 Operating Systems Introduction

The Process

• A central concept in operating systems

• A process is a program in execution

• A process has an address space (0 to N)

• code, data, stack

• Processes

• execute independently

• are protected from each other

• can start other processes

• can terminate

26

Page 27: CS 326 Operating Systems Introduction

The OS as a process manager

• The OS provides support for the process model

• System calls for process creation

• System call for communication

• The OS protects processes

• The OS schedules processes

• How and when to switch from one process to another

27

Page 28: CS 326 Operating Systems Introduction

Components of an OS

• The kernel

• Code that resides in main memory

• Controls the machine resources

• Provides the system call interface

• Executes with special privileges

• User-level code

• Outside the kernel all programs run in user-mode

• Has limited access to CPU and hardware

• Accesses the kernel via system calls

28

Page 29: CS 326 Operating Systems Introduction

Types of user-level processes

• System software

• Used to support the execution of applications

• E.g., libraries, compilers, linkers, servers, etc

• Applications

• End user programs

• E.g., word processors and web browsers

• Some system programs may also be application programs (e.g. the shell)

29

Page 30: CS 326 Operating Systems Introduction

Role of Hardware

• CPU protection: preemption

• The kernel needs a way to interrupt a running process

• The hardware clock interrupts the CPU and transfers control to the kernel

• The kernel can determine if the current process should stop

30

Page 31: CS 326 Operating Systems Introduction

Role of Hardware Continued

• Memory protection: virtual memory

• Modern CPUs support virtual addressing

• A process generates a virtual address for every memory access

• The OS translates the virtual address into a physical address

• CPU keeps track of recent translations

31

Page 32: CS 326 Operating Systems Introduction

OS Design Goals

• Efficiency

• Fast operations, don’t want to get in the way of application

• Fairness

• Give each application equal access to resources (not always though)

• Reliability

• Don’t fail or handle failures gracefully

• Security

• Don’t protect data and resources from unauthorized users

32

Page 33: CS 326 Operating Systems Introduction

Current OS Characteristics

• Huge: Millions of lines of code

• Complex:

• Asynchronous

• Hardware idiosyncrasies

• Conflicting user needs

• Performance is crucial

• Pooly understood:

• The system outlives its builders

• Never fully debugged

• Behavior is hard to predict

• Often unreliable

33

Page 34: CS 326 Operating Systems Introduction

Why Study OS?

• Internet still driver many software technologies included OS research

• Linux and other open source OSes gaining ground

• Linux accepted and promoted by Sun, IBM, and the US Government

• Linux runs on almost everything

• Apple uses BSD as basis for Mac OS X

• Windows?

34

Page 35: CS 326 Operating Systems Introduction

More Details on Projects

• We will be using C exclusively

• First project will be C systems programming on Linux

• Remaining projects will be to develop Pintos (more later)

35

Page 36: CS 326 Operating Systems Introduction

Roadmap

• C programming and UNIX system calls

• Processes and Threads

• System call implementation

• Virtual memory

• File systems

36

Page 37: CS 326 Operating Systems Introduction

Reading Assignment

• Silberschatz: Chapter 1

• Kochan: Chapters 7, 8, and 9 (as needed)

37