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

Similar documents
Lecture 2 Process Management

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

Chapter 4: Processes

Chapter 4: Processes. Process Concept

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

Diagram of Process State Process Control Block (PCB)

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

CHAPTER 2: PROCESS MANAGEMENT

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

The Big Picture So Far. Chapter 4: Processes

Part Two - Process Management. Chapter 3: Processes

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

The Big Picture So Far. Chapter 4: Processes

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

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

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

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

Chapter 4: Processes. Process Concept

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

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

Chapter 4: Processes

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

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

Chapter 3: Processes

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

Chapter 3: Processes

Chapter 3: Process Concept

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

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 4: Processes

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

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

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

Chapter 3: Processes. Operating System Concepts 8th Edition

Chapter 4: Processes. Process Concept. Process State

Chapter 3: Process Concept

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

CHAPTER 3 - PROCESS CONCEPT

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

UNIT - II PROCESS MANAGEMENT

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

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

Chapter 3: Process Concept

TDIU25: Operating Systems II. Processes, Threads and Scheduling

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

Chapter 3: Processes

Processes and Threads

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

Chapter 5: CPU Scheduling

ICS Principles of Operating Systems

CPU Scheduling Algorithms

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

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

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

So far. Next: scheduling next process from Wait to Run. 1/31/08 CSE 30341: Operating Systems Principles

CS370 Operating Systems

Chapter 6: CPU Scheduling

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

CS420: Operating Systems. Interprocess Communication

CS307 Operating Systems Processes

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

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

UNIT 2 Basic Concepts of CPU Scheduling. UNIT -02/Lecture 01

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

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

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

Chapter 5 CPU scheduling

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

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Properties of Processes

CPU Scheduling: Part I ( 5, SGG) Operating Systems. Autumn CS4023

Course: Operating Systems Instructor: M Umair. M Umair

Processes-Process Concept:

Chapter 6: CPU Scheduling

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

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

CS370 Operating Systems Midterm Review

CS370 Operating Systems

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition,

CSC 539: Operating Systems Structure and Design. Spring 2006

Operating System Concepts Ch. 5: Scheduling

LECTURE 3:CPU SCHEDULING

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

Chapter 5: CPU Scheduling

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

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

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

CS370 Operating Systems

Chapter 5: Process Scheduling

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

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

Processes and Threads

Processes. Process Concept

CPU Scheduling. Rab Nawaz Jadoon. Assistant Professor DCS. Pakistan. COMSATS, Lahore. Department of Computer Science

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Transcription:

OPERATING SYSTEMS UNIT II Sections A, B & D PREPARED BY ANIL KUMAR PRATHIPATI, ASST. PROF., DEPARTMENT OF CSE. 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 data section 1

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. ready: The process is waiting to be assigned to a process. terminated: The process has finished execution. DIAGRAM OF PROCESS STATE 2

PROCESS CONTROL BLOCK (PCB) Information associated with each process. Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information PROCESS CONTROL BLOCK (PCB) 3

CPU SWITCH FROM PROCESS TO PROCESS PROCESS SCHEDULING QUEUES 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. Process migration between the various queues. 4

READY QUEUE AND VARIOUS I/O DEVICE QUEUES REPRESENTATION OF PROCESS SCHEDULING 5

SCHEDULERS Long-term scheduler (or job scheduler) selects which processes should be brought into the ready queue. Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU. ADDITION OF MEDIUM TERM SCHEDULING 6

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. 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. CONTEXT SWITCH 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. Context-switch time is overhead; the system does no useful work while switching. Time dependent on hardware support. 7

PROCESS CREATION Parent process create children processes, which, in turn create other processes, forming a tree of processes. 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 children terminate. PROCESS CREATION (CONT.) Address space Child duplicate of parent. Child has a program loaded into it. UNIX examples fork system call creates new process exec system call used after a fork to replace the process memory space with a new program. 8

PROCESSES TREE ON A UNIX SYSTEM PROCESS TERMINATION Process executes last statement and asks the operating system to decide it (exit). Output data 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. Parent is exiting. Operating system does not allow child to continue if its parent terminates. Cascading termination. 9

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. 10

BOUNDED-BUFFER SHARED-MEMORY SOLUTION Shared data #define BUFFER_SIZE 10 typedef struct {... } item; item buffer[buffer_size]; int in = 0; int out = 0; Solution is correct, but can only use BUFFER_SIZE-1 elements BOUNDED-BUFFER PRODUCER PROCESS item nextproduced; while (1) { while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = nextproduced; in = (in + 1) % BUFFER_SIZE; } 11

BOUNDED-BUFFER CONSUMER PROCESS item nextconsumed; while (1) { while (in == out) ; /* do nothing */ nextconsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; } INTERPROCESS COMMUNICATION (IPC) 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) message size fixed or variable receive(message) If 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) 12

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? 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 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. 13

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. Link may be unidirectional or bi-directional. INDIRECT COMMUNICATION 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 14

