ch3 OS Processes
ch3 OS Processes
Operating System Concepts – 8th Edition,! Silberschatz, Galvin and Gagne ©2009!
Chapter 3: Processes
■ Process Concept"
■ Process Scheduling"
■ Operations on Processes"
■ Interprocess Communication"
Operating System Concepts – 8th Edition! 3.2! Silberschatz, Galvin and Gagne ©2009!
Objectives
Operating System Concepts – 8th Edition! 3.3! Silberschatz, Galvin and Gagne ©2009!
Process Concept
Operating System Concepts – 8th Edition! 3.4! Silberschatz, Galvin and Gagne ©2009!
Process Concept
■ A process includes:"
● program counter "
● Stack (ex. return address)"
● data section "
● Text (code)"
● Heap (memory that is dynamically allocated during
process run time) "
Operating System Concepts – 8th Edition! 3.5! Silberschatz, Galvin and Gagne ©2009!
Process in Memory
Operating System Concepts – 8th Edition! 3.6! Silberschatz, Galvin and Gagne ©2009!
Process State
Operating System Concepts – 8th Edition! 3.7! Silberschatz, Galvin and Gagne ©2009!
Diagram of Process State
Operating System Concepts – 8th Edition! 3.8! Silberschatz, Galvin and Gagne ©2009!
Process Control Block (PCB)
Operating System Concepts – 8th Edition! 3.9! Silberschatz, Galvin and Gagne ©2009!
Process Control Block (PCB)
Information associated with each process"
■ Process state: new, ready, running, waiting, halted."
■ Program counter: the address of the next instruction
to be executed for this process."
■ CPU registers: accumulators, Index registers, SP,
must be saved when an interrupt occurs to allow the
process to be continued correctly afterward."
■ CPU scheduling information: ex. process priority."
■ Memory-management information: ex. the value of
the base and limit registers."
■ Accounting information: ex. process number."
■ I/O status information: ex. List of I/O devices
allocated to the process , list of open files."
Silberschatz, Galvin and Gagne ©2009!
Operating System Concepts – 8th Edition! 3.10!
"
Process Control Block (PCB)
Operating System Concepts – 8th Edition! 3.11! Silberschatz, Galvin and Gagne ©2009!
CPU Switch From Process to Process
Operating System Concepts – 8th Edition! 3.12! Silberschatz, Galvin and Gagne ©2009!
CPU Switch From Process to Process
Operating System Concepts – 8th Edition! 3.13! Silberschatz, Galvin and Gagne ©2009!
Process Scheduling Queues
Operating System Concepts – 8th Edition! 3.14! Silberschatz, Galvin and Gagne ©2009!
Ready Queue And Various I/O Device Queues
Operating System Concepts – 8th Edition! 3.15! Silberschatz, Galvin and Gagne ©2009!
Representation of Process Scheduling
(queuing diagram)
Operating System Concepts – 8th Edition! 3.16! Silberschatz, Galvin and Gagne ©2009!
Schedulers
Operating System Concepts – 8th Edition! 3.17! Silberschatz, Galvin and Gagne ©2009!
Addition of Medium Term Scheduling
Operating System Concepts – 8th Edition! 3.18! Silberschatz, Galvin and Gagne ©2009!
Schedulers (Cont)
Operating System Concepts – 8th Edition! 3.19! Silberschatz, Galvin and Gagne ©2009!
Schedulers (Cont)
Operating System Concepts – 8th Edition! 3.20! Silberschatz, Galvin and Gagne ©2009!
Operations on the processes
1-Process Creation
■ a process may create several new processes, via a
create-process system call. "
■ Parent process create children processes, which, in
turn create other processes, forming a tree of processes"
■ Most O.S. identify process and managed via a unique
process identifier (pid) (an integer number)."
"
Operating System Concepts – 8th Edition! 3.21! Silberschatz, Galvin and Gagne ©2009!
Operations on the processes
1-Process Creation
■ A process will need resources (CPU time, memory, fileI/
O devices) to accomplish its task. "
■ When a process creates a subprocess, that subprocess
may be:"
Ø able to obtain its resources directly from O.S."
Ø Resource sharing"
u Parent and children share all resources"
u Children share subset of parent’s resources"
u Parent and child share no resources"
■ Execution"
● Parent and children execute concurrently"
● Parent waits until some or all children terminate"
Operating System Concepts – 8th Edition! 3.22! Silberschatz, Galvin and Gagne ©2009!
"
Process Creation (Cont)
■ Address space"
● Child duplicate of parent (it has the same program
and data as the parent)."
● Child has a new program loaded into it"
■ UNIX examples"
● fork system call creates new process (copy of the
address space of the original process)."
● exec system call used after a fork to replace the
process’ memory space with a new program"
● Wait() the parent waits for the child process to
complete."
● Exit().!
Operating System Concepts – 8th Edition! 3.23! Silberschatz, Galvin and Gagne ©2009!
Process Creation
Operating System Concepts – 8th Edition! 3.24! Silberschatz, Galvin and Gagne ©2009!
A tree of processes on a typical Solaris
Operating System Concepts – 8th Edition! 3.25! Silberschatz, Galvin and Gagne ©2009!
2- Process Termination
Operating System Concepts – 8th Edition! 3.26! Silberschatz, Galvin and Gagne ©2009!
2- Process Termination
Operating System Concepts – 8th Edition! 3.27! Silberschatz, Galvin and Gagne ©2009!
Interprocess Communication
■ Independent process cannot affect or be affected by the
execution of another process!
■ Cooperating process can affect or be affected by other
processes, including sharing data"
Operating System Concepts – 8th Edition! 3.28! Silberschatz, Galvin and Gagne ©2009!
Interprocess Communication
■ Reasons for cooperating processes:"
● Information sharing (ex.: shared file)"
● Computation speedup (break up process into sub
tasks to run faster and can be achieved only if the
computer has multiple processing elements – CPUs or
I/O channels)"
● Modularity (dividing system functions into separate
processes or threads)"
● Convenience (individual user may work on many tasks
at the same time could be editing, printing, and
compiling in parallel)"
Operating System Concepts – 8th Edition! 3.29! Silberschatz, Galvin and Gagne ©2009!
Interprocess Communication
■ Mechanism for processes to communicate and to synchronize
their actions"
■ Two models of IPC:"
!1) shared memory!
"cooperating processes exchange information by reading and
writing data to a shared region of memory."
"* allows maximum speed and convenience of communication."
"* faster than message passing (system calls only to establish
the region. All accesses are routine memory accesses, no
assistance from the kernel)."
!"
Operating System Concepts – 8th Edition! 3.30! Silberschatz, Galvin and Gagne ©2009!
Interprocess Communication
■ Mechanism for processes to communicate and to synchronize
their actions"
■ Two models of IPC:"
!2) message passing!
"messages are exchanged between the cooperating processes"
"* useful for exchanging smaller amounts of data."
"* easier to implement than is shared memory for
intercomputer communications."
* implemented using system calls (more time, kernel
intervention)."
Operating System Concepts – 8th Edition! 3.31! Silberschatz, Galvin and Gagne ©2009!
Communications Models
Operating System Concepts – 8th Edition! 3.32! Silberschatz, Galvin and Gagne ©2009!
Shared memory system
Operating System Concepts – 8th Edition! 3.33! Silberschatz, Galvin and Gagne ©2009!
Producer-Consumer Problem
■ A common Paradigm for cooperating processes, producer
process produces information that is consumed by a
consumer process."
■ Ex. The assembler produce object modules, which are
consumed by the loader."
■ Ex. Web server produces(provides) HTML files and
images, which are consumed (read) by the web browser
requesting the resource."
■ One solution to the producer-consumer problem uses
shared memory."
■ To Allow the P and C processes to run concurrently, we
must have a buffer that can be filled by the P and emptied
by the C."
■ This buffer reside in a region of memory that is shared by
the P and C processes."
Operating System Concepts – 8th Edition! 3.34! Silberschatz, Galvin and Gagne ©2009!
Producer-Consumer Problem
Operating System Concepts – 8th Edition! 3.36! Silberschatz, Galvin and Gagne ©2009!
Interprocess Communication – Message Passing
Operating System Concepts – 8th Edition! 3.37! Silberschatz, Galvin and Gagne ©2009!
Implementation Questions
Operating System Concepts – 8th Edition! 3.38! Silberschatz, Galvin and Gagne ©2009!
Interprocess Communication – Message
Passing
■ Several methods for logically implementing a link, and
the send()/receive() operations :"
● Direct or indirect communication."
● Synchronous or asynchronous communication."
● Automatic or explicit buffering.
Operating System Concepts – 8th Edition! 3.39! Silberschatz, Galvin and Gagne ©2009!
Direct Communication
■ Processes must name each other explicitly:"
● send (P, message) – send a message to process P"
● receive(Q, message) – receive a message from
process Q"
■ The Properties of the communication link:"
● Links are established automatically between every pair
of processes that want to communicate. The processes
need to know only each other’s identity to
communicate."
● A link is associated with exactly one pair of
communicating processes"
● Between each pair there exists exactly one link"
● The link may be unidirectional, but is usually bi-
directional"
th
Operating System Concepts – 8 Edition! 3.40! Silberschatz, Galvin and Gagne ©2009!
Indirect Communication
■ Messages are directed and received from mailboxes
(also referred to as ports)"
● Each mailbox has a unique id"
● Processes can communicate only if they share a
mailbox"
■ Properties of communication link"
● Link established only if processes share a common
mailbox"
● A link may be associated with many processes"
● Each pair of processes may share several
communication links, with each link corresponding
to one mailbox."
● Link may be unidirectional or bi-directional"
Operating System Concepts – 8th Edition! 3.41! Silberschatz, Galvin and Gagne ©2009!
Indirect Communication
■ Mailbox sharing"
● P1, P2, and P3 share mailbox A."
● P1, sends a message to A; P2 and P3 receive from A."
● Who gets the message?"
■ Solutions"
● Allow a link to be associated with at most two
processes"
● Allow only one process at a time to execute a receive
operation"
● Allow the system to select arbitrarily the receiver (P2
or P3 not both) Sender is notified who the receiver
was."
Operating System Concepts – 8th Edition! 3.43! Silberschatz, Galvin and Gagne ©2009!
"
Synchronization
Operating System Concepts – 8th Edition! 3.44! Silberschatz, Galvin and Gagne ©2009!
Synchronization
Operating System Concepts – 8th Edition! 3.45! Silberschatz, Galvin and Gagne ©2009!
Buffering
Operating System Concepts – 8th Edition! 3.46! Silberschatz, Galvin and Gagne ©2009!
End of Chapter 3
Operating System Concepts – 8th Edition,! Silberschatz, Galvin and Gagne ©2009!