What is a Process? Processes. Processes vs. Programs. Processes vs. Threads. Questions answered in this lecture: A process is different than a program

Similar documents
Processes and Non-Preemptive Scheduling. Otto J. Anshus

Chapter 2: OS Overview

Chapter 6, The Operating System Machine Level

Process Description and Control william stallings, maurizio pizzonia - sistemi operativi

CS161: Operating Systems

ELEC 377. Operating Systems. Week 1 Class 3

Introduction. What is an Operating System?

Operating Systems. Lecture 03. February 11, 2013

Operating Systems 4 th Class

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Computer-System Architecture

CSC 2405: Computer Systems II

Introduction to Operating Systems. Perspective of the Computer. System Software. Indiana University Chen Yu

An Implementation Of Multiprocessor Linux

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

How To Understand How A Process Works In Unix (Shell) (Shell Shell) (Program) (Unix) (For A Non-Program) And (Shell).Orgode) (Powerpoint) (Permanent) (Processes

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

Technical Properties. Mobile Operating Systems. Overview Concepts of Mobile. Functions Processes. Lecture 11. Memory Management.

COS 318: Operating Systems. I/O Device and Drivers. Input and Output. Definitions and General Method. Revisit Hardware

CS414 SP 2007 Assignment 1

W4118: segmentation and paging. Instructor: Junfeng Yang

Operating System Overview. Otto J. Anshus

Operating System Components and Services

Process definition Concurrency Process status Process attributes PROCESES 1.3

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Linux Driver Devices. Why, When, Which, How?

Chapter 3. Operating Systems

System Calls and Standard I/O

Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes

Virtual vs Physical Addresses

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Example of Standard API

Real Time Programming: Concepts

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Chapter 3 Operating-System Structures

Linux Process Scheduling Policy

Operating Systems Concepts: Chapter 7: Scheduling Strategies

Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest

Have both hardware and software. Want to hide the details from the programmer (user).

Operating System Tutorial

Origins of Operating Systems OS/360. Martin Grund HPI

Chapter 1 Computer System Overview

OPERATING SYSTEM SERVICES

Announcements. More OS motivation. Today s adventure. Why processes? Simplicity. www. Why processes? Speed. Processes in the real world

Exception and Interrupt Handling in ARM

Keil C51 Cross Compiler

This tutorial will take you through step by step approach while learning Operating System concepts.

SYSTEM ecos Embedded Configurable Operating System

I/O Device and Drivers

Chapter 11: Input/Output Organisation. Lesson 06: Programmed IO

Operating System Components

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

Operating System Structures

Performance Comparison of RTOS

Operating System: Scheduling

1. Computer System Structure and Components

Operating Systems. Privileged Instructions

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

LSN 2 Computer Processors

W4118 Operating Systems. Instructor: Junfeng Yang

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17

find model parameters, to validate models, and to develop inputs for models. c 1994 Raj Jain 7.1

CHAPTER 15: Operating Systems: An Overview

Overview of Operating Systems Instructor: Dr. Tongping Liu

COS 318: Operating Systems

First-class User Level Threads

Linux Scheduler. Linux Scheduler

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

UNIT 4 Software Development Flow

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 5 - DBMS Architecture

Processes, Protection and the Kernel: Mode, Space, and Context

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2005

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

Chapter 11 I/O Management and Disk Scheduling

ò Paper reading assigned for next Thursday ò Lab 2 due next Friday ò What is cooperative multitasking? ò What is preemptive multitasking?

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

TRACE PERFORMANCE TESTING APPROACH. Overview. Approach. Flow. Attributes

The Linux Kernel: Process Management. CS591 (Spring 2001)

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Traditional IBM Mainframe Operating Principles

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

Deciding which process to run. (Deciding which thread to run) Deciding how long the chosen process can run

Outline: Operating Systems

Keil Debugger Tutorial

CS0206 OPERATING SYSTEMS Prerequisite CS0201, CS0203

Module 8. Industrial Embedded and Communication Systems. Version 2 EE IIT, Kharagpur 1

Road Map. Scheduling. Types of Scheduling. Scheduling. CPU Scheduling. Job Scheduling. Dickinson College Computer Science 354 Spring 2010.

Storage. The text highlighted in green in these slides contain external hyperlinks. 1 / 14

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

How To Understand And Understand An Operating System In C Programming

CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.

Types Of Operating Systems

Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights

Real Time Control Under UNIX for RCCL

Transcription:

CS 537 Introduction to Operating Systems Processes Questions answered in this lecture: What is a process? UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department How does the dispatcher context-switch between processes? How does the OS create a new process? Andrea C. Arpaci-Dusseau Remzi H. Arpaci-Dusseau What is a Process? Process: An execution stream in the context of a process state Execution stream 1) Stream of executing instructions 2) Running piece of code 3) Sequential sequence of instructions 4) thread of control Process state Everything that the running code can affect or be affected by Registers General-purpose, floating point, status, program counter, stack pointer Address space Everything process can address through memory Represented by array of bytes Heap, stack, and code Processes vs. Programs A process is different than a program Program: Static code and static data Process: Dynamic instance of code and data No one-to-one mapping between programs and processes Can have multiple processes of the same program Example: many users can run ls at the same time One program can invoke multiple processes Example: make runs many processes to accomplish its work Processes vs. Threads A process is different than a thread Thread: Lightweight process (LWP) An execution stream that shares an address space Multiple threads within a single process Example: Two processes examining memory address 0xffe84264 see different values (I.e., different contents) Two threads examining memory address 0xffe84264 see same value (I.e., same contents) 1

