Process! Process Creation / Termination! Process Transitions in" the Two-State Process Model! A Two-State Process Model!

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

Diagram of Process State Process Control Block (PCB)

Process Description and Control. Chapter 3

The Big Picture So Far. Chapter 4: Processes

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

Chapter 4: Processes. Process Concept

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

The Big Picture So Far. Chapter 4: Processes

Chapter 4: Processes

Lecture 2 Process Management

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

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

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

Chapter 3: Processes

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

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

Chapter 4: Processes

Chapter 3: Process Concept

Chapter 4: Processes. Process Concept

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

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

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

Part Two - Process Management. Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts 9 th Edition

Today: Process Management. The Big Picture So Far. What's in a Process? Example Process State in Memory

The Big Picture So Far. Today: Process Management

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

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

ICS Principles of Operating Systems

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

Chapter 3: Process Concept

Chapter 3: Process Concept

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

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

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

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

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

Chapter 3: Processes

Processes and Threads

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

Chapter 3: Process Concept

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

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Chapter 4: Processes

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

CHAPTER 3 - PROCESS CONCEPT

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

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

Chapter 3 Process Description and Control

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

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

Processes, PCB, Context Switch

Chapter 3: Processes. Operating System Concepts 9 th Edition

CSC 539: Operating Systems Structure and Design. Spring 2006

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

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

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

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.

Chapter 3: Process Concept

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

Process Description and Control. Chapter 3

Computer Systems II. First Two Major Computer System Evolution Steps

Process Description and Control. Chapter 3

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

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

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

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

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

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

Process Description and Control

UNIX Processes. by Armin R. Mikler. 1: Introduction

Lecture 4: Process Management

Chapter 3: Processes

Chapter 4: Processes. Process Concept. Process State

Processes. Operating System Concepts 8 th Edition

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

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

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

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

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

Processes. CS3026 Operating Systems Lecture 05

Operating Systems Process description and control

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

Operating Systems. Lecture 05

IT 540 Operating Systems ECE519 Advanced Operating Systems

CSI Module 2: Processes

Course: Operating Systems Instructor: M Umair. M Umair

Chapter 3: Processes. Operating System Concepts 8th Edition

CHAPTER 2: PROCESS MANAGEMENT

CS 322 Operating Systems Practice Midterm Questions

Process Description and Control. Major Requirements of an Operating System

Major Requirements of an Operating System Process Description and Control

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

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

SMD149 - Operating Systems

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

CS5460: Operating Systems

Transcription:

Process! Process Creation / Termination!!! A process (sometimes called a task, or a job) is a program in execution"!! Process is not the same as program "!! We distinguish between a passive program stored on disk, and an actively executing process in memory"!! Multiple users can run the same program; each is a distinct process"!! The program is only part of a process; the process also contains the execution state and program data"!! List processes (Mac OS X):"!! ps " my processes, little detail"!! ps u " my processes, more detail"!! ps aux " all processes, more detail"!! Note user processes and OS processes" 1! Fall 2008, Chapter 3!!! Reasons for process creation"!! User logs on"!! User starts a program"!! OS creates process to provide a service (e.g., printer daemon to manage printer)"!! Program starts another process (e.g., Mail opens Firefox to show a web page)"!! Reasons for process termination"!! Normal completion"!! Arithmetic error, or data misuse (e.g., wrong type)"!! Invalid instruction execution"!! Insufficient memory available, or memory bounds violation"!! Resource protection error"!! I/O failure" 2! Fall 2008, Chapter 3! A Two-State Process Model!!! This process model says that either a process is, or it is not "!! State transition diagram:"!! Queuing diagram:" enter enter not queue pause pause CPU!! CPU scheduling (round-robin)"!! Queue is first-in, first-out (FIFO) list"!! CPU scheduler takes process at head of queue, runs it on CPU for one time slice, then puts it back at tail of queue " 3! Fall 2008, Chapter 3! Process Transitions in" the Two-State Process Model!!! When the OS creates a new process, it is initially placed in the not- state"!! It#s waiting for an opportunity to execute"!! At the end of each time slice, the CPU scheduler selects a new process to run"!! The previously process is paused moved from the state into the not- state (at tail of queue)"!! The new process (at head of queue) is ed moved from the not - state into the state"!! If the process completes its execution, it s, and the CPU scheduler is invoked again"!! If it doesn#t complete, but its time is up, it gets moved into the not- state anyway, and the CPU scheduler chooses a new process to execute" 4! Fall 2008, Chapter 3!

