Mon Sep 17, 2007 Lecture 3: Process Management

Similar documents
Jan 20, 2005 Lecture 2: Multiprogramming OS

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Processes. CS3026 Operating Systems Lecture 05

Computer Systems II. First Two Major Computer System Evolution Steps

Chap 4, 5: Process. Dongkun Shin, SKKU

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

CS 333 Introduction to Operating Systems. Class 2 OS-Related Hardware & Software The Process Concept

518 Lecture Notes Week 3

What is a Process? Processes and Process Management Details for running a program

2 Processes. 2 Processes. 2 Processes. 2.1 The Process Model. 2.1 The Process Model PROCESSES OPERATING SYSTEMS

CS399 New Beginnings. Jonathan Walpole

OS Structure, Processes & Process Management. Don Porter Portions courtesy Emmett Witchel

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

CS 333 Introduction to Operating Systems Class 2 OS-Related Hardware & Software The Process Concept

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Linux Operating System

Lecture 4: Process Management

! The Process Control Block (PCB) " is included in the context,

CSE 380 Computer Operating Systems. Instructor: Insup Lee. University of Pennsylvania Fall 2003

CSC 1600 Unix Processes. Goals of This Lecture

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 3: Process Concept

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

CS510 Operating System Foundations. Jonathan Walpole

Processes. Sanzheng Qiao. December, Department of Computing and Software

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100

System Call. Preview. System Call. System Call. System Call 9/7/2018

Fall 2015 COMP Operating Systems. Lab #3

Operating Systems. II. Processes

CS 322 Operating Systems Practice Midterm Questions

Announcement. Exercise #2 will be out today. Due date is next Monday

Operating System Structure

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

o Reality The CPU switches between each process rapidly (multiprogramming) Only one program is active at a given time

Dr. Rafiq Zakaria Campus. Maulana Azad College of Arts, Science & Commerce, Aurangabad. Department of Computer Science. Academic Year

Processes, PCB, Context Switch

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Killing Zombies, Working, Sleeping, and Spawning Children

CS 31: Intro to Systems Processes. Kevin Webb Swarthmore College March 31, 2016

Unix Processes. What is a Process?

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

Process Description and Control

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 26

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

Processes and Threads

Introduction. CS3026 Operating Systems Lecture 01

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Processes. Process Scheduling, Process Synchronization, and Deadlock will be discussed further in Chapters 5, 6, and 7, respectively.

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

Processes. CSE 2431: Introduction to Operating Systems Reading: Chap. 3, [OSC]

Process Concepts 8/21/2014. CS341: Operating System. Scheduling: Theoretical Analysis

Sistemi in Tempo Reale

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU

CHAPTER 2: PROCESS MANAGEMENT

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Lecture 4: Memory Management & The Programming Interface

CSCE 313: Intro to Computer Systems

Design Overview of the FreeBSD Kernel CIS 657

Operating Systems. Figure: Process States. 1 P a g e

Processes. Process Concept

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

Operating Systems. Lecture 05

Chapter 3: Processes

CSci 4061 Introduction to Operating Systems. Processes in C/Unix

www nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

Lecture 2 Process Management

Processes. CS439: Principles of Computer Systems January 24, 2018

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

(MCQZ-CS604 Operating Systems)

Major Requirements of an OS

Misc. Third Generation Batch Multiprogramming. Fourth Generation Time Sharing. Last Time Evolution of OSs

The Kernel Abstraction. Chapter 2 OSPP Part I

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

CS450/550 Operating Systems

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Computer System Overview

OS lpr. www. nfsd gcc emacs ls 9/18/11. Process Management. CS 537 Lecture 4: Processes. The Process. Why Processes? Simplicity + Speed

Transcription:

Mon Sep 17, 2007 Lecture 3: Process Management September 19, 2007 1 Review OS mediates between hardware and user software QUIZ: Q: Name three layers of a computer system where the OS is one of these layers. A: Hardware, OS, Application Programs Q: Which of the following concepts do not belong in the group? Interrupt, Bootstrap, System Call, Trap, Exception A: Bootstrap. The others are just forms of interrupts. Interrupt is a generic name for any instruction that stops the CPU in its current execution. TRAP are self-generated software-generated interrupts System Calls. Exceptions are interrupts generated by some error condition or special status. System calls is an OS-specified function called via a TRAP. I/O Interrupt is generated by I/O hardware. Q: An OS provide services. How does a user access these services? A: Make system calls. to READ from disk: A: Steps of the READ system call: (1) User Program loads the arguments and calls a system library READ routine (2) This routine loads the code for reading and TRAPS (3) CPU switch to kernel mode, and executes at fixed address in the kernel. (4) CPU returns to the library READ routine (5) Library READ returns to user program. 2 Basic Issues in Multiprogramming We could begin with the simple view of an OS as a software to manage a set of processes. A process (or job or task) is a program in execution. As such, it has source code, current state, memory and files, resources such as printers and I/O. A closely related, more modern concept is thread. There are many variants of the thread concept, and its relation to processes. Here are some views: (1) Threads as a executional unit of a process. (2) Threads as a light-weight process. (3) Threads as kernel objects, or as process objects. In any case, an extended notion of OS is that an OS manages a collection of processes and their threads. The OS, as a manager of processes/threads, has to provide these functions: Process Management: (1) Create/delete, schedule, synchronize and provide communication among processes. (2) Process scheduling 1

