Introduction to Operating Systems CS2301 System Programming for

  • Slides: 27
Download presentation
Introduction to Operating Systems CS-2301, System Programming for Non -majors (Slides include materials from

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) CS-2301 B-term 2008 Introduction to Operating Systems 1

Why an Intro to Operating Systems? • This is a System Programming Course •

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 CS-2301 B-term 2008 Introduction to Operating Systems 2

Class Discussion What is an Operating System? (Laptops closed, please!) CS-2301 B-term 2008 Introduction

Class Discussion What is an Operating System? (Laptops closed, please!) CS-2301 B-term 2008 Introduction to Operating Systems 3

What Operating Systems have you Used? (Other than Windows, Linux, Mac-OS, Unix) CS-2301 B-term

What Operating Systems have you Used? (Other than Windows, Linux, Mac-OS, Unix) CS-2301 B-term 2008 Introduction to Operating Systems 4

What is an Operating System? • Characteristics • Functions – Large, complex set of

What is an Operating System? • Characteristics • Functions – Large, complex set of programs – Long-lived, evolving – Worked on by many people for many years CS-2301 B-term 2008 Introduction to Operating Systems – Creates abstractions – Multiplexes concurrent activities – Manages resources – Mediates access to hardware devices – Provides a variety of services to users and applications – … 5

de o c f so 9 line 8 – 10 x) u n S.

de o c f so 9 line 8 – 10 x) u n S. 0 i 1 L O = e d e an tim l a Larg indows e ar r o f (W d • e Functions o Characteristics c f o 7 line – Large, complex 10 set of – Creates abstractions What is an Operating System? • programs – Long-lived, evolving – Worked on by many people for many years CS-2301 B-term 2008 Introduction to Operating Systems – Multiplexes concurrent activities – Manages resources – Mediates access to hardware devices – Provides a variety of services to users and applications – … 6

Definition – Abstraction • The distillation of a complex mechanism into a simple, conceptual

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) CS-2301 B-term 2008 Introduction to Operating Systems 7

Operating Systems • Typically – – Long-lived Frequently extended and updated Worked on by

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 CS-2301 B-term 2008 Introduction to Operating Systems 8

Kinds of operating systems • • • Mainframe Operating Systems Server Operating Systems Multiprocessor

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 … CS-2301 B-term 2008 Introduction to Operating Systems 9

OS and Hardware • OS mediates programs’ access to hardware – Computation – CPU

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 CS-2301 B-term 2008 Introduction to Operating Systems 10

Four fundamental Abstractions • Processes & threads • Multiplexing of processor(s) to create the

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 CS-2301 B-term 2008 Introduction to Operating Systems 11

Definition – Process • A particular execution of a program • Different from all

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 CS-2301 B-term 2008 Introduction to Operating Systems 12

Why Processes? • Enables programmers – to completely disengage from issues of concurrent execution

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 CS-2301 B-term 2008 Introduction to Operating Systems 13

Why Processes (continued)? • Exploit modern processors – Capable of executing multiple threads of

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 CS-2301 B-term 2008 Introduction to Operating Systems 14

Why Processes (continued)? • Exploit modern processors – Capable of executing multiple threads of

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: – – wer o p to ue d n o Integrated circuit componentslimshrink in itati ern on. d o 50% every 18 months M issipati d – Double in speed every 18 months CS-2301 B-term 2008 Introduction to Operating Systems 15 size by

Resources Assigned to a Process • Memory • Virtual or real • Processor time

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. CS-2301 B-term 2008 Introduction to Operating Systems 16

Resources (continued) • Managed by OS • Protection and isolation from other processes •

Resources (continued) • Managed by OS • Protection and isolation from other processes • Allocation according to defined policies • Enforcement of limits, etc. • … CS-2301 B-term 2008 Introduction to Operating Systems 17

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

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 CS-2301 B-term 2008 Introduction to Operating Systems 18

Threads (continued) • Linux: – • A thread is a special kind of process

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 CS-2301 B-term 2008 Introduction to Operating Systems 19

Why Threads? • To enable development of applications with concurrent activities inside them •

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 … CS-2301 B-term 2008 Introduction to Operating Systems 20

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

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 CS-2301 B-term 2008 Introduction to Operating Systems 21

Typical Virtual Memory for Process (Windows & Linux) 0 x. FFFF stack (dynamically allocated)

Typical Virtual Memory for Process (Windows & Linux) 0 x. FFFF stack (dynamically allocated) SP address space heap (dynamically allocated) static data 0 x 0000 CS-2301 B-term 2008 program code (text) Introduction to Operating Systems PC 22

Eve Sep ry p r Typical Virtual Memory for Process oces (Windows & Linux)

Eve Sep ry p r Typical Virtual Memory for Process oces (Windows & Linux) s ha arat s one e fro of th me ese. very 0 x. FFFF stack othe r pro (dynamically allocated) cess. address space SP heap (dynamically allocated) static data 0 x 0000 CS-2301 B-term 2008 program code (text) Introduction to Operating Systems PC 23

Virtual Memories in Embedded System 0 x 0000 FFFF stack Process 3 stack Physical

Virtual Memories in Embedded System 0 x 0000 FFFF stack Process 3 stack Physical Process 2 memory stack Process 1 OS Kernel 0 x 0000 CS-2301 B-term 2008 Introduction to Operating Systems 24

Virtual Memory for Multiple Threads 0 x. FFFF thread 1 stack SP (T 1)

Virtual Memory for Multiple Threads 0 x. FFFF thread 1 stack SP (T 1) thread 2 stack SP (T 2) thread 3 stack SP (T 3) Virtual address space heap static data 0 x 0000 CS-2301 B-term 2008 PC (T 2) PC (T 1) PC (T 3) code (text) Introduction to Operating Systems 25

Note on Threads • Most embedded system programmers will probably have to design with

Note on Threads • Most embedded system programmers will probably have to design with multiple threads in the future CS-2301 B-term 2008 Introduction to Operating Systems 26

Questions? CS-2301 B-term 2008 Introduction to Operating Systems 27

Questions? CS-2301 B-term 2008 Introduction to Operating Systems 27