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

Similar documents
Chapter 3: Processes

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

CHAPTER 3 - PROCESS CONCEPT

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

Chapter 4: Processes

Chapter 3: Processes. Operating System Concepts 9 th Edition

Chapter 4: Processes. Process Concept

Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts 9 th Edition

Diagram of Process State Process Control Block (PCB)

Chapter 3: Process Concept

Chapter 3: Process Concept

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

Chapter 3: Process Concept

Chapter 3: Process Concept

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 9 th Edit9on

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

The Big Picture So Far. Chapter 4: Processes

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

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

The Big Picture So Far. Chapter 4: Processes

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

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

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 3: Processes. Operating System Concepts Essentials 8 th Edition

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

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

Chapter 4: Processes. Process Concept

CS370 Operating Systems

Chapter 4: Processes

Chapter 3: Processes

Lecture 2 Process Management

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

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

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

Operating System Design

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

Chapter 3: Process Concept

Chapter 4: Processes. Process Concept. Process State

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

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

Chapter 4: Processes

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

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

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

Chapter 3: Processes. Operating System Concepts 8th Edition

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Course: Operating Systems Instructor: M Umair. M Umair

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

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

CS307 Operating Systems Processes

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

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

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

CS420: Operating Systems. Interprocess Communication

CS370 Operating Systems

UNIT - II PROCESS MANAGEMENT

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

Processes and Threads

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

TDIU25: Operating Systems II. Processes, Threads and Scheduling

ICS Principles of Operating Systems

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

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

CSC 539: Operating Systems Structure and Design. Spring 2006

CHAPTER 2: PROCESS MANAGEMENT

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

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

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

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

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

Chap 4, 5: Process. Dongkun Shin, SKKU

CSI Module 2: Processes

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

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

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

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

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

Chapter 3: Processes

Processes. Process Concept

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

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

Operating System Concepts Ch. 3: Processes

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

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

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

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

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

Announcements. Operating Systems. Autumn CS4023

CS370 Operating Systems Midterm Review

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

Processes. Operating System Concepts 8 th Edition

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

Killing Zombies, Working, Sleeping, and Spawning Children

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Processes. Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra

Transcription:

Process Concept Chapter 3 Processes Computers can do several activities at a time Executing user programs, reading from disks writing to a printer, etc. In multiprogramming: CPU switches from program to program. CPU still runs only one program at a time but gives an illusion of parallelism, called pseudo parallelism or virtual CPU 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 Concept Process Concept (Cont.) File A passive entity, A named sequence of bytes Process a program in execution; process execution must progress in sequential fashion An active entity Needs certain resources such as CPU, memory, I/O Resources are allocated either at the beginning or during execution on demand. At any given point in time, System consists of: System processes which execute systems code and the User processes that execute user code and all of them exist concurrently. An OS is responsible for following process related activities Process creating and deletion Scheduling processes Provisions of mechanisms for synchronization, communication and deadlock handling. Traditionally a process contained a single thread of controls but most modern OS now supports processes with multiple threads Process Concept (Cont.) A process includes: A program counter (PC) CPU registers: for data manipulation Stack: for function parameters, return address, etc. Data section: for global variables Heap: for dynamic allocation of memory during run time. Two processes may be associated with same program and are considered two execution instances they have separate of PC, stack, heap, etc. even though the text section (i.e., code is same). Example: several users running mail program Process Concept (Cont.) Conceptually, each process has its own virtual CPU but in reality, there is only one CPU, shared by all processes. Assume that there are 4 programs in memory Abstract View: each process has its own CPU, running independently Over period of time, all processes have made progress but in reality, at any given point in time, only one process is active. 1

