Chapter 3: Processes. Operating System Concepts 8 th Edition,

Similar documents
Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

Process Concept. Chapter 4: Processes. Diagram of Process State. Process State. Process Control Block (PCB) Process Control Block (PCB)

Chapter 4: Processes

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

Chapter 4: Processes. Process Concept

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Chapter 4: Processes. Process Concept

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Chapter 4: Processes

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Diagram of Process State Process Control Block (PCB)

Processes. Operating System Concepts with Java. 4.1 Sana a University, Dr aimen

Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts Essentials 8 th Edition

Part Two - Process Management. Chapter 3: Processes

Processes. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & Apps 1

Chapter 3: Processes. Operating System Concepts 8th Edition,

The Big Picture So Far. Chapter 4: Processes

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

Chapter 3: Processes

The Big Picture So Far. Chapter 4: Processes

Chapter 3: Process Concept

Chapter 3: Processes. Operating System Concepts 8 th Edition,

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Chapter 3: Process Concept

Chapter 3: Processes. Operating System Concepts 9 th Edition

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

Chapter 3: Processes

Chapter 3: Process Concept

Chapter 3: Process Concept

CHAPTER 3 - PROCESS CONCEPT

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss

Lecture 2 Process Management

Chapter 3: Processes. Operating System Concepts 9 th Edition

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

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

Course: Operating Systems Instructor: M Umair. M Umair

Chapter 3: Process Concept

Chapter 4: Processes. Process Concept. Process State

Chapter 3: Processes. Operating System Concepts 8th Edition

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

Chapter 4: Processes

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

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Process Concept Process Scheduling Operations On Process Inter-Process Communication Communication in Client-Server Systems

Process. Program Vs. process. During execution, the process may be in one of the following states

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

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

2. PROCESS. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

CS420: Operating Systems. Interprocess Communication

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

Process Concept. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

ICS Principles of Operating Systems

Processes and Threads

Process. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

CS370 Operating Systems

Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne

Processes. Process Concept

CHAPTER 2: PROCESS MANAGEMENT

CSC 539: Operating Systems Structure and Design. Spring 2006

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Dept. Of Computer Science, Colorado State University

Operating System Design

Frequently asked questions from the previous class survey

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

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

Page 1. Analogy: Problems: Operating Systems Lecture 7. Operating Systems Lecture 7

Killing Zombies, Working, Sleeping, and Spawning Children

Outlook. Process Concept Process Scheduling Operations on Processes. IPC Examples

Operating System Concepts Ch. 3: Processes

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

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

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. CS 475, Spring 2018 Concurrent & Distributed Systems

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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

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

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

UNIT - II PROCESS MANAGEMENT

Processes. Operating System Concepts 8 th Edition

CSI Module 2: Processes

Processes. Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra

Process Concept Process in Memory Process State new running waiting ready terminated Diagram of Process State

Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors

CS370 Operating Systems

Outline. Interprocess Communication. Interprocess Communication. Communication Models: Message Passing and shared Memory.

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

Announcements. Operating Systems. Autumn CS4023

CS Lecture 2! Processes! George Mason University! Fall 2010!

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

Processes CHAPTER CHAPTER OBJECTIVES. 3.1 Process Concept

Concurrent Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 3: Processes

Transcription:

Chapter 3: Processes, Silberschatz, Galvin and Gagne 2009

Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2 Silberschatz, Galvin and Gagne 2009

Objectives To introduce the notion of a process -- a program in execution, which forms the basis of all computation To describe the various features of processes, including scheduling, creation and termination, and communication 3.3 Silberschatz, Galvin and Gagne 2009

Process Concept An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks Textbook uses the terms job and process almost interchangeably Process a program in execution; process execution must progress in sequential fashion A process includes: program counter Stack (ex. return address) data section Text ( code) Heap (memory that is dynamically allocated during process run time) 3.4 Silberschatz, Galvin and Gagne 2009

Process in Memory 3.5 Silberschatz, Galvin and Gagne 2009

Process State As a process executes, it changes state new: The process is being created running: Instructions are being executed waiting: The process is waiting for some event to occur (such as I/O) ready: The process is waiting to be assigned to a processor terminated: The process has finished execution 3.6 Silberschatz, Galvin and Gagne 2009

Diagram of Process State 3.7 Silberschatz, Galvin and Gagne 2009

Process Control Block (PCB) Each process is represented in the OS by PCB. It is data structure called the process control block (PCB) that holds all this stuff The PCB is identified by an integer process ID (PID) It is a snapshot of the execution and protection environment Only one PCB active at a time OS keeps all of a process s hardware execution state in the PCB when the process isn t running PC, SP, registers, etc. when a process is unscheduled, the state is transferred out of the hardware into the PCB 3.8 Silberschatz, Galvin and Gagne 2009

