OPERATING SYSTEMS
Processes
OBJECTIVES
• To introduce the notion of a process -- a program
in execution, which forms the basis of all
computation
• To describe the various features of processes,
including scheduling, creation and termination,
and communication
PROCESS CONCEPT
• Process – a program in execution;
• Process execution must progress in sequential fashion
PROCESS STATE
• 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
DIAGRAM OF PROCESS STATE
PROCESS CONTROL BLOCK (PCB)
Information associated with each process
•Process state
•Program counter
•CPU registers
•CPU scheduling information
•Memory-management information
•Accounting information
•I/O status information
PROCESS CONTROL BLOCK (PCB)
CONTEXT SWITCH
• 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 via a
context switch
• Context of a process represented in the PCB
• Context-switch time is overhead; the system does no useful work while
switching
• Time dependent on hardware support
CPU SWITCH FROM PROCESS TO PROCESS
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
• Processes migrate among the various queues
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
SCHEDULERS (CONT)
• Short-term scheduler is invoked very frequently
(milliseconds) (must be fast)
• Long-term scheduler is invoked very infrequently
(seconds, minutes) (may be slow)
• The long-term scheduler controls the degree of
multiprogramming
CPU SWITCH FROM PROCESS TO PROCESS
PROCESS CREATION
• Parent process create children processes, which, in turn
create other processes, forming a tree of processes
• Resource sharing
• Parent and children share all resources
• Children share subset of parent’s resources
• Parent and child share no resources
• Execution
• Parent and children execute concurrently
• Parent waits until children terminate
PROCESS CREATION (CONT)
• fork system call creates new process
• exec system call used after a fork to create a child process.
PROCESS TERMINATION
• Process executes last statement and asks the operating
system to delete it (exit)
• Output data from child to parent (via wait)
• Process’ resources are deallocated by operating system
• Parent may terminate execution of children processes
(abort)
• Child has exceeded allocated resources
• Task assigned to child is no longer required
• If parent is exiting
• Operating system do not allow child to continue if its parent
terminates
• All children terminated - cascading termination
PROCESS CREATION
COOPERATING PROCESSES
• Cooperating process can affect or be affected by the
execution of another process
• Independent process cannot affect or be affected by the
execution of another process
INTERPROCESS COMMUNICATION
• Cooperating process can affect or be affected by other
processes, including sharing data
• Reasons for cooperating processes:
• Information sharing
• Computation speedup
• Cooperating processes need interprocess
communication (IPC)
• Two models of IPC
• Direct Communication - Message Passing
• Indirect Communication – Shared Mailboxes
INTERPROCESS COMMUNICATION – MESSAGE
PASSING
• Message system – processes communicate with each other
without resorting to shared variables
• IPC facility provides two operations:
• send(message) – message size fixed or variable
• receive(message)
• If P and Q wish to communicate, they need to:
• establish a communication link between them
• exchange messages via send/receive
• Implementation of communication link
• physical (e.g., shared memory, hardware bus)
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
• Properties of communication link
• Links are established automatically
• 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
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
• Link may be unidirectional or bi-directional
END OF LECTURE