Beruflich Dokumente
Kultur Dokumente
Process scheduling
Operation on Processes
Cooperating Processes
Threads
Interprocess communication
An operating system executes a variety of programs:
Batch system jobs
Time-shared systems user programs or tasks
Process a program in execution.
A process includes:
program counter
stack
data section
A process is an abstraction that supports running programs
Different processes may run several instances of the same
program
In most systems, processes form a tree, with the root being the
first process to be created
At a minimum, the following resources are required:
Memory to contain the program code and data
A set of CPU registers to support execution
•Multiprogramming of
four
programs
• Conceptual model
-- 4 independent
processes
-- Processes run
sequentially
• Only one program active
at any instant!
-- That instant can be
very short…
As a process executes, it changes state
new: The process is being created
running: Instructions are being executed
waiting: The process is waiting for some event to occur
ready: The process is waiting to be assigned to a
processor
terminated: The process has finished execution
Each process has a process control block (pcb)
that:
describes its components and other relevant data
allows efficient and centralized access to all
information related to a process
Routing queues usually use pointers to pcb s
Naming: Each process has a process identifier
(pid)
must be unique
must be reused with extreme care after a process
terminates
PCB contains many pieces of
information associated with each
process, including:
Process state
Program counter
CPU registers
CPU scheduling information
Memory-management
information
Accounting information
I/O status information
Scheduling Queues
Waiting
Types of Schedulers
Long term ( job ) scheduler
Slow
Short term ( CPU ) scheduler
Fast
100 ms:
Dispatcher
Switching context
Switching to user mode
Jumping to proper location in program
Invoked during every process switch - Dispatcher should be
as fast as possible
Dispatch latency
Time that the Dispatcher takes to stop one process and
start another running.
Save registers of old process
General purpose registers
Memory management related information
Stack pointer
Save PSW of old process
Put PCB on relevant queue
save PC of old process
Mark PCB of new process as running
Load PSW of new process
Load PC of new process
New process continues to run from where interrupted
Context switching time is overhead not useful work
Penalties of CS
Explicit:
Cost of loading and storing registers from/into
main memory
Implicit:
In a pipelined CPU, must wait until pipeline is
drained
If a CPU uses memory caches, the process that
is switched in, usually have a large number of
cache misses when it runs until they are loaded
from memory
Context switching overhead is a big factor in the
efficiency of an operating system, and its cost
continues to increase with faster CPU s
Parent process creates children processes, which, in turn
create other processes, forming a tree of processes.
Execution possibilities:
UNIX examples
Information sharing
Computing Speedup
overlap CPU and I/O
use several processors
Modularity
Convenience
Classical models
Reader/Writer
Shared data
var n; var buffer, array [0..n–1] of item;
type item = … ; in, out: 0….n-1;
repeat repeat
while in == out do no-op;
produce an item in nextp nextc := buffer [out];
while in + 1 mod n == out out := out+1 mod n;
do no-op;
buffer [in] :=nextp; consume the item in nextc
in :=in+1 mod n;
until false;
until false;
Single threading:
“Many-to-One” model
Contains code for:
creating and destroying threads
passing messages and data between threads
scheduling thread execution
pass control from one thread to another
saving and restoring thread contexts
time
their actions.
receive(message)
If processes P and Q wish to communicate, they need to:
destroy a mailbox
Solutions
Allow a link to be associated with at most two processes
1. Zero capacity
0 messages
Sender must wait for receiver (rendezvous)
2. Bounded capacity
finite length of n messages
Sender must wait if the link is full
3. Unbounded capacity
infinite length
Sender never waits