Process Control Block (PCB) Information associated with each process Process state: new, ready, running, waiting, halted. Program counter: the address of the next instruction to be executed for this process. CPU registers: accumulators, Index registers, SP,.. Must be saved when an interrupt occurs to allow the process to be continued correctly afterward. CPU scheduling information : ex. process priority. Memory-management information : ex. the value of the base and limit registers. Accounting information : ex. process number. I/O status information : ex. List of I/O devices allocated to the process, list of open files. 3.9 Silberschatz, Galvin and Gagne 2009

Process Control Block (PCB) 3.10 Silberschatz, Galvin and Gagne 2009

CPU Switch From Process to Process When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process The act of switching the CPU from one process to another is called a context switch. Context-switch time is overhead; the system does no useful work while switching Time dependent on hardware support 3.11 Silberschatz, Galvin and Gagne 2009

CPU Switch From Process to Process 3.12 Silberschatz, Galvin and Gagne 2009

Process Scheduling Queues The process scheduler selects an available process( from a set of several available processes) for program execution on the CPU. Job queue set of all processes in the system Ready queue set of all processes residing in main memory, ready and waiting to execute Device queues set of processes waiting for an I/O device (each device has its own device queue) Processes migrate among the various queues 3.13 Silberschatz, Galvin and Gagne 2009

Ready Queue And Various I/O Device Queues 3.14 Silberschatz, Galvin and Gagne 2009

Representation of Process Scheduling (queuing diagram) 3.15 Silberschatz, Galvin and Gagne 2009

Schedulers Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue and load them into memory. Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU 3.16 Silberschatz, Galvin and Gagne 2009

Addition of Medium Term Scheduling 3.17 Silberschatz, Galvin and Gagne 2009

Schedulers (Cont) Short-term scheduler is invoked very frequently (milliseconds) (must be fast) Long-term scheduler is invoked very infrequently (seconds, minutes) (may be slow) The long-term scheduler controls the degree of multiprogramming (the number of processes in memory). Processes can be described as either: I/O-bound process spends more time doing I/O than computations, many short CPU bursts CPU-bound process spends more time doing computations; few very long CPU bursts The long term scheduler should select a good process mix of I/O bound and CPU-bound processes. 3.18 Silberschatz, Galvin and Gagne 2009

Operations on the processes 1-Process Creation a process may create several new processes, via a create-process system call. Parent process create children processes, which, in turn create other processes, forming a tree of processes Most O.S. identify process and managed via a unique process identifier (pid) (an integer number). A process will need resources (CPU time, memory, files, ) to accomplish its task. When a process creates a subprocess, that subprocess may be able to obtain its resources directly from O.S. or Resource sharing Parent and children share all resources Children share subset of parent s resources Parent and child share no resources Execution Parent and children execute concurrently Parent waits until some or all children terminate 3.19 Silberschatz, Galvin and Gagne 2009

Process Creation (Cont) Address space Child duplicate of parent (it has the same program and data as the parent). Child has a new program loaded into it UNIX examples fork system call creates new process (copy of the address space of the original process). exec system call used after a fork to replace the process memory space with a new program Wait() the parent waits for the child process to complete. Exit(). 3.20 Silberschatz, Galvin and Gagne 2009

Process Creation 3.21 Silberschatz, Galvin and Gagne 2009

A tree of processes on a typical Solaris 3.22 Silberschatz, Galvin and Gagne 2009

2- Process Termination A Process terminates when it finishes executing its last statement and asks the operating system to delete it by using the (exit) syste call. Return a value from child to parent (via wait) Process resources are deallocated by operating system Parent may terminate execution of children processes (abort) Child has exceeded allocated resources Task assigned to child is no longer required If parent is exiting Some operating system do not allow child to continue if its parent terminates All children terminated - cascading termination 3.23 Silberschatz, Galvin and Gagne 2009

Interprocess Communication Independent process cannot affect or be affected by the execution of another process Cooperating process can affect or be affected by other processes, including sharing data Reasons for cooperating processes: Information sharing (ex.: shared file) Computation speedup (break up process into sub tasks to run faster and can be achieved only if the computer has multiple processing elements CPUs or I/O channels) Modularity (dividing system functions into separate processes or threads) Convenience (individual user may work on many tasks at the same time could be editing, printing, and compiling in parallel) 3.24 Silberschatz, Galvin and Gagne 2009

Mechanism for processes to communicate and to synchronize their actions Two models of IPC: Interprocess Communication 1) shared memory cooperating processes exchange information by reading and writing data to a shared region of memory. * allows maximum speed and convenience of communication. * faster than message passing (system calls only to establish the region. All accesses are routine memory accesses, no assistance from the kernel). 2) message passing messages are exchanged between the cooperating processes * useful for exchanging smaller amounts of data. * easier to implement than is shared memory for intercomputer communications. * implemented using system calls (more time, kernel intervention). 3.25 Silberschatz, Galvin and Gagne 2009

Communications Models 3.26 Silberschatz, Galvin and Gagne 2009

