38
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 3: Processes

Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.1 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Chapter 3: Processes

Page 2: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.2 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Chapter 3: Processes

Process ConceptProcess SchedulingOperations on ProcessesInterprocess CommunicationExamples of IPC SystemsCommunication in Client-Server Systems

Page 3: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.4 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process Concept

An operating system executes a variety of programs:Batch system – jobsTime-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 stackdata section

Page 4: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.5 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process in Memory

Page 5: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.6 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process State

As a process executes, it changes statenew: The process is being createdrunning: Instructions are being executedwaiting: The process is waiting for some event to occurready: The process is waiting to be assigned to a processorterminated: The process has finished execution

Page 6: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.7 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Diagram of Process State

Page 7: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.8 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process Control Block (PCB)

Information associated with each process

Process stateProgram counterCPU registersCPU scheduling informationMemory-management informationAccounting informationI/O status information

Page 8: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.9 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process Control Block (PCB)

Page 9: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.10 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

CPU Switch From Process to Process

Page 10: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.11 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

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

Processes migrate among the various queues

Page 11: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.12 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Ready Queue And Various I/O Device Queues

Page 12: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.13 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Representation of Process Scheduling

Page 13: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.14 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

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

Page 14: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.16 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

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)

Page 15: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.17 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

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 via a context switch

Context of a process represented in the PCB

Context-switch time is overhead; the system does no useful work while switching

Time dependent on hardware support

Page 16: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.18 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process Creation

Parent process create children processes, which, in turn create other processes, forming a tree of processes

Generally, process identified and managed via a process identifier (pid)

Parent and children share all resourcesChildren share subset of parent’s resourcesParent and child share no resources

ExecutionParent and children execute concurrentlyParent waits until children terminate

Resource sharing: 3 possibility

Page 17: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.19 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process Creation (Cont.)

Address spaceChild duplicate of parentChild has a program loaded into it

UNIX examplesfork system call creates new processexec system call used after a fork to replace the process’ memory space with a new program

Page 18: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.20 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process Creation

Page 19: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.21 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

C Program Forking Separate Process

int main(){pid_t pid;

/* fork another process */pid = fork();if (pid < 0) { /* error occurred */

fprintf(stderr, "Fork Failed");exit(-1);

}else if (pid == 0) { /* child process */

execlp("/bin/ls", "ls", NULL);}else { /* parent process */

/* parent will wait for the child to complete */wait (NULL);printf ("Child Complete");exit(0);

}}

Page 20: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.22 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process Creation in POSIX

Page 21: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.23 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process Creation in Win32

Page 22: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.26 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Process Termination

Process executes last statement and asks the operating system todelete 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 resourcesTask assigned to child is no longer requiredIf parent is exiting

Some operating system do not allow child to continue if its parent terminates

– All children terminated - cascading termination

Page 23: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.27 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Interprocess Communication

Processes within a system may be independent or cooperatingCooperating process can affect or be affected by other processes, including sharing dataReasons for cooperating processes:

Information sharingComputation speedupModularity

Cooperating processes need interprocess communication (IPC)Two models of IPC

Shared memoryMessage passing

Page 24: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.28 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Communications Models

Page 25: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.30 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

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. The consumer may have to wait for new items,but the producer can always produce new items.

bounded-buffer assumes that there is a fixed buffer size.In this case,the consumer must wait if the buffer is empty, and the producer must wait if the buffer is full.

Page 26: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.35 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Interprocess Communication –Message Passing

Mechanism for processes to communicate and to synchronize their actionsMessage system – processes communicate with each other without resorting to shared variablesIPC 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 themexchange messages via send/receive

Page 27: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.37 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Direct Communication

Processes must name each other explicitly:send (P, message) – send a message to process Preceive(Q, message) – receive a message from process Q

Properties of communication linkLinks are established automaticallyA link is associated with exactly one pair of communicating processesBetween each pair there exists exactly one linkThe link may be unidirectional, but is usually bi-directional

Page 28: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.38 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Indirect Communication

Messages are directed and received from mailboxes (also referredto as ports)

Each mailbox has a unique idProcesses can communicate only if they share a mailbox

Properties of communication linkLink established only if processes share a common mailboxA link may be associated with many processesLink may be unidirectional or bi-directional

Page 29: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.39 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Indirect Communication

Operationscreate a new mailboxsend and receive messages through mailboxdestroy a mailbox

Primitives are defined as:send(A, message) – send a message to mailbox Areceive(A, message) – receive a message from mailbox A

Page 30: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.41 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Synchronization

Message passing may be either blocking or non-blocking

Blocking is considered synchronousBlocking send has the sender block until the message is received

Non-blocking is considered asynchronousNon-blocking send has the sender send the message and continue

Page 31: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.47 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Communications in Client-Server Systems

Sockets

Remote Procedure Call (Remote Method Invocation -RMI- in Java)

Page 32: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.48 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Sockets

A socket is defined as an endpoint for communication

Concatenation of IP address and port

The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8

Communication consists between a pair of sockets

Page 33: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.49 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Socket Communication

Page 34: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.50 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Socket Communication in Java

Page 35: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.51 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Socket Communication in Java

Page 36: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.54 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

Remote Method InvocationRemote Method Invocation (RMI) is a Java mechanism similar to RPCs

RMI allows a Java program on one machine to invoke a method on aremote object

Page 37: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.55 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

RMI registry

Page 38: Chapter 3: Processesturgaybilgin/2015-2016-guz/opsys/cen302_ch3.pdfOperating System Concepts with Java – 8 th Edition 3.18 Silberschatz, Galvin and Gagne ©2009 Process Creation

3.59 Silberschatz, Galvin and Gagne ©2009Operating System Concepts with Java – 8th Edition

End of Chapter 3