Operating-System Structures CS 3100 Operating-System Structures1.
Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301,...
-
date post
18-Dec-2015 -
Category
Documents
-
view
224 -
download
0
Transcript of Introduction to Operating Systems CS-2301 B-term 20081 Introduction to Operating Systems CS-2301,...
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)
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
Introduction to Operating Systems
CS-2301 B-term 2008 3
Class Discussion
What is an Operating System?
(Laptops closed, please!)
Introduction to Operating Systems
CS-2301 B-term 2008 4
What Operating Systemshave you Used?
(Other than Windows, Linux, Mac-OS, Unix)
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
– …
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.
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)
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
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• …
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
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
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
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
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
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.
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.
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.
• …
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
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
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
• …
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
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
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.
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
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)
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
Introduction to Operating Systems
CS-2301 B-term 2008 27
Questions?