Waiting on Something to Happen! A Five-State Process Model!!! Some reasons why a process that might otherwise be needs to wait:"!! Wait for user to type the next key"!! Wait for output to appear on the screen"!! Program tried to read a file wait while OS decides which disk blocks to read, and then actually reads the requested information into memory"!! Firefox tries to follow a link (URL) wait while OS determines address, requests data, reads packets, displays requested web page"!! OS must distinguish between:"!! Processes that are ready to run and are waiting their turn for another time slice"!! Processes that are waiting for something to happen (OS operation, hardware, etc.)" 5! Fall 2008, Chapter 3!!! The not- state in the two-state model has now been split into a ready state and a blocked state"!! Running currently being executed"!! Ready prepared to execute"!! Blocked waiting for some to occur (for an I/O operation to complete, or a resource to become available, etc.)"!! New just been created"!! Exit just been terminated"!! State transition diagram:" new admit ready occurs blocked timeout wait release 6! Fall 2008, Chapter 3! State Transitions in Five-State" Process Model!!! new! ready"!! Admitted to ready queue; can now be considered by CPU scheduler"!! ready! "!! CPU scheduler chooses that process to execute next, according to some scheduling algorithm"!!! ready"!! Process has used up its current time slice"!!! blocked"!! Process is waiting for some to occur (for I/O operation to complete, etc.)"!! blocked! ready"!! Whatever the process was waiting on has occurred" 7! Fall 2008, Chapter 3! Process State!!! The process state consists of (at least):"!! Code for the program"!! Program#s static and dynamic data"!! Program#s procedure call stack"!! Contents of general purpose registers"!! Contents of Program Counter (PC)"!! Contents of Stack Pointer (SP)"!! Contents of Program Status Word (PSW) interrupt status, condition codes, etc."!! OS resources in use (e.g., memory, open files, active I/O devices)"!! Accounting information (e.g., CPU scheduling, memory management)" "!Everything necessary to resume the process# execution if it is somehow put aside temporarily" 8! Fall 2008, Chapter 3!

Process Control Block (PCB)!!! For every process, the OS maintains a Process Control Block (PCB), a data structure that represents the process and its state:"!! Process id number"!! Userid of owner"!! Memory space (static, dynamic)"!! Program Counter, Stack Pointer, general purpose registers"!! Process state (, not-, etc.)" A Five-State Process Model" (Review)!!! The not- state in the two-state model has now been split into a ready state and a blocked state"!! Running currently being executed"!! Ready prepared to execute"!! Blocked waiting for some to occur (for an I/O operation to complete, or a resource to become available, etc.)"!! New just been created"!! Exit just been terminated"!! CPU scheduling information (e.g., priority)"!! List of open files"!! I/O states, I/O in progress"!! State transition diagram:" new admit ready timeout release!! Pointers into CPU scheduler#s state queues (e.g., the waiting queue)"!! " occurs blocked wait 9! Fall 2008, Chapter 3! 10! Fall 2008, Chapter 3! UNIX Process Model! UNIX Process Model" (cont.)!!! Start in Created, go to either:"!! Ready to Run, in Memory"!! or Ready to Run, Swapped (Out) if there isn#t room in memory for the new process"!! Ready to Run, in Memory is basically same state as Preempted (dotted line)"!! Preempted means process was returning to user mode, but the kernel switched to another process instead"!! When scheduled, go to either:"!! User Running (if in user mode)" Figure from Operating Systems: Internals and Design Principles, 4thedition, Stallings, Prentice Hall, 2001" "Original diagram from The Design of the UNIX Operating System, M. Bach, Prentice Hall, 1986"!! or Kernel Running (if in kernel mode)"!! Go from U.R. to K.R. via system call"!! Go to Asleep in Memory when waiting for some, to RtRiM when it occurs" 11! Fall 2008, Chapter 3!!! Go to Sleep, Swapped if swapped out" 12! Fall 2008, Chapter 3!

Process Creation in UNIX! Example of UNIX Process Creation!!! One process can create another process, perhaps to do some work for it"!! The original process is called the parent"!! The new process is called the child"!! The child is an (almost) identical copy of parent (same code, same data, etc.)"!! The parent can either wait for the child to complete, or continue executing in parallel (concurrently) with the child"!! In UNIX, a process creates a child process using the system call fork( )"!! In child process, fork( ) returns 0"!! In parent process, fork( ) returns process id of new child" #include <sys/types.h>" #include <stdio.h>" int a = 6; " "/* global (external) variable */" int main(void)" {" int b; " "/* local variable */" pid_t pid; "/* process id */" b = 88;" printf("..before fork\n");" pid = fork();" if (pid == 0) { "/* child */" a++; b++;" } else " "/* parent */" wait(pid);" printf("..after fork, a = %d, b = %d\n", a, b);" (0);" }" aegis> fork"..before fork"..after fork, a = 7, b = 89"..after fork, a = 6, b = 88"!! Child often uses exec( ) to start another completely different program" 13! Fall 2008, Chapter 3! 14! Fall 2008, Chapter 3! Context Switching! Context Switching!!! Stopping one process and starting another is called a context switch"!! When the OS stops a process, it stores the hardware registers (PC, SP, etc.) and any other state information in that process# PCB"!! When OS is ready to execute a waiting process, it loads the hardware registers (PC, SP, etc.) with the values stored in the new process# PCB, and restores any other state information"!! Performing a context switch is a relatively expensive operation"!! However, time-sharing systems may do 100 1000 context switches a second"!! Why so often?"!! Why not more often?" 15! Fall 2008, Chapter 3! 16! Fall 2008, Chapter 3!

