1
CSC351-Operating System
Week-3 Lecture-5
Semester 5
2
Process concept
►Process States
Preamble ►Queues
(Past lesson ►Schedulers
brief)
Lahore Garrison University
3
Operations on Processes
System must provide mechanisms for:
Process creation
Process Preemption
Process Blocking
Process termination
Lahore Garrison University
4
Process Creation
Parent process create children processes, which, in turn create other
processes, forming a tree of processes
Generally, process identified and managed via a process identifier (pid)
Resource sharing options
Parent and children share all resources
Children share subset of parent’s resources
Parent and child share no resources
Execution options
Parent and children execute concurrently
Parent waits until children terminate
Lahore Garrison University
5
A Tree of Processes in Linux
init
pid = 1
login kthreadd sshd
pid = 8415 pid = 2 pid = 3028
bash khelper pdflush sshd
pid = 8416 pid = 6 pid = 200 pid = 3610
emacs tcsch
ps
pid = 9204 pid = 4005
pid = 9298
Lahore Garrison University
6
Process Creation (Cont.)
Address space
Child duplicate of parent
Child has a program loaded into it
UNIX examples
fork() system call creates new process
exec() system call used after a fork() to replace the process memory
7
Process Preemption
Lahore Garrison University
8
Process Blocking
Lahore Garrison University
9
Process Termination
Process executes last statement and then asks the operating system to
delete it using the exit() system call.
Returns status data from child to parent (via wait())
Process’ resources are deallocated by operating system
Parent may terminate the execution of children processes using the
abort() system call. Some reasons for doing so:
Child has exceeded allocated resources
Task assigned to child is no longer required
The parent is exiting and the operating systems does not allow a child to
continue if its parent terminates
Lahore Garrison University
10
Process Termination
Some operating systems do not allow child to exists if its parent has
terminated. If a process terminates, then all its children must also be
terminated.
cascading termination. All children, grandchildren, etc. are terminated.
The termination is initiated by the operating system.
The parent process may wait for termination of a child process by using the
wait()system call. The call returns status information and the pid of the
terminated process
pid = wait(&status);
If no parent waiting (did not invoke wait()) process is a zombie (a zombie
process or defunct process is a process that has completed execution but
still has an entry in the process table)
If parent terminated without invoking wait , process is an orphan
Lahore Garrison University
11
Multiprocess Architecture – Chrome Browser
Many web browsers ran as single process (some still do)
If one web site causes trouble, entire browser can hang or crash
Google Chrome Browser is multiprocess with 3 different types of processes:
Browser process manages user interface, disk and network I/O
Renderer process renders web pages, deals with HTML, Javascript. A new
renderer created for each website opened
Plug-in process for each type of plug-in
Lahore Garrison University
12
Inter process Communication
Independent process cannot affect or be affected by the
execution of another process
Cooperating process can affect or be affected by the
execution of another process
Any process that share data with other processes is a cooperating
process.
Reasons for providing an environment for process cooperation
Information sharing
Computation speed-up
Modularity
Convenience
Lahore Garrison University
13
Inter process
Communication(Cont…)
Information sharing:
Since several users may be interested in the same piece of information (for
instance, a shared file) we must provide an environment to allow concurrent users
to access these types of resources.
Computation speed up:
If we want a particular task to run faster, we must break it into subtasks each of
which will be running in parallel with the others. Such a speedup can be obtained
only if the computer has multiple processing elements (such as CPU’s or I/O
channels).
Lahore Garrison University
14
Inter process
Communication(Cont…)
Modularity:
We may want to construct the system in a modular fashion, dividing the system
functions into separate processes or threads.
Convenience:
Even an individual user may have many tasks on which to work at one time. For
instance, a user may be editing, printing, and compiling in parallel.
Lahore Garrison University
15
Models for Inter process
Communication
Cooperating processes require an inter process communication (IPC)
mechanism that will allow them to exchange data and information.
There are Two Fundamental models of IPC
Shared memory
Message passing
Lahore Garrison University
Inter process Communication – 16
Shared Memory
An area of memory shared among the processes that wish to
communicate
Processes can then exchange information by reading and writing
data to the shared region.
Major issues is to provide mechanism that will allow the user processes
to synchronize their actions when they access shared memory.
Synchronization is discussed in great details ahead.
Lahore Garrison University
Inter process Communication –17
Message Passing
In this model, communication takes place by means of messages
exchange between the cooperating processes, Message system in
which processes communicate with each other without resorting to
shared variables and to synchronize their actions without sharing the
same address space
It is particularly useful in a distributed environment, where the
communicating processes may reside on different computers
connected by a network.
IPC facility provides two operations:
send(message)
receive(message)
The message size is either fixed or variable
Lahore Garrison University
18
Communications Models
(a) Message passing. (b) shared memory.
Lahore Garrison University
19
Message Passing (Cont.)
If processes P and Q wish to communicate, they need to:
Establish a communication link between them
Exchange messages via send/receive
Implementation issues:
How are links established?
Can a link be associated with more than two processes?
How many links can there be between every pair of communicating
processes?
What is the capacity of a link?
Is the size of a message that the link can accommodate fixed or variable?
Is a link unidirectional or bi-directional?
20
Message Passing (Cont.)
Implementation of communication link
Physical:
Shared memory
Hardware bus
Network
Logically implementing a link
Direct or indirect communication
Synchronous or asynchronous communication
Automatic or explicit buffering
Lahore Garrison University
21
Message Passing (Cont.)
Issues regarding Logically implementing a link
Direct or indirect communication [Naming issue]
Synchronous or asynchronous communication
Automatic or explicit buffering
Lahore Garrison University
Naming 22
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
Lahore Garrison University
Property of direct Communication23
for message passing
This Scheme exhibits symmetry in addressing;
That is both the sender process and the receiver process must name the other to
communicate
Another variant of Direct Communication
Here, only the sender names the recipient; the recipient is not required to name
the sender.
Send (P, message)- Send a message to process P
Receive (id, message)- Receive a message from any process;
the variable is set to the name of the process with which communication has
taken place (This scheme employs asymmetry in addressing)
24
Disadvantage of both these
Schemes
The disadvantage in both of these schemes (symmetric and
asymmetric) is the limited modularity of the resulting process
definitions.
Changing the identifier of a process may necessitate examining all
other process definitions.
Lahore Garrison University
25
Indirect Communication
The messages are sent to and received from mailboxes, or ports.
A mailbox can be viewed abstractly as an object into which messages can
be placed by processes and from which messages can be removed.
Each mailbox has a unique identification.
Processes can communicate only if they share a mailbox
Primitives are defined as:
send(A, message) – send a message to mailbox A
receive(A, message) – receive a message from mailbox A
Lahore Garrison University
26
Indirect Communication
Properties of communication link
Link established only if processes share a common mailbox
A link may be associated with more than two processes
Each pair of processes may share several communication links
Link may be unidirectional or bi-directional
Operations
create a new mailbox (port)
send and receive messages through mailbox
destroy a mailbox
Lahore Garrison University
27
Indirect Communication
Mailbox sharing
P1, P2, and P3 share mailbox A
P1, sends; P2 and P3 receive
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. Sender is notified who
the receiver was.
A mailbox may be owned either by a process or by the operating system.
Lahore Garrison University
28
Synchronization
Communication between processes takes place through calls to send()
and receive() primitives. There are different design options for
implementing each primitive.
Message passing may be either blocking or nonblocking also known as
synchronous and asynchronous.
Blocking send. The sending process is blocked until the message is
received by the receiving process or by the mailbox.
Nonblocking send. The sending process sends the message and resumes
operation.
Blocking receive. The receiver blocks until a message is available.
Nonblocking receive. The receiver retrieves either a valid message or a
null.
Lahore Garrison University
29
Buffering
Whether communication is direct or indirect, messages exchanged by
communicating processes reside in a temporary queue. Basically, such
queues can be implemented in three ways:
Zero capacity. The queue has a maximum length of zero; thus, the link
cannot have any messages waiting in it. In this case, the sender must
block until the recipient receives the message.
Bounded capacity. The queue has finite length n; thus, at most n
messages can reside in it. If the queue is not full when a new message
is sent, the message is placed in the queue (either the message is
copied or a pointer to the message is kept), and the sender can
continue execution without waiting. The link’s capacity is finite,
however. If the link is full, the sender must block until space is available
in the queue.
Unbounded capacity. The queue’s length is potentially infinite; thus,
any number of messages can wait in it. The sender never blocks.
30
Reference
To cover this topics , different reference material has
been used for consultation.
Operating systems concept by Abraham siberchatz
edition 9
[Link]
[Link]
Lahore Garrison University