Memory management: (1) Main Memory Management (2) File management (3) Memory hierarchy issues Resources management: e.g., Deadlock management. e.g., Networking e.g., I/O management Security and Protection: Just as there is some hierarchy involving threads and processes, we may also have hierarchy among the processes. E.g., in Unix, each process (except the root) has a parent process. The OS has to manage this hierarchy. 3 Memory Management for Multiprogramming KEY FUNCTION: provides multiprogramming environment Usefulness of multiprogramming: I/O bound vs CPU bound processes User processes vs Kernel processes When useful? What is needed for multiprogramming? Process management (process table) Memory management Interrupts (and ability to turn on/off interrupts)... Requirements: to isolate processes from each other, to isolate processes from kernel, to relocate programs. Relocation problem: when a program is compiled, it must be assumed that each instruction is placed in some location, and the locations conventionally start at 0. When this program is LOADED, it will begin at some address determined at runtime. Also, a certain amount of space is allocated for data. THE CDC MODEL (CDC is an early computer, one of the first models was delivered to Courant Institute in NYU in the 70s): Each process occupies a contiguous chunk of memory. THIS CALLS for a BASE REGISTER and a LIMIT REGISTER: Limit register tells the size of the program+data. Chunk = [base, base + limit] These registers are protected from users How does this modify our execution cycle? Each instruction or data fetch is checked to be within the limit, and then offset by base. But actually, it is done by the MMU. THIS illustrates virtual address vs physical address. context switching: the values of the register pair is a context! Drawback: we need to predict how much data is needed. So everyone overestimates. MODIFIED CDC MODEL: Have two pairs of Base+Limit registers. Pair 1 for program, Pair 2 for data. ADVANTAGE: processes can share program! 4 Processes Our first programming effort will involve multi-processes. So... We will examine processes in Unix and Windows! 2

How are processes created? At system initialization (foreground process, e.g., login shells), (background, e.g., email, http daemons) Users can create them (e.g., multiple window processes) E.g., > cat chap1.txt chap2.txt grep process Current process creates two new process, one to run cat (which contenates 2 files), the other to run grep (to look for word process ). UNIX: fork (creates a clone of caller process! but the the child can next do some manipulation and ultimately execute a execve to do its job) BUT both have different address spaces. THEY CAN share resources like open files. Windows: CreateProcess with 10 parameters! and lots of related functions. Process Hierarchies Windows: no hierarchy! The parent process has only one special advantage: it has the token or handle to control the child, but can give the handle away! Unix: from fork, get parent-child relation. ALL PROCESSES are descendents of the init process! The hierarchy cannot change except through process creation or process termination: when a parent process exits, all its children will have the init process as parent! Unix: Process group a process and all its descendents. If a signal is sent to root of group, it is delivered to all. How are Processes terminated? Normal exit (voluntary), Error exit (voluntary), Fatal error exit (involuntary), Killed by another process exit (involuntary), Unix: normal termination is achieved by a process executing the exit() system call. The exiting process may return a status value to parent. Unix: a process can terminate another process by calling abort(). E.g., a parent process aborts a child process if it is taking too long, or its services is no longer needed. EXAMPLE: Unix Fork The main interface to unix is the shell (there are many variants, bash being our default in cygwin). Each shell controls a window (assuming a multi-window GUI) The shell sits in a loop to process use commands. Suppose we type ls (list current directory). The shell would execute a fork() system call. This creates a new process, a CHILD of the current process. The PARENT process then executes a wait() for the CHILD to terminate. 3

After the CHILD does its job (listing current directory), it terminates and sends the parent a signal. The parent receives the signal and continues. HERE IS THE CODE to SIMULATE the process: #include < stdio.h > #include < unistd.h > int main (int argc, char *argv[]){ int pid; pid = fork(); if (pid < 0) { fprintf(stderr, fork failed ); exit(-1);} else if (pid == 0) { execlp( /bin/ls, ls, NULL);} else { wait(null); printf( child completed ); exit(0);} } 5 Process States and Transition Start Run Terminated Ready Pre-empt Running Unblock Blocked Block Figure 1: Process States and their transitions Cyclic States: Ready, Running, Blocked. Transitory States: New, Terminated. Refinements: Ready-suspended, blocked-suspended. (suspension is related to process swapping) NOTE: there is at most ONE process in the Running state (for each CPU). Possible state transitions (draw a transition diagram) Ready Running Blocked Ready. Also: New Ready, Running Terminated. Names of transitions: (1) create (New Ready) (1) terminate (Running Terminated) (2) preempt (Running Ready) caused by scheduler (2) run (Ready Running) caused by scheduler (3) block (Running Blocked) (3) unblock (Blocked Ready) caused by event 4