System Classifications All systems support processes, but the number varies Uniprogramming: Only one process resident at a time Examples: First systems and DOS for PCs Advantages: Runs on all hardware Disadvantages: Not convenient for user and poor performance Multiprogramming: Multiple processes resident at a time (or, multitasking) Note: Different than multiprocessing Multiprocessing: Systems with multiple processors Examples: Unix variants, WindowsNT Advantages: Better user convenience and system performance Disadvantages: Complexity in OS Multiprogramming OS requirements for multiprogramming Mechanism To switch between processes To protect processes from one another Policy To decide which process to schedule Separation of policy and mechanism Reoccuring theme in OS Policy: Decision-maker to optimize some workload performance metric Which process when? Process Scheduler: Future lecture Mechanism: Low-level code that implements the decision How? Process Dispatcher: Today s lecture OS runs dispatch loop Dispatch Mechanism while (1) { run process A for some time-slice stop process A and save its context load context of another process B Context-switch Question 1: How does dispatcher gain control? Question 2: What execution context must be saved and restored? Q1: Hardware for Multiprogramming Must differentiate application process and OS Hardware support Bit in status word designates whether currently running in user or system mode System mode (or privileged or supervisor) allows functionality Execution of special instructions (e.g., access hardware devices) Access to all of memory Change stack pointer Usage Applications run in user mode OS runs in system mode 2

Q1: Entering system mode How does OS get control? 1) Synchronous interrupts, or traps Event internal to a process that gives control to OS Examples: System calls, page faults (access page not in main memory), or errors (illegal instruction or divide by zero) 2) Asynchronous interrupts Events external to a process, generated by hardware Examples: Characters typed, or completion of a disk transfer How are interrupts handled? Each type of interrupt has corresponding routine (handler or interrupt service routine (ISR) Hardware saves current process and passes control to ISR Q1: How does Dispatcher run? Option 1: Cooperative Multi-tasking Trust process to relinquish CPU through traps Trap: Event internal to process that gives control to OS Examples: System call, page fault (access page not in main memory), or error (illegal instruction or divide by zero) Disadvantages: Processes can misbehave By avoiding all traps and performing no I/O, can take over entire machine Only solution: Reboot! Not performed in modern operating systems Q1: How does Dispatcher run? Option 2: True Multi-tasking Guarantee OS can obtain control periodically Enter OS by enabling periodic alarm clock Hardware generates timer interrupt (CPU or separate chip) Example: Every 10ms User must not be able to mask timer interrupt Dispatcher counts interrupts between context switches Example: Waiting 20 timer ticks gives 200 ms time slice Common time slices range from 10 ms to 200 ms Q2: Process States Each process is in one of three modes: Transitions? Running: On the CPU (only one on a uniprocessor) Ready: Waiting for the CPU Blocked (or asleep): Waiting for I/O or synchronization to complete Running Blocked Ready 3

Q2: Tracking Processes OS must track every process in system Each process identified by unique Process ID (PID) OS maintains queues of all processes Ready queue: Contains all ready processes Event queue: One logical queue per event (e.g., disk I/O and locks) Contains all processes waiting for that event to complete Q2: What Context must be Saved? Dispatcher must track context of process when not running Save context in process control block (PCB) (or, process descriptor) What information is stored in PCB? PID Process state (I.e., running, ready, or blocked) Execution state (all registers, PC, stack ptr) Scheduling priority Accounting information (parent and child processes) Credentials (which resources can be accessed, owner) Pointers to other allocated resources (e.g., open files) Q2: Context-Switch Implementation Basic idea: Save all registers to PCB in memory Tricky: Must execute code without using registers Machine-dependent code (written in assembly) Different for x86, SPARC, MIPS, etc. Requires special hardware support Hardware saves process PC and PSR on interrupts CISC: Single instruction saves all registers onto stack RISC: Agreement to keep some registers empty Alpha and SPARC: Shadow registers MIPS: Two general-purpose registers are scratch, avoided by compiler How long does a context-switch take? 10s of microseconds Multiprogramming and Memory Does OS need to save all of memory between processes? Option 1: Save all of memory to disk Example: Alto, early personal workstation Disadvantage: Very time consuming How long to save a 10 MB process to disk? Option 2: Trust next process to not overwrite memory Example: Early multiprogramming in PCs and Macs (single user) Disadvantage: Very hard to track down bugs Option 3: Protect memory (and files) from next process Requires hardware support Investigate later in course 4

Process Creation Two ways to create a process Build a new empty process from scratch Copy an existing process and change it appropriately Option 1: New process from scratch Steps Load specified code and data into memory; Create empty call stack Create and initialize PCB (make look like context-switch) Put process on ready list Advantages: No wasted work Disadvantages: Difficult to setup process correctly and to express all possible options Process permissions, where to write I/O, environment variables Example: WindowsNT has call with 10 arguments Process Creation Option 2: Clone existing process and change Example: Unix fork() and exec() Fork(): Clones calling process Exec(char *file): Overlays file image on calling process Fork() Stop current process and save its state Make copy of code, data, stack, and PCB Add new PCB to ready list Any changes needed to PCB? Exec(char *file) Replace current data and code segments with those in specified file Advantages: Flexible, clean, simple Disadvantages: Wasteful to perform copy and then overwrite of memory Unix Process Creation How are Unix shells implemented? While (1) { Char *cmd = getcmd(); Int retval = fork(); If (retval == 0) { // This is the child process // Setup the child s process environment here // E.g., where is standard I/O, how to handle signals? exec(cmd); // exec does not return if it succeeds printf( ERROR: Could not execute %s\n, cmd); exit(1); else { // This is the parent process; Wait for child to finish int pid = retval; wait(pid); 5