Download presentation
Presentation is loading. Please wait.
Published byPiers Gregory Hall Modified over 9 years ago
1
1 11/1/2015 Chapter 4: Processes l Process Concept l Process Scheduling l Operations on Processes l Cooperating Processes l Interprocess Communication l Communication in Client-Server Systems
2
2 11/1/2015 Process Concept l An operating system executes a variety of programs: Batch system – jobs Time-shared systems – user programs or tasks l Textbook uses the terms job and process almost interchangeably. Process – a program in execution; process execution must progress in sequential fashion. l A process includes: n program counter n stack n data section
3
3 11/1/2015 Process State l As a process executes, it changes state n new: The process is being created. n running: Instructions are being executed. n waiting: The process is waiting for some event to occur. n ready: The process is waiting to be assigned to a process. n terminated: The process has finished execution.
4
4 11/1/2015 Diagram of Process State
5
5 11/1/2015 Process Control Block (PCB) Information associated with each process. l Process state l Program counter l CPU registers l CPU scheduling information l Memory-management information l Accounting information l I/O status information
6
6 11/1/2015 Process Control Block (PCB)
7
7 11/1/2015 CPU Switch From Process to Process
8
8 11/1/2015 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. l Process migration between the various queues.
9
9 11/1/2015 Ready Queue And Various I/O Device Queues
10
10 11/1/2015 Representation of Process Scheduling
11
11 11/1/2015 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.
12
12 11/1/2015 Addition of Medium Term Scheduling
13
13 11/1/2015 Schedulers (Cont.) l Short-term scheduler is invoked very frequently (milliseconds) (must be fast). l Long-term scheduler is invoked very infrequently (seconds, minutes) (may be slow). l The long-term scheduler controls the degree of multiprogramming. l 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.
14
14 11/1/2015 Context Switch l 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. l Context-switch time is overhead; the system does no useful work while switching. l Time dependent on hardware support.
15
15 11/1/2015 Process Creation l Parent process create children processes, which, in turn create other processes, forming a tree of processes. l Resource sharing n Parent and children share all resources. Children share subset of parent ’ s resources. n Parent and child share no resources. l Execution n Parent and children execute concurrently. n Parent waits until children terminate.
16
16 11/1/2015 Process Creation (Cont.) l Address space n Child duplicate of parent. n Child has a program loaded into it. l UNIX examples n fork system call creates new process exec system call used after a fork to replace the process ’ memory space with a new program.
17
17 11/1/2015 Processes Tree on a UNIX System
18
18 11/1/2015 Process Termination l Process executes last statement and asks the operating system to decide it (exit). n Output data from child to parent (via wait). Process ’ resources are deallocated by operating system. l Parent may terminate execution of children processes (abort). n Child has exceeded allocated resources. n Task assigned to child is no longer required. n Parent is exiting. u Operating system does not allow child to continue if its parent terminates. u Cascading termination.
19
19 11/1/2015 Cooperating Processes l Independent process cannot affect or be affected by the execution of another process. l Cooperating process can affect or be affected by the execution of another process l Advantages of process cooperation n Information sharing n Computation speed-up n Modularity n Convenience
20
20 11/1/2015 Producer-Consumer Problem l Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process. n unbounded-buffer places no practical limit on the size of the buffer. n bounded-buffer assumes that there is a fixed buffer size.
21
21 11/1/2015 Bounded-Buffer – Shared-Memory Solution l Shared data #define BUFFER_SIZE 10 Typedef struct {... } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; l Solution is correct, but can only use BUFFER_SIZE- 1 elements
22
22 11/1/2015 Bounded-Buffer – Producer Process item nextProduced; while (1) { while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; }
23
23 11/1/2015 Bounded-Buffer – Consumer Process item nextConsumed; while (1) { while (in == out) ; /* do nothing */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; }
24
24 11/1/2015 Interprocess Communication (IPC) l Mechanism for processes to communicate and to synchronize their actions. Message system – processes communicate with each other without resorting to shared variables. l IPC facility provides two operations: send(message) – message size fixed or variable n receive(message) l If P and Q wish to communicate, they need to: n establish a communication link between them n exchange messages via send/receive l Implementation of communication link n physical (e.g., shared memory, hardware bus) n logical (e.g., logical properties)
25
25 11/1/2015 Implementation Questions l How are links established? l Can a link be associated with more than two processes? l How many links can there be between every pair of communicating processes? l What is the capacity of a link? l Is the size of a message that the link can accommodate fixed or variable? l Is a link unidirectional or bi-directional?
26
26 11/1/2015 Direct Communication l Processes must name each other explicitly: send (P, message) – send a message to process P receive(Q, message) – receive a message from process Q l Properties of communication link n Links are established automatically. n A link is associated with exactly one pair of communicating processes. n Between each pair there exists exactly one link. n The link may be unidirectional, but is usually bi- directional.
27
27 11/1/2015 Indirect Communication l Messages are directed and received from mailboxes (also referred to as ports). n Each mailbox has a unique id. n Processes can communicate only if they share a mailbox. l Properties of communication link n Link established only if processes share a common mailbox n A link may be associated with many processes. n Each pair of processes may share several communication links. n Link may be unidirectional or bi-directional.
28
28 11/1/2015 Indirect Communication l Operations n create a new mailbox n send and receive messages through mailbox n destroy a mailbox l Primitives are defined as: send(A, message) – send a message to mailbox A receive(A, message) – receive a message from mailbox A
29
29 11/1/2015 Indirect Communication l Mailbox sharing n P 1, P 2, and P 3 share mailbox A. n P 1, sends; P 2 and P 3 receive. n Who gets the message? l Solutions n Allow a link to be associated with at most two processes. n Allow only one process at a time to execute a receive operation. n Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was.
30
30 11/1/2015 Synchronization l Message passing may be either blocking or non-blocking. l Blocking is considered synchronous l Non-blocking is considered asynchronous l send and receive primitives may be either blocking or non- blocking.
31
31 11/1/2015 Buffering l 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.
32
32 11/1/2015 Client-Server Communication l Sockets l Remote Procedure Calls l Remote Method Invocation (Java)
33
33 11/1/2015 Sockets l A socket is defined as an endpoint for communication. l Concatenation of IP address and port l The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8 l Communication consists between a pair of sockets.
34
34 11/1/2015 Socket Communication
35
35 11/1/2015 Remote Procedure Calls l Remote procedure call (RPC) abstracts procedure calls between processes on networked systems. Stubs – client-side proxy for the actual procedure on the server. l The client-side stub locates the server and marshalls the parameters. l The server-side stub receives this message, unpacks the marshalled parameters, and peforms the procedure on the server.
36
36 11/1/2015 Execution of RPC
37
37 11/1/2015 Remote Method Invocation l Remote Method Invocation (RMI) is a Java mechanism similar to RPCs. l RMI allows a Java program on one machine to invoke a method on a remote object.
38
38 11/1/2015 Marshalling Parameters
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.