Chapter 3 Process Scheduling Bernard Chen Spring 2007.

Slides:



Advertisements
Similar presentations
Operating Systems Lecture 7.
Advertisements

©2009 Operačné systémy Procesy. 3.2 ©2009 Operačné systémy Process in Memory.
Dr. Kalpakis CMSC 421, Operating Systems. Fall Processes.
Abhinav Kamra Computer Science, Columbia University 4.1 Operating System Concepts Silberschatz, Galvin and Gagne  2002 Chapter 4: Processes Process Concept.
Adapted from slides ©2005 Silberschatz, Galvin, and Gagne Lecture 4: Processes.
Chapter 3: Processes.
Chapter 3 Processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
1/30/2004CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Chapter 3: Processes. Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
02/01/2010CSCI 315 Operating Systems Design1 Interprocess Communication Notice: The slides for this lecture have been largely based on those accompanying.
1/26/2007CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Interprocess Communication. Process Concepts Last class.
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Chap 3 Processes-Concept. Process Concept Process – a program in execution; process execution must progress in sequential fashion A process includes:
Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems.
Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server.
Silberschatz, Galvin and Gagne  Operating System Concepts Cooperating Processes Independent process cannot affect or be affected by the execution.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Process Concept Process – a program.
Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 3: Processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 3: Processes.
Schedule 2: Concurrent Serializable Schedule. Timestamp Timestamp-based Protocols Select order among transactions in advance – timestamp-ordering Transaction.
Chapter 3 Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Jan 19, 2005 Chapter 3: Processes Process Concept.
AE4B33OSS Chapter 3: Processes. 3.2Silberschatz, Galvin and Gagne ©2005AE4B33OSS Chapter 3: Processes Process Concept Process Scheduling Operations on.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 3: Processes Process Concept Process Scheduling.
3.1 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8 th Edition Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Outline n Process Concept n Process.
Chapter 3: Processes (6 th edition chap 4). 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Chapter 3: Processes. 3.2CSCI 380 Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication.
1 11/1/2015 Chapter 4: Processes l Process Concept l Process Scheduling l Operations on Processes l Cooperating Processes l Interprocess Communication.
Share Memory Program Example int array_size=1000 int global_array[array_size] main(argc, argv) { int nprocs=4; m_set_procs(nprocs); /* prepare to launch.
3.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Interprocess Communication Processes within a system may be.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Processes. Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 3: Processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 3: Processes.
CS212: OPERATING SYSTEM Lecture 2: Process 1. Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process Concept.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-4 Process Communication Department of Computer Science and Software.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 10 Processes II Read.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 3 Operating Systems.
Chapter 3: Process-Concept. Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 3: Process Concept.
3.1 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8 th Edition Chapter 3: Processes.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Jan 19, 2005 Chapter 3: Processes Process Concept.
Chapter 3: Processes-Concept. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes-Concept Overview Process Scheduling.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
 Process Concept  Process Scheduling  Operations on Processes  Cooperating Processes  Interprocess Communication  Communication in Client-Server.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server.
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Objectives To introduce the notion of a process -- a program in execution,
Chapter 3: Process-Concept. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 3: Process-Concept Process Concept Process Scheduling.
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process Termination Process executes last statement and asks the operating.
4.1 Operating System Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
CSC 360, Instructor: Kui Wu IPC. CSC 360, Instructor: Kui Wu Agenda 1.The need to communicate 2.Shared memory 3.Message passing.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
XE33OSA Chapter 3: Processes. 3.2XE33OSASilberschatz, Galvin and Gagne ©2005 Chapter 3: Processes Process Concept Process Scheduling Operations on Processes.
Chapter 4: Processes Process Concept Process Scheduling
Chapter 3: Process Concept
Chapter 4: Processes Process Concept Process Scheduling
Processes August 10, 2019 OS:Processes.
Presentation transcript:

Chapter 3 Process Scheduling Bernard Chen Spring 2007

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

Schedulers On some systems, the long-term scheduler maybe absent or minimal Just simply put every new process in memory for short-term scheduler The stability depends on physical limitation or self-adjustment nature of human users

Schedulers Sometimes it can be advantage to remove process from memory and thus decrease the degree of multiprogrammimg This scheme is called swapping

Addition of Medium Term Scheduling

Share Memory Parallelization System Example m_set_procs(number): prepare number of child for execution m_fork(function): childes execute “function” m_kill_procs(); terminate childs

Real Example main(argc, argv) { int nprocs=9; m_set_procs(nprocs); /* prepare to launch this many processes */ m_fork(slaveproc); /* fork out processes */ m_kill_procs(); /* kill activated processes */ } void slaveproc() { int id; id = m_get_myid(); m_lock(); printf(" Hello world from process %d\n",id); printf(" 2nd line: Hello world from process %d\n",id); m_unlock(); }

#include "stdio.h" #include "sys/types.h" #include "sys/times.h" #include "ulocks.h" #include "sys/param.h" #include "math.h" #define MAXTHRDS 6

