Introduction to Operating Systems CS-2301, B-Term 20091 Introduction to Operating Systems CS-2301, System Programming for Non-Majors (Slides include materials.

Slides:



Advertisements
Similar presentations
Categories of I/O Devices
Advertisements

Operating System.
Operating Systems Manage system resources –CPU scheduling –Process management –Memory management –Input/Output device management –Storage device management.
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
An Overview of the Computer System
EEE 435 Principles of Operating Systems Operating System Concepts (Modern Operating Systems 1.5)
Computer Systems/Operating Systems - Class 8
Introduction to Operating Systems CS-2301 B-term Introduction to Operating Systems CS-2301, System Programming for Non-majors (Slides include materials.
Processes CSCI 444/544 Operating Systems Fall 2008.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
More on FunctionsCS-2301 B-term More on Functions CS-2301, System Programming for Non-majors (Slides include materials from The C Programming Language,
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Chapter 11 Operating Systems
1 Introduction Chapter What is an operating system 1.2 History of operating systems 1.3 The operating system zoo 1.4 Computer hardware review 1.5.
Accessing Files in CCS-2303, C-Term Accessing Files in C CS-2303 System Programming Concepts (Slides include materials from The C Programming Language,
Introduction Operating Systems’ Concepts and Structure Lecture 1 ~ Spring, 2008 ~ Spring, 2008TUCN. Operating Systems. Lecture 1.
CS 3013 & CS 502 Summer 2006 Threads1 CS-3013 & CS-502 Summer 2006.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Computer Parts There are many parts that work together to make a computer work.
Operating Systems.
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
Recursion and Implementation of Functions
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Chapter 3 Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
Computer Organization Review and OS Introduction CS550 Operating Systems.
Flash Cards Computer Technology.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Operating System. Architecture of Computer System Hardware Operating System (OS) Programming Language (e.g. PASCAL) Application Programs (e.g. WORD, EXCEL)
Section 3.1: Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random.
Operating Systems. Without an operating system your computer would be useless! A computer contains an Operating System on its Hard Drive. This is loaded.
Processes and OS basics. RHS – SOC 2 OS Basics An Operating System (OS) is essentially an abstraction of a computer As a user or programmer, I do not.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CE Operating Systems Lecture 3 Overview of OS functions and structure.
File Management Chapter 12. File Management File management system is considered part of the operating system Input to applications is by means of a file.
CS333 Intro to Operating Systems Jonathan Walpole.
Introduction to Operating Systems CS-2301 B-term Introduction to Operating Systems (continued) CS-2301, System Programming for Non-majors (Slides.
Chapter 1 Introduction  What is an operating system  History of operating systems  The operating system zoo  Computer hardware review  Operating system.
Operating Systems: Summary INF1060: Introduction to Operating Systems and Data Communication.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
INTRODUCTION TO COMPUTERS. A computer system is an electronic device used to input data, process data, store data for later use and produce output in.
Introduction to Operating Systems Concepts
Processes and threads.
An Overview of the Computer System
Chapter 3: Process Concept
Operating System.
Operating Systems (CS 340 D)
CS399 New Beginnings Jonathan Walpole.
Operating Systems (CS 340 D)
Looking Inside the machine (Types of hardware, CPU, Memory)
An Overview of the Computer System
An Overview of the Computer System
Processes in Unix, Linux, and Windows
Processes in Unix, Linux, and Windows
CS703 - Advanced Operating Systems
Lecture Topics: 11/1 General Operating System Concepts Processes
CSCE 313 – Introduction to UNIx process
Recursion and Implementation of Functions
Accessing Files in C Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Introduction to Operating Systems
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
CS510 Operating System Foundations
CSE 153 Design of Operating Systems Winter 2019
Chapter-1 Computer is an advanced electronic device that takes raw data as an input from the user and processes it under the control of a set of instructions.
Presentation transcript:

Introduction to Operating Systems CS-2301, B-Term Introduction to Operating Systems CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie and from C: How to Program, 5 th and 6 th editions, by Deitel and Deitel)

Introduction to Operating Systems CS-2301, B-Term 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 Class Discussion What is an Operating System? (Laptops closed, please!)

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

Introduction to Operating Systems CS-2301, B-Term 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 = 10 8 –10 9 lines of code (Windows and Linux) 10 7 line of code for a real-time OS. Some systems smaller

Introduction to Operating Systems CS-2301, B-Term 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 We have already had this notion in the definition of function in C Abstraction is a collection of functions and data for creating a simple model

Introduction to Operating Systems CS-2301, B-Term 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 –… What operating system services have we used already in this course?

Introduction to Operating Systems CS-2301, B-Term 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 Important new category E.g.:– Windows Linux Unix Kinds of operating systems Mainframe Operating Systems Server Operating Systems Multiprocessor Operating Systems Personal Computer Operating Systems Mobile Phone 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 Some operating systems you may (or may not) have heard about z/OS VMS/Open VMS VxWorks RT Linux QNX Neutrino eCOS BrickOS/LeJos TinyOS Arduino … iPhone OS Android Symbian Blackberry OS PalmOS/Garnet Windows Mobile …

Introduction to Operating Systems CS-2301, B-Term 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 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 – i.e., persistent storage Organizing principles about long-term data storage Sockets & Connections Organizing principles about network communication

Introduction to Operating Systems CS-2301, B-Term 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 – i.e., persistent storage Organizing principles about long-term data storage Sockets & Connections Organizing principles about network communication

Introduction to Operating Systems CS-2301, B-Term 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 seem like each process has its own CPU Can execute at same time! Uses interrupts to manage and enforce multiplexing of CPU

Introduction to Operating Systems CS-2301, B-Term Definition – Interrupt A mechanism by which the processor suspends execution of the current, running program and gives control to the OS OS saves the state of the interrupted program so that it can be restarted later OS then takes appropriate action

Introduction to Operating Systems CS-2301, B-Term 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 –Safely!

Introduction to Operating Systems CS-2301, B-Term Why Processes (continued)? Exploit modern processors –Capable of executing multiple, simultaneous, program executions –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 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 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 Shell / Command Prompt Linux Shell is a process Windows Command Prompt is a process Created when you log on or connect to system (e.g., via PuTTY) Open Command Prompt, konsole, xterm, etc., window –Reads what you type (and displays it in your window) –Interprets lines as commands and arguments –Creates a process for each command, passes args –(Typically) waits for process to complete before interpreting next line

Introduction to Operating Systems CS-2301, B-Term Window Manager Window Manager is a process Tracks mouse movements, key clicks, menu actions “Open” an application means … Create process for that application; give it a window “Open” a document means … If application is not open, create process for it Pass document as argument to application

Introduction to Operating Systems CS-2301, B-Term Creating and Deleting Processes A process is created … –… at system boot time The first process Built-in processes – e.g., in embedded systems OR –… by another process Possibly in response to an action by a (human) user A process is deleted … –When its program exits –By another process – killed or paused (by debugger) –When system crashes or shuts down

Introduction to Operating Systems CS-2301, B-Term Questions about Processes?

Introduction to Operating Systems CS-2301, B-Term 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 separate memory per process Files – i.e., persistent storage Organizing principles about long-term data storage Sockets & Connections Organizing principles about network communication

Introduction to Operating Systems CS-2301, B-Term Virtual Memory Definition:– the illusion that a process has its own, independent 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 Independence of Virtual Memories A process cannot even see the virtual memory of another process A process cannot even see the memory used by the OS I.e., no possible pointer value can point to something in a different virtual memory Separate, parallel universes Except where explicitly linked together

Introduction to Operating Systems CS-2301, B-Term Typical Virtual Memory for Process (Windows & Linux) 0x xFFFFFFFF address space program code (text) static data heap (dynamically allocated) stack (dynamically allocated) PC SP

Introduction to Operating Systems CS-2301, B-Term Typical Virtual Memory for Process (Windows & Linux) 0x xFFFFFFFF address space program code (text) static data heap (dynamically allocated) stack (dynamically allocated) PC SP Every process has one of these. Independent of all others.

Introduction to Operating Systems CS-2301, B-Term Virtual Memory (continued) Typical virtual memory size – 4 GBytes Per process — even in a 1 GByte computer! “Inactive” pages are not resident in RAM Reference results in interrupt called a page fault OS brings in page from disk, (maybe) swaps one out Unused pages not filled in by OS Dereferencing pointer results in Segmentation Fault New pages created by OS as needed When stack or heap grows or programs are loaded

Introduction to Operating Systems CS-2301, B-Term Virtual Memory in Embedded Systems Implemented by partitioning RAM No swapping in or out May not even have a disk! Also in smart-phone operating systems

Introduction to Operating Systems CS-2301, B-Term Virtual Memories in Embedded System OS Kernel stack Process 1 stack Process 2 0x x0000FFFF Physical memory stack Process 3

Introduction to Operating Systems CS-2301, B-Term Questions about Processes or Virtual Memory? Not in Kernighan & Ritchie

Introduction to Operating Systems CS-2301, B-Term Threads A refinement of concept of process Short for “thread of control” Concurrent execution of a function within the context of a process Needs own stack in order to call other functions Shares heap, static data, and code with other threads of same process Reason Application may need to manage concurrency of its own computation with external events

Introduction to Operating Systems CS-2301, B-Term Virtual Memory for Multiple Threads 0x xFFFFFFFF 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 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 Thread Interface – POSIX standard #include int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void*(*start_routine) (void), void *arg) –creates a new thread of control –new thread begins executing at start_routine pthread_exit(void *value_ptr) –terminates the calling thread pthread_join(pthread_t thread, void **value_ptr) –blocks the calling thread until the thread specified terminates pthread_t pthread_self() –Returns the calling thread's identifier

Introduction to Operating Systems CS-2301, B-Term Thread Interface – POSIX standard #include int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void*(*start_routine) (void), void *arg) –creates a new thread of control –new thread begins executing at start_routine pthread_exit(void *value_ptr) –terminates the calling thread pthread_join(pthread_t thread, void **value_ptr) –blocks the calling thread until the thread specified terminates pthread_t pthread_self() –Returns the calling thread's identifier Pointer to a function– see §5.7 of K & R

Introduction to Operating Systems CS-2301, B-Term Thread Interface – POSIX standard #include int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void*(*start_routine) (void), void *arg) –creates a new thread of control –new thread begins executing at start_routine pthread_exit(void *value_ptr) –terminates the calling thread pthread_join(pthread_t thread, void **value_ptr) –blocks the calling thread until the thread specified terminates pthread_t pthread_self() –Returns the calling thread's identifier Arguments to that function

Introduction to Operating Systems CS-2301, B-Term Thread Example pthread_create(tp, &f, &args) pthread_join(tp) main function f g f h f

Introduction to Operating Systems CS-2301, B-Term Thread Example pthread_create(tp, &f, &args) pthread_join(tp) main function f g f h f Two threads run at the same time

Introduction to Operating Systems CS-2301, B-Term Why Threads? To enable development of applications with concurrent activities inside them Need to share data (difficult with separate virtual memories) 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 Example Thread Application One or more threads to get data from sensor 1000 times per second; cannot afford to miss a reading Places data on queue Another thread processes and displays data Removes and processes each data item from queue Displays system state on control panel User thread Allows operator to adjust system parameters While other threads are still running

Introduction to Operating Systems CS-2301, B-Term Additional Functions & Data Required pthread_mutex_t — mutual exclusion lock –Enables a thread to “lock” some data so that other threads do not touch in mid-operation pthread_cond_t — condition variable –Enables a thread to wait for an event to happen –Signaled by another thread See man pages for details

Introduction to Operating Systems CS-2301, B-Term Questions about Threads? Not in Kernighan & Ritchie

Introduction to Operating Systems CS-2301, B-Term 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 Definition – File A (potentially) large amount of information or data that lives a (potentially) very long time Often much larger than the memory of the computer Often much longer than any computation Sometimes longer than life of machine itself (Usually) organized as a linear array of bytes or blocks Internal structure is imposed by application (Occasionally) blocks may be variable length (Often) requiring concurrent access by multiple threads or processes Even by processes on different machines!

Introduction to Operating Systems CS-2301, B-Term Implementations of Files Usually on disks (or devices that mimic disks) Magnetic – hard drive or floppy Optical – CD, DVD Flash drives – electronic memory, organized as disks Requirement Preserve data contents during power-off or disasters Directory / Folder Special kind of file that contains links pointing to other files Associates names with files

Introduction to Operating Systems CS-2301, B-Term Implementations of Files Usually on disks (or devices that mimic disks) Magnetic – hard drive or floppy Optical – CD, DVD Flash drives – electronic memory, organized as disks Requirement Preserve data contents during power-off or disasters Directory / Folder Special kind of file that contains links pointing to other files Associates names with files Older systems also used magnetic tape, paper tape, trays of punched cards, etc.

Introduction to Operating Systems CS-2301, B-Term File Access in C See Kernighan & Ritchie, Chapter 8 Raw file access Without simplifying stream functions – e.g., –scanf, fscanf, printf, fprintf, fgetc, etc. read and write raw disk blocks Seek to a file position –lseek, fseek — sets file pointer to specified location –Subsequent read, write, etc., start there –ftell – returns file pointer

Introduction to Operating Systems CS-2301, B-Term Organizations of Files Contiguous Blocks stored contiguously on storage medium E.g., CD, DVD, some large database systems Access time to any block is O(1) Linked Blocks linked together – File Allocation Table (FAT) Access time is O(n) Indexed Blocks accessed via tree of index blocks (i-nodes) Access time is O(log n) However, base of logarithm may be very large (>100)

Introduction to Operating Systems CS-2301, B-Term Organizations of Files Contiguous Blocks stored contiguously on storage medium E.g., CD, DVD, some large database systems Access time to any block is O(1) Linked Blocks linked together – File Allocation Table (FAT) Access time is O(n) Indexed Blocks accessed via tree of index blocks (i-nodes) Access time is O(log n) However, base of logarithm may be very large (>100) NTFS and Linux file systems on hard drives

Introduction to Operating Systems CS-2301, B-Term Organizations of Files Contiguous Blocks stored contiguously on storage medium E.g., CD, DVD, some large database systems Access time to any block is O(1) Linked Blocks linked together – File Allocation Table (FAT) Access time is O(n) Indexed Blocks accessed via tree of index blocks (i-nodes) Access time is O(log n) However, base of logarithm may be very large (>100) Typical camera chips, flash drives, floppies

Introduction to Operating Systems CS-2301, B-Term Questions about Files?

Introduction to Operating Systems CS-2301, B-Term 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 Sockets and Connections Connection: –a serial conversation over a network between two end points e.g., processes, threads, tasks on different computers –organized as a sequence of messages or datagrams –distinct from all other connections Socket: –An end point of a connection –An abstraction that allows a process to send or receive only the information of that connection –Multiplexed on network with all other connections

Introduction to Operating Systems CS-2301, B-Term Sockets and Connections Defer to another course –CS-4513, Distributed Systems –CS-4514, Computer Networks

Introduction to Operating Systems CS-2301, B-Term General Questions?