Process Concept (Cont.) Process State As a process executes, it changes state Important: with switching back and forth, Rate at which a process performs computation may not be uniform. Probably the time may not be reproducible even if same processes are run again. Therefore, no assumption should be made about built-in timings. Generally, most processes are not affected by underlying multiprogramming of CPU or relative speed of other processes new: The process is being created running: Instructions are being executed waiting: The process is waiting for some event to occur (I/O completion or reception of a signal ready: The process is waiting to be assigned to a processor terminated: The process has finished execution Process Control Block (PCB) CPU Switch From Process to Process Information associated with each process (also called process/task control block or PCB) Process state running, waiting, etc. Program counter location of instruction to next execute CPU registers contents of all process-centric registers CPU scheduling information- priorities, scheduling queue pointers Memory-management information memory allocated to the process Accounting information CPU used, clock time elapsed since start, time limits I/O status information I/O devices allocated to process, list of open files Pointer - point to the PCB of another process in the list Threads Process Scheduling So far, process has a single thread of execution Consider having multiple program counters per process Multiple locations can execute at once Multiple threads of control -> threads Must then have storage for thread details, multiple program counters in PCB Will talk more about it in next chapter Uni-process system: No problem since there is only one process Multi-process system: Process waits until CPU is free (either because of I/O or time quantum expiration)maximize CPU use, quickly switch processes onto CPU for time sharing Process scheduler selects among available processes for next execution on CPU Maintains scheduling queues of processes 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 During its life, a processes migrate among various queues 2

Ready Queue And Various I/O Device Queues Representation of Process Scheduling Queueing diagram represents queues, resources and flows Rectangles: Queue Circles: Resources that serve queues Schedulers Addition of Medium Term Scheduling Short-term scheduler (or CPU scheduler or dispatcher) selects which process should be executed next and allocates CPU Sometimes the only scheduler in a system Short-term scheduler is invoked frequently (milliseconds) (must be fast) Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue Long-term scheduler is invoked infrequently (seconds, minutes) (may be slow) The long-term scheduler controls the degree of multiprogramming 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 Long-term scheduler strives for good process mix Medium-term scheduler can be added if degree of multiple programming needs to decrease Remove process from memory, store on disk, bring back in from disk to continue execution: swapping Advantage: may improve job mix, free up limited memory Scheduling (contd.) Multitasking in Mobile Systems When does a scheduler executes? 1. a process switches from running to waiting select new process for CPU 2. a process terminates select new process for CPU 3. a process switches from running to ready select new process for CPU 4. a process switches from waiting to ready 5. a new process Some mobile systems (e.g., early version of ios) allow only one process to run, others suspended Due to screen real estate, user interface limits ios provides for a Foreground: A single process - controlled via user interface Background: multiple processes in memory, running, but not on the display, and with limits Limits include single, short task, receiving notification of events, specific long-running tasks like audio playback Android runs foreground and background, with fewer limits Background process uses a service to perform tasks Service can keep running even if background process is suspended Service has no user interface, small memory use 3

Context Switch Operations on Processes 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 via a context switch Context of a process is represented in the PCB Context-switch time is a pure overhead; CPU is busy switching between processes, not doing any real work leads to bottle neck The more complex the OS and the PCB the longer the context switch Time is dependent on hardware support Some hardware provides multiple sets of registers per CPU multiple contexts loaded at once System must provide mechanisms for: process creation, process execution process termination, Process Creation A Tree of Processes in Linux During execution, a process may create several new processes, via a create-process system call. The creating process is called a Parent process, the new processes are called the children of that process. Each of these new processes may in turn create other processes, forming a tree of processes In most OS including UNIX and Windows family, Processes are identified by a unique id, called Process ID (PID). Process Creation (Cont.) Every process needs resources (e.g., files, pointer, memory, CPU time, etc.). 3 possible scenarios 1. Parent and children share all resources 2. Children share only a subset of parent s resources 3. Parent and children share no resources. In this case, a child process may ask for its own resources from OS It can get only a subset of the parent's resources. Why? Prevents processes from overloading system Process Creation (Cont.) UNIX examples A new process is created using fork() system call Parent and child share same address space Both continue after fork() system call. A return code: fork() == 0 for child and 1 for parent. execv() system call is used by one of the two processes to replace the process's memory space with a new program. 4

Process Execution Process Termination Execution: 2 possibilities 1. Parent continues to execute concurrently with its children 2. Parent waits until some or all of its children are terminated Process can termination either normally or abnormally How a process can terminate? 1. By itself A process terminates itself after execution of last statement by asking OS to delete it by using the exit() system call. Resources are de-allocated. 2. A parent can terminate a child process (via abort() system call) 3. WHY? A child has exceeded its usage of some of the resources allocated to it The task assigned to child is no longer required The parent is exiting and the OS doesn't allow a child to continue if its parent terminates (e.g., VMS) Cascaded termination: All children, grandchildren, etc. are terminated. The termination is initiated by the operating system. Process Termination (contd.) Multiprocess Architecture Chrome Browser 3. The parent process may wait for termination of a child process by using the wait()system call. The call returns status information and the pid of the terminated process pid = wait(&status); If a process is terminating and its parent is not waiting for its termination (i.e., did not invoke wait()yet) process is called a zombie UNIX All processes transition to this state when they terminate but generally they exist as zombies ONLY briefly If parent terminated without invoking wait(), process is an orphan Child terminates by exit() system call wait() returns the process identifier of the child process so parent can identify its child If parent terminates, children are assigned a new parent the init process. Many web browsers use to run as single process (some still do) If one web site causes trouble, entire browser can hang or crash Google Chrome Browser is multi-process with 3 different types of processes: Browser process manages user interface, disk and network I/O Renderer process renders web pages, deals with HTML, JavaScript. A new renderer is created for each website opened Runs in sandbox, restricting disk and network I/O, minimizing effect of security exploits Plug-in process for each type of plug-in Interprocess Communication Interprocess Communication Will talk about it when we start chapter on Process Synchronization (Chapter 5) Processes within a system may be independent or cooperating Cooperating process can affect or be affected by other processes, including sharing data Reasons for cooperating processes: Information sharing Computation speedup Modularity Convenience Cooperating processes need interprocess communication (IPC) Two models of IPC Shared memory Message passing 5

Communications Models (a) Message passing. (b) shared memory. Cooperating Processes Independent process cannot affect or be affected by the execution of another process Cooperating process can affect or be affected by the execution of another process Advantages of process cooperation Information sharing Computation speed-up Modularity Convenience Producer-Consumer Problem Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process unbounded-buffer places no practical limit on the size of the buffer bounded-buffer assumes that there is a fixed buffer size Bounded-Buffer Shared-Memory Solution Shared data #define BUFFER_SIZE 10 typedef struct {... } item; item buffer[buffer_size]; int in = 0; int out = 0; Bounded-Buffer Producer/Consumer Code Producer code item next_produced; while (true) { /* produce an item in next produced */ while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = next_produced; in = (in + 1) % BUFFER_SIZE; } Consumer code item next_consumed; while (true) { while (in == out) ; /* do nothing */ next_consumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; /* consume the item in next consumed */ } Solution is correct, but can only use BUFFER_SIZE-1 elements Interprocess Communication Shared Memory Interprocess Communication Message Passing An area of memory shared among the processes that wish to communicate The communication is under the control of the users processes not the operating system. Major issues is to provide mechanism that will allow the user processes to synchronize their actions when they access shared memory. Synchronization is discussed in great details in Chapter 5. Mechanism for processes to communicate and to synchronize their actions Message system processes communicate with each other without resorting to shared variables IPC facility provides two operations: send(message) receive(message) The message size is either fixed or variable 6

Message Passing (Cont.) Message Passing (Cont.) If processes P and Q wish to communicate, they need to: Establish a communication link between them Exchange messages via send/receive Implementation issues: 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? Implementation of communication link Physical: Shared memory Hardware bus Network Logical: Direct or indirect Synchronous or asynchronous Automatic or explicit buffering Direct Communication Indirect 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 Properties of communication link Links are established automatically 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 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 Link may be unidirectional or bi-directional Indirect Communication Indirect Communication Operations create a new mailbox (port) 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 Mailbox sharing P 1, P 2, and P 3 share mailbox A P 1, sends; P 2 and P 3 receive 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. Sender is notified who the receiver was. 7

Synchronization Message passing may be either blocking or non-blocking Blocking is considered synchronous Blocking send -- the sender is blocked until the message is received Blocking receive -- the receiver is blocked until a message is available Non-blocking is considered asynchronous Non-blocking send -- the sender sends the message and continue Non-blocking receive -- the receiver receives: A valid message, or Null message Different combinations possible If both send and receive are blocking, we have a rendezvous Synchronization (Cont.) Producer-consumer becomes trivial Produce code message next_produced; while (true) { /* produce an item in next produced */ send(next_produced); } Produce code message next_consumed; while (true) { receive(next_consumed); /* consume the item in next consumed */ } Buffering Queue of messages attached to the link. implemented in one of three ways 1. Zero capacity no messages are queued on a link. Sender must wait for receiver (rendezvous) 2. Bounded capacity finite length of n messages Sender must wait if link full 3. Unbounded capacity infinite length Sender never waits 8