ch4
38 pág.

ch4


DisciplinaSistemas Operacionais I8.353 materiais171.763 seguidores
Pré-visualização2 páginas
Silberschatz, Galvin and Gagne \uf6d920024.1Operating System Concepts
Chapter 4: Processes
\ufffd Process Concept
\ufffd Process Scheduling
\ufffd Operations on Processes
\ufffd Cooperating Processes
\ufffd Interprocess Communication
\ufffd Communication in Client-Server Systems
Silberschatz, Galvin and Gagne \uf6d920024.2Operating System Concepts
Process Concept
\ufffd An operating system executes a variety of programs:
\u2726 Batch system \u2013 jobs
\u2726 Time-shared systems \u2013 user programs or tasks
\ufffd Textbook uses the terms job and process almost
interchangeably.
\ufffd Process \u2013 a program in execution; process execution
must progress in sequential fashion.
\ufffd A process includes:
\u2726 program counter
\u2726 stack
\u2726 data section
Silberschatz, Galvin and Gagne \uf6d920024.3Operating System Concepts
Process State
\ufffd As a process executes, it changes state
\u2726 new: The process is being created.
\u2726 running: Instructions are being executed.
\u2726 waiting: The process is waiting for some event to occur.
\u2726 ready: The process is waiting to be assigned to a process.
\u2726 terminated: The process has finished execution.
Silberschatz, Galvin and Gagne \uf6d920024.4Operating System Concepts
Diagram of Process State
Silberschatz, Galvin and Gagne \uf6d920024.5Operating System Concepts
Process Control Block (PCB)
Information associated with each process.
\ufffd Process state
\ufffd Program counter
\ufffd CPU registers
\ufffd CPU scheduling information
\ufffd Memory-management information
\ufffd Accounting information
\ufffd I/O status information
Silberschatz, Galvin and Gagne \uf6d920024.6Operating System Concepts
Process Control Block (PCB)
Silberschatz, Galvin and Gagne \uf6d920024.7Operating System Concepts
CPU Switch From Process to Process
Silberschatz, Galvin and Gagne \uf6d920024.8Operating System Concepts
Process Scheduling Queues
\ufffd Job queue \u2013 set of all processes in the system.
\ufffd Ready queue \u2013 set of all processes residing in main
memory, ready and waiting to execute.
\ufffd Device queues \u2013 set of processes waiting for an I/O
device.
\ufffd Process migration between the various queues.
Silberschatz, Galvin and Gagne \uf6d920024.9Operating System Concepts
Ready Queue And Various I/O Device Queues
Silberschatz, Galvin and Gagne \uf6d920024.10Operating System Concepts
Representation of Process Scheduling
Silberschatz, Galvin and Gagne \uf6d920024.11Operating System Concepts
Schedulers
\ufffd Long-term scheduler (or job scheduler) \u2013 selects which
processes should be brought into the ready queue.
\ufffd Short-term scheduler (or CPU scheduler) \u2013 selects which
process should be executed next and allocates CPU.
Silberschatz, Galvin and Gagne \uf6d920024.12Operating System Concepts
Addition of Medium Term Scheduling
Silberschatz, Galvin and Gagne \uf6d920024.13Operating System Concepts
Schedulers (Cont.)
\ufffd Short-term scheduler is invoked very frequently
(milliseconds) \ufffd (must be fast).
\ufffd Long-term scheduler is invoked very infrequently
(seconds, minutes) \ufffd (may be slow).
\ufffd The long-term scheduler controls the degree of
multiprogramming.
\ufffd Processes can be described as either:
\u2726 I/O-bound process \u2013 spends more time doing I/O than
computations, many short CPU bursts.
\u2726 CPU-bound process \u2013 spends more time doing
computations; few very long CPU bursts.
Silberschatz, Galvin and Gagne \uf6d920024.14Operating System Concepts
Context Switch
\ufffd 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.
\ufffd Context-switch time is overhead; the system does no
useful work while switching.
\ufffd Time dependent on hardware support.
Silberschatz, Galvin and Gagne \uf6d920024.15Operating System Concepts
Process Creation
\ufffd Parent process create children processes, which, in turn
create other processes, forming a tree of processes.
\ufffd Resource sharing
\u2726 Parent and children share all resources.
\u2726 Children share subset of parent\u2019s resources.
\u2726 Parent and child share no resources.
\ufffd Execution
\u2726 Parent and children execute concurrently.
\u2726 Parent waits until children terminate.
Silberschatz, Galvin and Gagne \uf6d920024.16Operating System Concepts
Process Creation (Cont.)
\ufffd Address space
\u2726 Child duplicate of parent.
\u2726 Child has a program loaded into it.
\ufffd UNIX examples
\u2726 fork system call creates new process
\u2726 exec system call used after a fork to replace the process\u2019
memory space with a new program.
Silberschatz, Galvin and Gagne \uf6d920024.17Operating System Concepts
Processes Tree on a UNIX System
Silberschatz, Galvin and Gagne \uf6d920024.18Operating System Concepts
Process Termination
\ufffd Process executes last statement and asks the operating
system to decide it (exit).
\u2726 Output data from child to parent (via wait).
\u2726 Process\u2019 resources are deallocated by operating system.
\ufffd Parent may terminate execution of children processes
(abort).
\u2726 Child has exceeded allocated resources.
\u2726 Task assigned to child is no longer required.
\u2726 Parent is exiting.
\u2714 Operating system does not allow child to continue if its
parent terminates.
\u2714 Cascading termination.
Silberschatz, Galvin and Gagne \uf6d920024.19Operating System Concepts
Cooperating Processes
\ufffd Independent process cannot affect or be affected by the
execution of another process.
\ufffd Cooperating process can affect or be affected by the
execution of another process
\ufffd Advantages of process cooperation
\u2726 Information sharing
\u2726 Computation speed-up
\u2726 Modularity
\u2726 Convenience
Silberschatz, Galvin and Gagne \uf6d920024.20Operating System Concepts
Producer-Consumer Problem
\ufffd Paradigm for cooperating processes, producer process
produces information that is consumed by a consumer
process.
\u2726 unbounded-buffer places no practical limit on the size of the
buffer.
\u2726 bounded-buffer assumes that there is a fixed buffer size.
Silberschatz, Galvin and Gagne \uf6d920024.21Operating System Concepts
Bounded-Buffer \u2013 Shared-Memory Solution
\ufffd Shared data
#define BUFFER_SIZE 10
Typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
\ufffd Solution is correct, but can only use BUFFER_SIZE-1
elements
Silberschatz, Galvin and Gagne \uf6d920024.22Operating System Concepts
Bounded-Buffer \u2013 Producer Process
item nextProduced;
while (1) {
while (((in + 1) % BUFFER_SIZE) == out)
; /* do nothing */
buffer[in] = nextProduced;
in = (in + 1) % BUFFER_SIZE;
}
Silberschatz, Galvin and Gagne \uf6d920024.23Operating System Concepts
Bounded-Buffer \u2013 Consumer Process
item nextConsumed;
while (1) {
while (in == out)
; /* do nothing */
nextConsumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
}
Silberschatz, Galvin and Gagne \uf6d920024.24Operating System Concepts
Interprocess Communication (IPC)
\ufffd Mechanism for processes to communicate and to
synchronize their actions.
\ufffd Message system \u2013 processes communicate with each
other without resorting to shared variables.
\ufffd IPC facility provides two operations:
\u2726 send(message) \u2013 message size fixed or variable
\u2726 receive(message)
\ufffd If P and Q wish to communicate, they need to:
\u2726 establish a communication link between them
\u2726 exchange messages via send/receive
\ufffd Implementation of communication link
\u2726 physical (e.g., shared memory, hardware bus)
\u2726 logical (e.g., logical properties)
Silberschatz, Galvin and Gagne \uf6d920024.25Operating System Concepts
Implementation Questions
\ufffd How are links established?
\ufffd Can a link be associated with more than two processes?
\ufffd How many links can there be between every pair of
communicating processes?
\ufffd What is the capacity of a link?
\ufffd Is the size of a message that the link can accommodate
fixed or variable?
\ufffd Is a link unidirectional or bi-directional?
Silberschatz, Galvin and Gagne \uf6d920024.26Operating System Concepts
Direct Communication
\ufffd Processes must name each other explicitly:
\u2726 send (P, message) \u2013 send a message to process P
\u2726 receive(Q, message) \u2013 receive a message from process Q
\ufffd Properties of communication link
\u2726 Links are established automatically.
\u2726 A link is associated with exactly one pair of communicating
processes.
\u2726 Between each pair there exists exactly one link.
\u2726 The link may be unidirectional, but is usually