Real Example int array_size=1000 int global_array[array_size] main(argc, argv) { int nprocs=4; m_set_procs(nprocs); /* prepare to launch this many processes */ m_fork(sum); /* fork out processes */ m_kill_procs(); /* kill activated processes */ } void sum() { int id; id = m_get_myid(); for (i=id*(array_size/nprocs); i<(id+1)*(array_size/nprocs); i++) global_array[id*array_size/nprocs]+=global_array[i]; }

Cooperating Processes Independentprocess cannot affect or be affected by the execution of another process Cooperatingprocess can affect or be affected by the execution of another process Advantages of process cooperation Information sharing Computation speed-up Modularity Convenience

Interprocess Cpmmunication (IPC) Two fundamental models (1) Share Memory (2) Message Passing

Communication Models (a): MPI (b): Share memory

Shared-Memory Systems Consider the producer-consumer problem A producer process produce information that is consumed by customer process, for example, a web server produces HTML files and images which are consumed by client web browser

Shared-Memory Systems The producer and consumer must be synchronized, so that consumer does not try to consume an item that has not yet been produced. Two types of buffer can be used: 1. Unbounded buffer 2. Bounded buffer

Shared-Memory Systems Unbounded Buffer: the consumer may have to wait for new items, but producer can always produce new items. Bounded Buffer: the consumer have to wait if buffer is empty, the producer have to wait if buffer is full

Bounded Buffer #define BUFFER_SIZE 6 Typedefstruct {... } item; item buffer[BUFFER_SIZE]; intin = 0; intout = 0;

Bounded Buffer (producer iew) while (true) { /* Produce an item */ while (((in = (in + 1) % BUFFER SIZE count) == out) ; /* do nothing --no free buffers */ buffer[in] = item; in = (in + 1) % BUFFER SIZE; }

Bounded Buffer (Consumer view) while (true) { while (in == out) ; // do nothing --nothing to consume // until remove an item from the buffer item = buffer[out]; out = (out + 1) % BUFFER SIZE; return item; }

Message-Passing Systems A message passing facility provides at least two operations: send(message), receive(message)

Message-Passing Systems If 2 processes want to communicate, a communication link must exist It has the following variations: 1. Direct or indirect communication 2. Synchronize or asynchronize communication 3. Automatic or explicit buffering

Message-Passing Systems Direct communication send(P, message) receive(Q, message) Properties: A link is established automatically A link is associated with exactly 2 processes Between each pair, there exists exactly one link

Message-Passing Systems Indirect communication: the messages are sent to and received from mailbox send(A, message) receive(A, message)

Message-Passing Systems Properties: A link is established only if both members of the pair have a shared mailbox A link is associated with more than 2 processes Between each pair, there exists a number of links

Message-Passing Systems Mailbox sharing P1, P2, andP3 share mailbox A P1, sends; P2 andP3 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.

Message-Passing Systems If the mailbox owned by process, it is easy to tell who is the owner and user. And there is no confuse we send the message and who receives it. When process terminates, the mailbox disappear

Message-Passing Systems If the mailbox owned by OS, it requires the following functions: Create a new mailbox Send and Receive message through the mailbox Delete a mailbox

Message-Passing Systems Synchronization: synchronous and asynchronous Blocking is considered synchronous Blocking send has the sender block until the message is received Blocking receive has the receiver block until a message is available

Message-Passing Systems Non-blockingis considered asynchronous Non-blocking send has the sender send the message and continue Non-blocking receive has the receiver receive a valid message or null

Message-Passing Systems Buffering: Queue of messages attached to the link, there are 3 variations: Zero capacity –0 messages Sender must wait for receiver 2.Bounded capacity –finite length of n messages, sender must wait if link full 3.Unbounded capacity –infinite length Sender never waits

MPI Program example #include "mpi.h" #include int main (int argc, char *argv[]) { int id; /* Process rank */ int p; /* Number of processes */ int i,j; int array_size=100; int array[array_size]; /* or *array and then use malloc or vector to increase the size */ int local_array[array_size/p]; int sum=0; MPI_Status stat; MPI_Comm_rank (MPI_COMM_WORLD, &id); MPI_Comm_size (MPI_COMM_WORLD, &p);

MPI Program example if (id==0) { for(i=0; i<array_size; i++) array[i]=i; /* initialize array*/ for(i=0; i<p; i++) MPI_Send(&array[i*array_size/p], /* Start from*/ array_size/p, /* Message size*/ MPI_INT, /* Data type*/ i, /* Send to which process*/ MPI_COMM_WORLD); } else MPI_Recv(&local_array[0],array_size/p,MPI_INT,0,0,MPI_COMM_WORLD,&stat);

MPI Program example for(i=0;i<array_size/p;i++) sum+=array[i]; MPI_Reduce (&sum, &sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); if (id==0) printf("%d ",sum); }