Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 24

Operating System

Lecture #6-7
Process Management
Objectives
• Cooperating and Independent Processes
• Inter process communication
• Process Management in Unix
Inter Process Communication
• Interprocess communication is the mechanism provided by the operating
system that allows processes to communicate with each other.

• This communication could involve a process letting another process know


that some event has occurred or the transferring of data from one process
to another.
Inter Process Communication
• Processes executing concurrently in the operating system might be either
independent processes or cooperating processes.
• Cooperating Process in the operating system is a process that gets
affected by other processes under execution or can affect any other
process under execution. 
• An independent process in an operating system is one that does not
affect or impact any other process of the system.
Cooperating processes
• It shares data with other processes in the system by directly sharing a
memory or by sharing data through files or messages.
• Cooperating processes in OS requires a communication method that will allow
the processes to exchange data and information.
• There are two methods by which cooperating process in OS can communicate:
• Cooperation by Sharing
• Cooperation by Message Passing
Cooperation by Sharing
• The cooperation processes in OS can
communicate with each other using the
shared resource which
includes data, memory, variables, files,
etc.
• Processes can then exchange the
information by reading or writing data to
the shared region. We can use a critical
section that provides data integrity and
avoids data inconsistency.
Cooperation by Memory
• The cooperating processes in OS can
communicate with each other with the help
of message passing. The production
process will send the message and the
consumer process will receive the same
message.
• There is no concept of shared memory
instead the producer process will first send
the message to the kernel and then
the kernel sends that message to the
consumer process.
Task
• Explore the difference of Message passing and shared memory.
Inter Process Communication
• To send and receive messages in message passing, a communication link
is required between two processes. There are various ways to implement a
communication link.
• Direct and indirect communication
• Synchronous and asynchronous communication
• Buffering
Direct communication
• In direct communication, each process must explicitly name the recipient or
sender of the communication.
• send(P, message) – send a message to process P
• receive(Q, message) – receive a message from process Q
• Link is always created between two processes.
• One direct link can be used only between one pair of communicating processes. 
• Two processes can use only a single direct link for communication.
Indirect communication
• In indirect communication, messages are sent and received through
mailboxes or ports.
• send(A, message) – send a message to mailbox A
receive (A, message) – receive a message from mailbox A
• Different pair of processes can use the same indirect link for
communication.
•  Also, two processes can two different indirect links for communication. 
Synchronous and
asynchronous communication
• Message passing may be blocking (synchronous) or non blocking (non-
synchronous)
• Blocking send – blocks the sending process until the receiving process receives the
message. This means that the sending process will not send data until the receiving
process is also there. For example, in a class, the teacher will not speak until there
are students sitting to receive.
• Non blocking send – the sending process sends the message and resumes
operation. Hence, the sending process does not bother whether the receiver is there
or not.
Synchronous and
asynchronous communication
• Blocking receive – the receiver blocks until a message is available. This
means that the receiving process will not proceed until the sending
process is not there. For example, in a class, the students do not go until
the teacher comes and delivers the lecture.
• Non blocking receive – The receiver process does not wait for the sender
to send data. Hence, the receiver retrieves either a valid message or
NULL.
Buffering
• The speed of the sender and receiver process can be different. So, it is important to
introduce some kind of temporary storage. For example, if your internet connection is
slow, the video in youtube gets buffered. The messages exchanged by the communicating
process reside in a temporary queue. There are three ways to implement queues.
• Zero capacity buffer – it means that there is no buffering in the system. If the receiver is
slow, then the data will be lost.
• Bounded buffer – means that the memory used for buffering has a bound to it. Hence,
you can not buffer unlimited data.
• Unbounded buffer – if there is unlimited memory available for buffering.
Inter Process Communication
• The different approaches to implement interprocess communication are given as follows −
• Pipe
• A pipe is a data channel that is unidirectional. Two pipes can be used to create a two-way data channel between
two processes. This uses standard input and output methods. 
• Socket
• The socket is the endpoint for sending or receiving data in a network. This is true for data sent between processes
on the same computer or data sent between different computers on the same network. Most of the operating
systems use sockets for interprocess communication.
• File
• A file is a data record that may be stored on a disk or acquired on demand by a file server. Multiple processes can
access a file as required. All operating systems use files for data storage.
Inter Process Communication
• Signal
• Signals are useful in interprocess communication in a limited way. They are system messages that are sent
from one process to another. Normally, signals are not used to transfer data but are used for remote commands
between processes.
• Shared Memory
• Shared memory is the memory that can be simultaneously accessed by multiple processes. This is done so that
the processes can communicate with each other. 
• Message Queue
• Multiple processes can read and write data to the message queue without being connected to each other.
Messages are stored in the queue until their recipient retrieves them. Message queues are quite useful for
interprocess communication and are used by most operating systems.
Process Management in Unix
• When you execute a program on your Unix system, the system creates a special
environment for that program. This environment contains everything needed for
the system to run the program as if no other program were running on the system.
• Whenever you issue a command in Unix, it creates, or starts, a new process.
When you tried out the ls command to list the directory contents, you started a
process.
• The operating system tracks processes through a  pid or the process ID. Each
process in the system has a unique pid.
Starting a Process

• When you start a process (run a command), there are two ways you can run it −
• Foreground Processes
• Background Processes
Foreground Processes
• By default, every process that you start runs in the foreground. It gets its input from the
keyboard and sends its output to the screen.
• You can see this happen with the ls command. If you wish to list all the files in your current
directory, you can use the following command −
• $ls ch*.doc
General Definition
• Foreground Processes: They run on the screen and need
input from the user. For example Office Programs
• Background Processes: They run in the background and
usually do not need user input. For example Antivirus.
Running a Foreground Process

• To start a foreground process, you can either run it from the dashboard,
or you can run it from the terminal.
• When using the Terminal, you will have to wait, until the foreground
process runs.
Background Process

Background Processes
A background process runs without being connected to your keyboard. If the background process
requires any keyboard input, it waits.
The advantage of running a process in the background is that you can run other commands; you do
not have to wait until it completes to start another!
The simplest way to start a background process is to add an ampersand (&) at the end of the
command.
$ls ch*.doc &
Types of Processes
• Zombie Process:- A Zombie is a process that has completed its task but
still, it shows an entry in a process table. The zombie process usually
occurred in the child process. Very short time the process is a zombie.
After the process has completed all of its tasks it reports the parent
process that it has about to terminate.
• Zombie is unable to terminate itself because it is treated as a dead process.
So parent process needs to execute to terminate the command to terminate
the child
2. Orphan Process :

A child process that remains running even after its parent process is
terminated or completed without waiting for the child process execution is
called an orphan. A process becomes an orphan unintentionally. Some
time intentionally becomes orphans due to long-running time to complete
the assigned task without user attention. The orphan process has
controlling terminals.
3. Daemon process :

Daemon processes are started working when the system will be
bootstrapped and terminate only when the system is  shutdown .It does not
have a controlling terminal. It always runs in the background.

You might also like