introduction to operating systems cs-2301 b-term 20081 introduction to operating systems cs-2301,...

27
Introduction to O perating Systems CS-2301 B-term 200 8 1 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials from The C Programming Language, 2 nd ed., by Kernighan and Ritchie and from C: How to Program, 5 th ed., by Deitel and Deitel)

Post on 18-Dec-2015

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 1

Introduction to Operating Systems

CS-2301, System Programming for Non-majors

(Slides include materials from The C Programming Language, 2nd ed., by Kernighan and Ritchie and from C: How to Program, 5th ed., by Deitel and Deitel)

Page 2: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 2

Why an Intro to Operating Systems?

• This is a System Programming Course• For people who are not CS majors

• (Nearly) every programming task in real-life includes working with an OS

• Inevitably will have to deal with principle OS features

• Even if not knowledgeable in their designs

Page 3: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 3

Class Discussion

What is an Operating System?

(Laptops closed, please!)

Page 4: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 4

What Operating Systemshave you Used?

(Other than Windows, Linux, Mac-OS, Unix)

Page 5: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 5

What is an Operating System?

• Characteristics– Large, complex set of

programs

– Long-lived, evolving

– Worked on by many people for many years

• Functions– Creates abstractions

– Multiplexes concurrent activities

– Manages resources

– Mediates access to hardware devices

– Provides a variety of services to users and applications

– …

Page 6: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 6

What is an Operating System?

• Characteristics– Large, complex set of

programs

– Long-lived, evolving

– Worked on by many people for many years

• Functions– Creates abstractions

– Multiplexes concurrent activities

– Manages resources

– Mediates access to hardware devices

– Provides a variety of services to users and applications

– …

Large = 108–109 lines of code

(Windows and Linux)

107 line of code for a real-time OS.

Page 7: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 7

Definition – Abstraction

• The distillation of a complex mechanism into a simple, conceptual model

• User of abstraction does not need to worry about details

• Implementer of abstraction does not need to worry about how user will use it (within limits)

Page 8: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 8

Operating Systems

• Typically– Long-lived– Frequently extended and updated– Worked on by many developers– Used and, maybe, abused by a variety of users with

varying expertise and expectations

• Essential to create an acceptable computing environment to create and execute other programs that achieve business or personal goals

Page 9: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 9

Kinds of operating systems

• Mainframe Operating Systems• Server Operating Systems• Multiprocessor Operating Systems• Personal Computer Operating Systems• Handheld Computer Operating Systems• Embedded Operating Systems• Sensor Node Operating Systems• Real-time Operating Systems• Smart-card Operating Systems• …

Page 10: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 10

OS and Hardware

• OS mediates programs’ access to hardware– Computation – CPU– Storage – volatile (memory) and persistent

(disk)– Networks – NIC, protocols– I/O devices – sound cards, keyboards, displays

Page 11: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 11

Four fundamental Abstractions

• Processes & threads• Multiplexing of processor(s) to create the illusion of

many of them

• Virtual memory• Multiplexing of physical memory and disk blocks to

create illusion of own memory per process

• Files & persistent storage• Organizing principles about long-term data storage

• Sockets & connections• Organizing principles about network communication

Page 12: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 12

Definition – Process

• A particular execution of a program• Different from all other executions of that program

• Different from executions of other programs

• The OS uses one or more CPUs to make it look like each process has own CPU

• Can execute at same time!

• Uses interrupts to manage and enforce multiplexing of CPU

Page 13: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 13

Why Processes?

• Enables programmers – to completely disengage from issues of

concurrent execution of independent programs– to build applications with more than one

concurrent activity

• Enables independent applications to share a computing system

Page 14: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 14

Why Processes (continued)?

• Exploit modern processors– Capable of executing multiple threads of

execution simultaneously– Interleaved at instruction level or even memory

access level

• Moore’s Law:–– Integrated circuit components shrink in size by

50% every 18 months– Double in speed every 18 months

Page 15: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 15

Why Processes (continued)?

• Exploit modern processors– Capable of executing multiple threads of

execution simultaneously– Interleaved at instruction level or even memory

access level

• Moore’s Law:–– Integrated circuit components shrink in size by

50% every 18 months– Double in speed every 18 months

Modern limitation due to power

dissipation.

Page 16: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 16

Resources Assigned to a Process

• Memory• Virtual or real

• Processor time• Priorities• Deadlines for real-time activities

• Privileges• Security, authentication, etc.

• Files and file space• For long-term storage, temporary storage

• Devices• For input and output activity, sensors, etc.

Page 17: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 17

Resources (continued)

• Managed by OS

• Protection and isolation from other processes

• Allocation according to defined policies

• Enforcement of limits, etc.

• …

Page 18: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 18

Threads

• A refinement of concept of process• Short for “thread of control”

• An concurrent execution of a function within the context of a process

• Including all functions it calls

• Needs own stack

• Shares heap with other threads of same process

Page 19: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 19

Threads (continued)

• Linux:–• A thread is a special kind of process that shares all

resources with other threads

• A Process group is the collection of threads making up a process

• Windows:–• Threads are fundamental objects

• Process is a group of threads plus memory plus other resources

Page 20: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 20

Why Threads?

• To enable development of applications with concurrent activities inside them

• Need to share data (difficult with separate processes)

• Examples• Web server over common data pages

• Transaction processor over common data base

• Applications within a mobile phone or PDA

• Applications with different speeds of devices

• …

Page 21: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 21

Virtual Memory

• Definition:– the illusion that a process has its own, isolated memory

• (Often) more memory than machine has installed

• May be implemented using interrupts, pages, and disk blocks

• Swapping fast enough so process is unaware

• May be implemented by partitioning• Swapping not necessary for real-time activities

Page 22: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 22

Typical Virtual Memory for Process(Windows & Linux)

0x00000000

0xFFFFFFFF

address space

program code(text)

static data

heap(dynamically allocated)

stack(dynamically allocated)

PC

SP

Page 23: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 23

Typical Virtual Memory for Process(Windows & Linux)

0x00000000

0xFFFFFFFF

address space

program code(text)

static data

heap(dynamically allocated)

stack(dynamically allocated)

PC

SP

Every process has one of these.

Separate from every other process.

Page 24: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 24

Virtual Memories in Embedded System

OS Kernel

stack

Process 1

stack

Process 2

0x00000000

0x0000FFFF

Physical

memory

stack

Process 3

Page 25: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 25

Virtual Memory for Multiple Threads

0x00000000

0xFFFFFFFF

Virtual

address space

code(text)

static data

heap

thread 1 stack

PC (T2)

SP (T2)thread 2 stack

thread 3 stack

SP (T1)

SP (T3)

PC (T1)

PC (T3)

Page 26: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 26

Note on Threads

• Most embedded system programmers will probably have to design with multiple threads in the future

Page 27: Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials

Introduction to Operating Systems

CS-2301 B-term 2008 27

Questions?