Lecture 16
Lecture 16
Process
•For example, when we write a program in C or C++ and compile it, the compiler creates
binary code. The original code and binary code are both programs. When we actually run the
binary code, it becomes a process.
•A process is an ‘active’ entity, as opposed to a program, which is considered to be a
‘passive’ entity. A single program can create many processes when run multiple times; for
example, when we open a .exe or binary file multiple times, multiple instances begin
(multiple processes are created).
Process
•It is the job of OS to manage all the running processes of the system. It handles operations
by performing tasks like process scheduling and such as resource allocation.
What does a process look like in memory?
A program which is going to be picked up by the OS into the main memory is called a new process.
2. Ready
Whenever a process is created, it directly enters in the ready state, in which, it waits for the CPU to be
assigned. The OS picks the new processes from the secondary memory and put all of them in the main
memory.
The processes which are ready for the execution and reside in the main memory are called ready state
processes. There can be many processes present in the ready state.
3. Running
One of the processes from the ready state will be chosen by the OS depending upon the scheduling algorithm.
Hence, if we have only one CPU in our system, the number of running processes for a particular time will
always be one. If we have n processors in the system then we can have n processes running simultaneously.
Process States
4. Block or wait
From the Running state, a process can make the transition to the block or wait state
depending upon the scheduling algorithm or the intrinsic behaviour of the process.
When a process waits for a certain resource to be assigned or for the input from the user
then the OS move this process to the block or wait state and assigns the CPU to the other
processes.
5. Completion or termination
When a process finishes its execution, it comes in the termination state. All the context of the
process (Process Control Block) will also be deleted the process will be terminated by the
Operating system.
Process States
6. Suspend ready
A process in the ready state, which is moved to secondary memory from the main memory due to lack of the
resources (mainly primary memory) is called in the suspend ready state.
If the main memory is full and a higher priority process comes for the execution then the OS have to make the
room for the process in the main memory by throwing the lower priority process out into the secondary
memory. The suspend ready processes remain in the secondary memory until the main memory gets available.
7. Suspend wait
Instead of removing the process from the ready queue, it's better to remove the blocked process which is
waiting for some resources in the main memory. Since it is already waiting for some resource to get available
hence it is better if it waits in the secondary memory and make room for the higher priority process. These
processes complete their execution once the main memory gets available and their wait is finished.
Context Switch
change the process from one state to another using the CPUs present in
• Inter Process Communication (IPC) refers to a mechanism, where the operating systems allow various processes
to communicate with each other. This involves synchronizing their actions and managing shared data.
Types of Process
• Co-operating process: Interact with each other and share data or resources. A co-
operating process can be affected by other executing processes. Inter-process
communication (IPC) is a mechanism that allows processes to communicate with each
other and synchronize their actions. The communication between these processes can be
seen as a method of cooperation between them.
Inter Process Communication (IPC)
• Shared Memory
• Message Passing
Inter Process Communication (IPC)
•The Figure 1 below shows a basic structure of communication between processes via the shared memory
method and via the message passing method.
•An operating system can implement both method of communication. First, we will discuss the shared memory
methods of communication and then message passing.
•Communication between processes using shared memory requires processes to share some variable and it
completely depends on how programmer will implement it. One way of communication using shared memory
can be imagined like this:
Suppose process1 and process2 are executing simultaneously and they share some resources or use some
information from another process. Process1 generate information about certain computations or resources
being used and keeps it as a record in shared memory.
When process2 needs to use the shared information, it will check in the record stored in shared memory and
take note of the information generated by process1 and act accordingly. Processes can use shared memory
for extracting information as a record from another process as well as for delivering any specific information
to other processes.
Let’s discuss an example of communication between processes using shared memory method.
Inter Process Communication (IPC)
i) Shared
•Ex: Producer-Consumer problem
Memory Method
•There are two processes: Producer and Consumer. Producer produces some item and
Consumer consumes that item. The two processes share a common space or memory
location known as a buffer where the item produced by Producer is stored and from which
the Consumer consumes the item, if needed.
•There are two versions of this problem:
the first one is known as unbounded buffer problem in which Producer can keep on
producing items and there is no limit on the size of the buffer
the second one is known as the bounded buffer problem in which Producer can
produce up to a certain number of items before it starts waiting for Consumer to
consume it.
ii) Messaging Passing Method
•In this method, processes communicate with each other without using any kind of shared
memory. If two processes p1 and p2 want to communicate with each other, they proceed
as follows:
Establish a communication link (if a link already exists, no need to establish it again.)
Start exchanging messages using basic primitives.
We need at least two primitives:
– send(message, destination) or send(message)
– receive(message, host) or receive(message)
ii) Messaging Passing Method