6 Process Scheduler OBJECTIVES OF SCHEDULING: Efficient use of resources (e.g., CPU usage). That is the reason for blocking a process. Fairness among processes (time-to-completion should be proportional to job size). That is the reason for preempting a process at the end of a quantum. (running ready) and (ready running) are done by process scheduler! These 2 transitions requires context switching, which is hardware supported. Scheduler [p.142-3]. Round Robin is simplest preemptive scheduler: (1) Ready processes are in FIFO queue (ready queue) (2) Each process runs in a fixed quantum (e.g. 50ms) (3) Current process P runs till it BLOCKS, in which case it is moved to blocked queue, or it finished its quantum, and put in end of ready queue. (4) Next process at top of FIFO queue is next running. Scheduler Queues: Job Queue: all current jobs Ready Queue: jobs in main memory in Ready state Device Queue: jobs waiting for a particular device See DIAGRAM of transitions between queues. [Silberschatz, Fig 4.5, p.109] REFINEMENTS of Schedulers (Silbershatz, p.109): CPU Scheduler (or short-term scheduler): manages the ready queue JOB Scheduler (or long-term scheduler): manages the Job Queue on disk (swaps processes in/out of main memory) It decides on how to admit New processes into the ready queue. 7 Process Management We now look a bit into the nitty-gritty for process management. Datastructure called Process Table (one entry/process). Each entry is called a Process Control Block (PCB). Each entry or PCB: Process ID Process State Registers: PC, SP, PSW, etc memory allocation files and their status accounting (CPU usage, memory usage, etc) scheduling info I/O status info for context switching 5

OTHER INFORMATION: priority, parent process, process group, signals, time when process started, children s CPU time, time of next alarm; pointer to text segment, data segment, stack segment; root directory, working directory, file descriptors, user ID, group ID. Process Image: memory must be organized to store each current process (in any state). TYPICAL LAYOUT IN MEMORY: text section (code), data section (global variables), stack section (params of calls, return addr, local vars) Each I/O Class (floppy, hard disk, timers, terminals,...) has a location called an interrupt vector. It has the address of the interrupt routine. If process 3 is running when a disk interrupt occurs: then HARDWARE causes process 3 s PC, registers, etc to be pushed onto the current stack, and make CPU jumps to the interrupt vector. That is all the hardware does. From then on, the interrupt service procedure takes over. When done, returns to the scheduler. 8 THREADS What is a THREAD? View a traditional process as a single thread. A process can have SEVERAL threads of execution. The threads all SHARE the same address space. The reason for threads are similar to the ones for processes BUT: easy to create and destroy the need to share data useful when threads are I/O bound E.g. Process running an editor: the process can run several threads at the same time: (1) thread for backup of file in background (2) thread for reformatting of file while we continue to edit the file (3) thread for reading from keyboard (4) thread for writing to screen (5) thread to do spell checking in background WHAT IS THE POINT? WHY DON T WE JUST HAVE JUST HAVE 5 PROCESSES? Processes share resources, but threads are executional units, that does not have independent resources. So sharing among threads within a process is very cheap. Thread can be implemented in kernel or user space 6

9 Buses It is useful to know about an essential piece of hardware in all modern computers: the bus. Various hardware devices talk to each other using buses. A bus is a set of wires with a well-defined protocol for sending and receiving messages along the wires. Various devices (monitor, procesor, keyboard, disk, etc) can be attached to the bus. Usually, devices have a dedicated unit called controller to interface with the bus. PC s have 8 BUSES. original IBM: ISA (ISA bridge various devices) Rate of 16 MB/sec. successor to ISA: PCI (PCI bridge various slots, inc.isa Bridge) Rate of 528 MB/sec. Newer buses: cache (CPU Level 2 cache) local (CPU PCI bridge) memory (PCI bridge Main Memory) SCSI (high performance bus for fast disks, scanners, etc) Rate of 160 MB/sec. USB (for slow I/O devices like keyboard, mouse) Rate of 1.5 MB/sec. Convenient to add devices, without reboot. Since 2001, USB 2.0 (Hi-Speed USB) introduced with rate of 60 MB/sec. IDE (for peripherals such as CD ROMs, disks) New: FireWire (a.k.a. i.link or IEEE 1394) (50 MB/sec) like USB but much faster (useful for audio/video devices like camcorders, etc) Partly viewed as replacement for USB. 7