Schedulers! Ready Queue and" Various I/O Device Queues!!! Medium-term scheduler (demand paging)"!! On time-sharing systems, does some of what long-term scheduler used to do"!! May swap processes out of memory temporarily"!! May suspend and resume processes"!! Goal: balance load for better throughput"!! Short-term scheduler (CPU scheduler)"!! Executes frequently, about one hundred times per second (every 10ms)"!! Runs whenever:"!! Process is created or terminated"!! Process switches from to blocked"!! Interrupt occurs"!! Selects process from those that are ready to execute, allocates CPU to that process" 17! Fall 2008, Chapter 3! From Operating System Concepts, Silberschatz & Galvin., Addison-Wesley, 1994"!! OS organizes all waiting processes (their PCBs, actually) into a number of queues"!! Queue for ready processes"!! Queue for processes waiting on each device (e.g., mouse) or type of (e.g., message)" 18! Fall 2008, Chapter 3! The Producer-Consumer Problem!!! One process is a producer of information; another is a consumer of that information"!! Processes communicate through a bounded (fixed -size) circular buffer" var buffer: array[0..n-1] of items; "/* circular array */" in = 0" out = 0" n = 7 0 1 2 3 4 5 6 free free full full full free free out /* producer */ " " " "/* consumer */" repeat forever " " " "repeat forever" " " " " " " " "while (in == out)" " "produce item nextp " " " "do nothing" " " " " " " " "nextc = buffer[out]" " "while (in+1 mod n == out) " "out = out+1 mod n" " " "do nothing " " " " " " "buffer[in] = nextp " " " "consume item nextc" " "in = in+1 mod n " " " " " end repeat" " " " "end repeat" in!! Blocking send:" Message Passing using" Send & Receive!!! send(destination-process, message)"!! Sends a message to another process, then blocks (i.e., gets suspended by OS) until message is received"!! Blocking receive:"!! receive(source-process, message)"!! Blocks until a message is received (may be minutes, hours, )"!! Producer-Consumer problem:" /* producer */ " " " "/* consumer */" repeat forever " " " "repeat forever" " " " " " " " " "receive(producer,nextc)" " "produce item nextp " " " " " " " " " " " " "consume item nextc" " "send(consumer, nextp) " " " end repeat " " " " "end repeat" 19! Fall 2008, Chapter 3! 20! Fall 2008, Chapter 3!

Direct vs. Indirect Communication! Buffering!!! Direct communication explicitly name the process you#re communicating with"!! send(destination-process, message)"!! receive(source-process, message)"!! Variation: receiver may be able to use a wildcard to receive from any source"!! Receiver can not distinguish between multiple types of messages from sender"!! Indirect communication communicate using mailboxes (owned by receiver)"!! send(mailbox, message)"!! receive(mailbox, message)"!! Variation: wildcard to receive from any source into that mailbox"!! Receiver can distinguish between multiple types of messages from sender"!! Some systems use tags instead of mailboxes" 21! Fall 2008, Chapter 3!!! Link may be able to temporarily queue some messages during communication"!! Zero capacity: " (queue of length 0)"!! Blocking send operation"!! Sender must wait until receiver receives the message this synchronization to exchange data is called a rendezvous"!! Bounded capacity: (queue of length n)"!! Blocking send operation"!! If receiver#s queue is has free space, new message is put on queue, and sender can continue executing immediately"!! If queue is full, sender must block until space is available in the queue"!! Unbounded capacity: (infinite queue)"!! Non-blocking send operation"!! Sender can always continue" 22! Fall 2008, Chapter 3! Client / Server Model using" Message Passing! Remote Procedure Call (RPC)! request client reply kernel request server reply kernel!! RPC mechanism:"!! Hides message-passing I/O from the programmer"!! Looks (almost) like a procedure call but client invokes a procedure on a server"!! Client / server model"!! Server = process (or collection of processes) that provides a service"!! Example: name service, file service"!! Client process that uses the service"!! Request / reply protocol:" network!! Client sends request message to server, asking it to perform some service"!! Server performs service, sends reply message containing results or error code" 23! Fall 2008, Chapter 3!!! RPC invocation (high-level view):"!! Calling process (client) is suspended"!! Parameters of procedure are passed across network to called process (server)"!! Server executes procedure"!! Return parameters are sent back across network"!! Calling process resumes"!! Invented by Birrell & Nelson at Xerox PARC, described in February 1984 ACM Transactions on Computer Systems! 24! Fall 2008, Chapter 3!

Client / Server Model using" Remote Procedure Calls (RPCs)! Remote Method Invocation (RMI)!!! RMI mechanism:"!! A Java mechanism similar to RPCs"!! Allows a Java program on one machine to invoke a method on a remote object"!! Client stub creates a parcel, sends to skeleton on the server side!!! Each RPC invocation by a client process calls a client stub, which builds a message and sends it to a server stub"!! The server stub uses the message to generate a local procedure call to the server"!! If the local procedure call returns a value, the server stub builds a message and sends it to the client stub, which receives it and returns the result(s) to the client" 25! Fall 2008, Chapter 3! 26! Fall 2008, Chapter 3!