Slides For Operating System Concepts By Silberschatz Galvin And Gagne
1. Slides for Operating System Concepts,
By Silberschatz, Galvin, and Gagne
http://www.wiley.com/college/silberschatz
Chapter 4: Processes Process Concept
n An operating system executes a variety of programs:
n Process Concept F Batch system – jobs
n Process Scheduling F Time-shared systems – user programs or tasks
n Operations on Processes n Textbook uses the terms job and process almost
n Cooperating Processes interchangeably.
n Interprocess Communication n Process – a program in execution; process execution
n Communication in Client-Server Systems must progress in sequential fashion.
n A process includes:
F program counter
F stack
F data section
Operating System Concepts 4.1 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.2 Silberschatz, Galvin and Gagne ”2002
Process State Diagram of Process State
n As a process executes, it changes state
F new: The process is being created.
F running: Instructions are being executed.
F waiting: The process is waiting for some event to occur.
F ready: The process is waiting to be assigned to a process.
F terminated: The process has finished execution.
Operating System Concepts 4.3 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.4 Silberschatz, Galvin and Gagne ”2002
Process Control Block (PCB) Process Control Block (PCB)
Information associated with each process.
n Process state
n Program counter
n CPU registers
n CPU scheduling information
n Memory-management information
n Accounting information
n I/O status information
Operating System Concepts 4.5 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.6 Silberschatz, Galvin and Gagne ”2002
2. Slides for Operating System Concepts,
By Silberschatz, Galvin, and Gagne
http://www.wiley.com/college/silberschatz
CPU Switch From Process to Process Process Scheduling Queues
n Job queue – set of all processes in the system.
n Ready queue – set of all processes residing in main
memory, ready and waiting to execute.
n Device queues – set of processes waiting for an I/O
device.
n Process migration between the various queues.
Operating System Concepts 4.7 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.8 Silberschatz, Galvin and Gagne ”2002
Ready Queue And Various I/O Device Queues Schedulers
n Long-term scheduler (or job scheduler) – selects which
processes should be brought into the ready queue.
n Short-term scheduler (or CPU scheduler) – selects which
process should be executed next and allocates CPU.
Operating System Concepts 4.9 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.10 Silberschatz, Galvin and Gagne ”2002
Schedulers (Cont.) Context Switch
n Short-term scheduler is invoked very frequently n When CPU switches to another process, the system must
(milliseconds) fi (must be fast). save the state of the old process and load the saved state
n Long-term scheduler is invoked very infrequently for the new process.
(seconds, minutes) fi (may be slow). n Context-switch time is overhead; the system does no
n The long-term scheduler controls the degree of useful work while switching.
multiprogramming. n Time dependent on hardware support.
n Processes can be described as either:
F I/O-bound process – spends more time doing I/O than
computations, many short CPU bursts.
F CPU-bound process – spends more time doing
computations; few very long CPU bursts.
Operating System Concepts 4.11 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.12 Silberschatz, Galvin and Gagne ”2002
3. Slides for Operating System Concepts,
By Silberschatz, Galvin, and Gagne
http://www.wiley.com/college/silberschatz
Process Creation Process Creation (Cont.)
n Parent process create children processes, which, in turn n Address space
create other processes, forming a tree of processes. F Child duplicate of parent.
n Resource sharing F Child has a program loaded into it.
F Parent and children share all resources. n UNIX examples
F Children share subset of parent’s resources. F fork system call creates new process
F Parent and child share no resources. F exec system call used after a fork to replace the process’
n Execution memory space with a new program.
F Parent and children execute concurrently.
F Parent waits until children terminate.
Operating System Concepts 4.13 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.14 Silberschatz, Galvin and Gagne ”2002
Processes Tree on a UNIX System Process Termination
n Process executes last statement and asks the operating
system to decide it (exit).
F Output data from child to parent (via wait).
F Process’ resources are deallocated by operating system.
n Parent may terminate execution of children processes
(abort).
F Child has exceeded allocated resources.
F Task assigned to child is no longer required.
F Parent is exiting.
4 Operating system does not allow child to continue if its
parent terminates.
4 Cascading termination.
Operating System Concepts 4.15 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.16 Silberschatz, Galvin and Gagne ”2002
Cooperating Processes Producer-Consumer Problem
n Independent process cannot affect or be affected by the n Paradigm for cooperating processes, producer process
execution of another process. produces information that is consumed by a consumer
n Cooperating process can affect or be affected by the process.
execution of another process F unbounded-buffer places no practical limit on the size of the
buffer.
n Advantages of process cooperation
F bounded-buffer assumes that there is a fixed buffer size.
F Information sharing
F Computation speed-up
F Modularity
F Convenience
Operating System Concepts 4.17 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.18 Silberschatz, Galvin and Gagne ”2002
4. Slides for Operating System Concepts,
By Silberschatz, Galvin, and Gagne
http://www.wiley.com/college/silberschatz
Bounded-Buffer – Shared-Memory Solution Bounded-Buffer – Producer Process
n Shared data
#define BUFFER_SIZE 10
Typedef struct { item nextProduced;
...
} item; while (1) {
item buffer[BUFFER_SIZE]; while (((in + 1) % BUFFER_SIZE) == out)
int in = 0; ; /* do nothing */
int out = 0; buffer[in] = nextProduced;
n Solution is correct, but can only use BUFFER_SIZE-1 in = (in + 1) % BUFFER_SIZE;
elements }
Operating System Concepts 4.19 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.20 Silberschatz, Galvin and Gagne ”2002
Bounded-Buffer – Consumer Process Interprocess Communication (IPC)
n Mechanism for processes to communicate and to
item nextConsumed; synchronize their actions.
n Message system – processes communicate with each
while (1) { other without resorting to shared variables.
while (in == out) n IPC facility provides two operations:
; /* do nothing */ F send(message) – message size fixed or variable
nextConsumed = buffer[out]; F receive(message)
out = (out + 1) % BUFFER_SIZE;
n If P and Q wish to communicate, they need to:
}
F establish a communication link between them
F exchange messages via send/receive
n Implementation of communication link
F physical (e.g., shared memory, hardware bus)
F logical (e.g., logical properties)
Operating System Concepts 4.21 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.22 Silberschatz, Galvin and Gagne ”2002
Implementation Questions Direct Communication
n How are links established? n Processes must name each other explicitly:
n Can a link be associated with more than two processes? F send (P, message) – send a message to process P
n How many links can there be between every pair of F receive(Q, message) – receive a message from process Q
communicating processes? n Properties of communication link
n What is the capacity of a link? F Links are established automatically.
n Is the size of a message that the link can accommodate F A link is associated with exactly one pair of communicating
fixed or variable? processes.
F Between each pair there exists exactly one link.
n Is a link unidirectional or bi-directional?
F The link may be unidirectional, but is usually bi-directional.
Operating System Concepts 4.23 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.24 Silberschatz, Galvin and Gagne ”2002
5. Slides for Operating System Concepts,
By Silberschatz, Galvin, and Gagne
http://www.wiley.com/college/silberschatz
Indirect Communication Indirect Communication
n Messages are directed and received from mailboxes
(also referred to as ports). n Operations
F Each mailbox has a unique id. F create a new mailbox
F Processes can communicate only if they share a mailbox. F send and receive messages through mailbox
n Properties of communication link F destroy a mailbox
F Link established only if processes share a common mailbox n Primitives are defined as:
F A link may be associated with many processes. send(A, message) – send a message to mailbox A
F Each pair of processes may share several communication receive(A, message) – receive a message from mailbox A
links.
F Link may be unidirectional or bi-directional.
Operating System Concepts 4.25 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.26 Silberschatz, Galvin and Gagne ”2002
Indirect Communication Synchronization
n Mailbox sharing n Message passing may be either blocking or non-blocking.
F P1 , P2 , and P3 share mailbox A. n Blocking is considered synchronous
F P1 , sends; P2 and P3 receive. n Non-blocking is considered asynchronous
F Who gets the message? n send and receive primitives may be either blocking or
n Solutions non-blocking.
F Allow a link to be associated with at most two processes.
F Allow only one process at a time to execute a receive
operation.
F Allow the system to select arbitrarily the receiver. Sender is
notified who the receiver was.
Operating System Concepts 4.27 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.28 Silberschatz, Galvin and Gagne ”2002
Buffering Client-Server Communication
n Queue of messages attached to the link; implemented in n Sockets
one of three ways. n Remote Procedure Calls
1. Zero capacity – 0 messages n Remote Method Invocation (Java)
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.
Operating System Concepts 4.29 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.30 Silberschatz, Galvin and Gagne ”2002
6. Slides for Operating System Concepts,
By Silberschatz, Galvin, and Gagne
http://www.wiley.com/college/silberschatz
Sockets Socket Communication
n A socket is defined as an endpoint for communication.
n Concatenation of IP address and port
n The socket 161.25.19.8:1625 refers to port 1625 on host
161.25.19.8
n Communication consists between a pair of sockets.
Operating System Concepts 4.31 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.32 Silberschatz, Galvin and Gagne ”2002
Remote Procedure Calls Remote Method Invocation
n Remote procedure call (RPC) abstracts procedure calls n Remote Method Invocation (RMI) is a Java mechanism
between processes on networked systems. similar to RPCs.
n Stubs – client-side proxy for the actual procedure on the n RMI allows a Java program on one machine to invoke a
server. method on a remote object.
n The client-side stub locates the server and marshalls the
parameters.
n The server-side stub receives this message, unpacks the
marshalled parameters, and peforms the procedure on
the server.
Operating System Concepts 4.33 Silberschatz, Galvin and Gagne ”2002 Operating System Concepts 4.34 Silberschatz, Galvin and Gagne ”2002
Marshalling Parameters
Operating System Concepts 4.35 Silberschatz, Galvin and Gagne ”2002