INDIRECT COMMUNICATION 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. SYNCHRONIZATION Message passing may be either blocking or non-blocking. Blocking is considered synchronous Non-blocking is considered asynchronous send and receive primitives may be either blocking or nonblocking. 15

BUFFERING Queue of messages attached to the link; implemented in one of three ways. 1. Zero capacity 0 messages 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. THREADS: SINGLE AND MULTITHREADED PROCESSES 16

BENEFITS Responsiveness Resource Sharing Economy USER THREADS Thread management done by user-level threads library Examples - POSIX Pthreads - Mach C-threads - Solaris threads 17

KERNEL THREADS Supported by the Kernel Examples - Windows 95/98/NT/2000 - Solaris - Tru64 UNIX - BeOS - Linux MULTITHREADING MODELS Many-to-One One-to-One Many-to-Many 18

MANY-TO-ONE Many user-level threads mapped to single kernel thread. Used on systems that do not support kernel threads. MANY-TO-ONE MODEL 19

ONE-TO-ONE Each user-level thread maps to kernel thread. Examples - Windows 95/98/NT/2000 - OS/2 ONE-TO-ONE MODEL 20

MANY-TO-MANY MODEL Allows many user level threads to be mapped to many kernel threads. Allows the operating system to create a sufficient number of kernel threads. Solaris 2 Windows NT/2000 with the ThreadFiber package MANY-TO-MANY MODEL 21

CPU SCHEDULING Basic Concepts Scheduling Criteria Scheduling Algorithms BASIC CONCEPTS Maximum CPU utilization obtained with multiprogramming CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait. CPU burst distribution 22

ALTERNATING SEQUENCE OF CPU AND I/O BURSTS HISTOGRAM OF CPU-BURST TIMES 23

CPU SCHEDULER Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state. 2. Switches from running to ready state. 3. Switches from waiting to ready. 4. Terminates. Scheduling under 1 and 4 is non-preemptive. All other scheduling is preemptive. DISPATCHER Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: switching context switching to user mode jumping to the proper location in the user program to restart that program Dispatch latency time it takes for the dispatcher to stop one process and start another running. 24

SCHEDULING CRITERIA CPU utilization keep the CPU as busy as possible Throughput # of processes that complete their execution per time unit Turnaround time amount of time to execute a particular process Waiting time amount of time a process has been waiting in the ready queue Response time amount of time it takes from when a request was submitted until the first response is produced, not output (for timesharing environment) OPTIMIZATION CRITERIA Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time 25

FIRST-COME, FIRST-SERVED (FCFS) SCHEDULING Process Burst Time P 1 24 P 2 3 P 3 3 Suppose that the processes arrive in the order: P 1, P 2, P 3 The Gantt Chart for the schedule is: P 1 P 2 P 3 0 24 27 30 Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 FCFS SCHEDULING (CONT.) Suppose that the processes arrive in the order The Gantt chart for the schedule is: P 2, P 3, P 1. P 2 P 3 P 1 0 Waiting time for P 1 = 6; P 2 = 0 ; P 3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case. 3 6 30 Convoy effect short process behind long process 26

SHORTEST-JOB-FIRST (SJR) SCHEDULING Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. Two schemes: nonpreemptive once CPU given to the process it cannot be preempted until completes its CPU burst. preemptive if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF). SJF is optimal gives minimum average waiting time for a given set of processes. EXAMPLE OF NON-PREEMPTIVE SJF Process Arrival Time Burst Time P 1 0.0 7 P 2 2.0 4 P 3 4.0 1 P 4 5.0 4 SJF (non-preemptive) P 1 P 3 P 2 P 4 0 3 7 8 12 16 Average waiting time = (0 + 6 + 3 + 7)/4-4 27

EXAMPLE OF PREEMPTIVE SJF Process Arrival Time Burst Time P 1 0.0 7 P 2 2.0 4 P 3 4.0 1 P 4 5.0 4 SJF (preemptive) P 1 P 2 P 3 P 2 P 4 P 1 0 2 4 5 7 11 16 Average waiting time = (9 + 1 + 0 +2)/4-3 DETERMINING LENGTH OF NEXT CPU BURST Can only estimate the length. Can be done by using the length of previous CPU bursts, using exponential averaging. 1. t n actual lenght of n 2. n 1 th CPU burst predicted value for the next CPU burst 3., 0 1 4. Define : n 1 tn 1. n 28

PREDICTION OF THE LENGTH OF THE NEXT CPU BURST EXAMPLES OF EXPONENTIAL AVERAGING =0 n+1 = n Recent history does not count. =1 n+1 = t n Only the actual last CPU burst counts. If we expand the formula, we get: n+1 = t n +(1 - ) t n -1 + +(1 - ) j t n -1 + +(1 - ) n=1 t n 0 Since both and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor. 29

PRIORITY SCHEDULING A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer highest priority). Preemptive nonpreemptive SJF is a priority scheduling where priority is the predicted next CPU burst time. Problem Starvation low priority processes may never execute. Solution Aging as time progresses increase the priority of the process. ROUND ROBIN (RR) Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. Performance q large FIFO q small q must be large with respect to context switch, otherwise overhead is too high. 30