Shared memory system IPC using shared memory requires communicating processes to establish region of shared memory. The region resides in the address space of the process creating the shared memory segment. Shared memory requires that two or more processes agree to remove the restriction. Exchange information by reading and writing data in the shared area. The processes are responsible for ensuring that they are not writing to the same location simultaneously. 3.27 Silberschatz, Galvin and Gagne 2009

Producer-Consumer Problem A common Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process. Ex. The assembler produce object modules, which are consumed by the loader. Ex. Web server produces(provides) HTML files and images, which are consumed (read) by the web browser requesting the resource. One solution to the producer-consumer problem uses shared memory. To Allow the P and C processes to run concurrently, we must have a buffer that can be filled by the P and emptied by the C. This buffer reside in a region of memory that is shared by the P and C processes. 3.28 Silberschatz, Galvin and Gagne 2009

Producer-Consumer Problem The P and C must be synchronized, so that the C does not try to consume an item that has not yet been produced. Two types of buffers: unbounded-buffer places no practical limit on the size of the buffer (the C may wait, the P can always produce new items) bounded-buffer assumes that there is a fixed buffer size ( the C must wait if buffer empty, the P must wait if the buffer is full). 3.29 Silberschatz, Galvin and Gagne 2009

Interprocess Communication Message Passing Provides a Mechanism for processes to communicate and to synchronize their actions. Message system processes communicate with each other without resorting to shared variables. IPC message-passing facility provides two operations: send(message) message size fixed or variable receive(message) If processes P and Q wish to communicate, they need to: establish a communication link between them exchange messages via send/receive Implementation of communication link : physical (e.g., shared memory, hardware bus) logical (e.g., logical properties) 3.30 Silberschatz, Galvin and Gagne 2009

Implementation Questions How are links established? Can a link be associated with more than two processes? How many links can there be between every pair of communicating processes? What is the capacity of a link? Is the size of a message that the link can accommodate fixed or variable? Is a link unidirectional or bi-directional? 3.31 Silberschatz, Galvin and Gagne 2009

Interprocess Communication Message Passing Several methods for logically implementing a link, and the send()/receive() operations : Direct or indirect communication. Synchronous or asynchronous communication. Automatic or explicit buffering. 3.32 Silberschatz, Galvin and Gagne 2009

Direct Communication Processes must name each other explicitly: send (P, message) send a message to process P receive(q, message) receive a message from process Q The Properties of the communication link: Links are established automatically between every pair of processes that want to communicate. The processes need to know only each other s identity to communicate. A link is associated with exactly one pair of communicating processes Between each pair there exists exactly one link The link may be unidirectional, but is usually bi-directional 3.33 Silberschatz, Galvin and Gagne 2009

Indirect Communication Messages are directed and received from mailboxes (also referred to as ports) Each mailbox has a unique id Processes can communicate only if they share a mailbox Properties of communication link Link established only if processes share a common mailbox A link may be associated with many processes Each pair of processes may share several communication links, with each link corresponding to one mailbox. Link may be unidirectional or bi-directional 3.34 Silberschatz, Galvin and Gagne 2009

Indirect Communication A mailbox may be owned either by a process (part of its address space) or by the OS. When a process that owns a mailbox terminates, the mailbox disappears. OS allows the process the operations: create a new mailbox send and receive messages through mailbox destroy a mailbox Primitives are defined as: send(a, message) send a message to mailbox A receive(a, message) receive a message from mailbox A 3.35 Silberschatz, Galvin and Gagne 2009

Indirect Communication Mailbox sharing P 1, P 2, and P 3 share mailbox A. P 1, sends a message to A; P 2 and P 3 receive from A. Who gets the message? Solutions Allow a link to be associated with at most two processes Allow only one process at a time to execute a receive operation Allow the system to select arbitrarily the receiver (P 2 or P 3 not both) Sender is notified who the receiver was. 3.36 Silberschatz, Galvin and Gagne 2009

Synchronization Message passing may be either blocking or non-blocking Blocking is considered synchronous Blocking send has the sender block until the message is received by the receiving process or by the mailbox. Blocking receive has the receiver block until a message is available Non-blocking is considered asynchronous Non-blocking send has the sender send the message and continue operation. Non-blocking receive has the receiver receive either a valid message or null When Both send() and receive() are blocking, we have a rendezvous between the sender and the receiver. 3.37 Silberschatz, Galvin and Gagne 2009

Buffering Messages exchanged by processes reside in a temporary queue. Queue of messages attached to the link; implemented in one of three ways 1. Zero capacity max length of 0 messages ( cannot have any messages waiting in it). Sender must wait(blocked) for receiver (rendezvous) 2. Bounded capacity finite length of n messages Sender must wait (block) if link is full 3. Unbounded capacity infinite length Sender never waits. 3.38 Silberschatz, Galvin and Gagne 2009

End of Chapter 3, Silberschatz, Galvin and Gagne 2009