UNIT 1 OPERATING SYSTEM’S
PROCESS & PROCESS
SYNCHRONIZATION
Unit 1
Prepared by: Asst. Prof. Bhaumik Raval
INTRODUCTION TO OPERATING SYSTEM
Computer system can be divided into four components
➢ Hardware – provides basic computing resources
CPU, memory, I/O devices
➢ Operating system
Controls and coordinates use of hardware among various
applications and users
➢ Application programs – define the ways in which the
system resources are
used to solve the computing problems of the users
Word processors, compilers, web browsers, database
systems, video games
➢ Users
People, machines, other computers
Computer Software can be divided into two
categories:
Application Programming: -- Our written programs
are called programs which are used to perform some
task or solve some problem.
System Programming:--The programs which manage
the operation of the computer itself is system program.
OS is not a Application program, It is most basic System
Program.
Whenever we are executing the application programs, it
needs some resources like memory, Input/output devices,
CPU etc.
Computer Hardware provides all these resources, even
though computer hardware is not responsible for executing
any application programs which is created by user.
It means, OS must be loaded into the computer system.
Without OS, computer is not ready to run any programs.
OS is essentially the body of the computer system. It
manages all of the hardware and all of the software
in computer system.
So, we can say that OS that OS is interface between
user of computer and hardware. As we can see in
diagram 1.1:
In diagram, it seems that operating system controls and co-
ordinates the hardware among different application
programs for the various user.
OS is similar to government.
Like government, it performs no useful function by itself. It
simply provides an environment within which other
programs can do useful work.
Why OS is known as Resource Manager OR Resource
Allocator?
A Computer system has many resources. The OS acts as the
manager of all these resources. Facing several requests of
all these resources, the OS decides how to allocate them to
specific program and users.
Why OS is known as Program Controller?
Operating system controls the various I/O devices and User
Programs. It manages the execution of the user programs to
prevent errors and also improper use of the computer.
OS SERVICES
The main functions provided by Operating System are as
follows:-
User point of view services:
1. Program execution: -
Because of OS, the system must be able to load the program
into memory and run that program. The program must be
able to end its execution, either normally or abnormally.
2. I/O Operations:
Whenever we are executing a program, it may require I/O.
I/O means I/O devices or a file. For efficiency, and
protection, users are not control the I/O directly. Therefore,
Operating System must provide a control of I/O operations.
3. File-system Manipulation: -
A ll the operations regarding files like creating a file, writing a
file, reading a file,deleting a file etc. are done by Operating
System Only.
4. Communication:-
In many circumstances, one process needs to exchange the
information with another process. Communication can be
occurred in two ways:
1. Communication between processes that are executing on the
same computer.
2. Communication between processes that are executing on different
computer system. In this communication computer network must
be there.
5. Error detection:-
In the computer system, error can be occurred in different ways
like in the CPU and memory hardware, in I/O devices, or in the
user program. OS constantly needs to aware of all possible errors.
For each type of error, OS should take appropriate action.
SYSTEM POINT OF VIEW SERVICES:
1. Resource Allocation:-
When multiple users are logged on the system at same time,
resources must be allocated to each of them. Different types of
resources are managed by operating system.
2. Accounting:-
OS keeps the track of which users use how many and which kind
of computer resources. This record keeping may be used for
accounting.
3. Protection:
The owner of the information which is stored in multiuser
computer system may want to protect that information or file. So
that any unauthorized person can’t access that file.
4. Security:-
Security of the system from outsider is also important. OS
Provides such security by means of password, to be allowed access
to resources etc
PROCESS CONCEPT
Why do we have a concept of Process?
Early computer system (in 1955- 65) allowed only one program to
be executed at a time. This program had completed control of the
system and had access to all the system’s resources.
Current day, in multiprogramming computer system allows
multiple programs to be located into memory and to be executed
concurrently. In this many jobs are in progress at any one time,
each requires several steps to be performed in sequence.
It became impossible to analyze all the possible combination of
sequences of events. So many errors were detected which are
difficult to analyze because they needed to be distinguished from
application software errors and hardware errors.
To tackle these problems, it is required to monitor and control the
various programs executing on the processor in a systematic way.
This is accomplished with the concept of process which is a
program in execution.
DIFFERENCE BETWEEN PROGRAM AND
PROCESS:
Program:
A program is an organized collection of instructions.
A program is a static/passive entity. Once user writes a
program, it will remain as it is until user modifies it.
A program has longer life span. Once a program is written
in some file and stored on disk. It remains there till file is
not deleted. So, its life span may be in months or even in
years.
A Program requires memory space on disk to store all
instructions only.
PROCESS:
A process is an instance of a computer program that is
being executed.
Process is a program in execution.
One by one all instructions are read from the program and
specified operations to be performed.
Process is a dynamic/active entity. It changes its state
during the time of execution. It takes birth (creation), lives
(execution), and dies (termination).
A Process requires various resources like memory space,
disk, printers, scanners, etc. as per its requirements.
A process contains memory space which is called its
address space.
Execution of process must be in a sequential fashion.
Operating system is responsible for managing all the
processes that are running on the computer. Operating
system is also responsible to allocate certain amount of
time to use a processor. Os also allocates various
resources that processes will need like memory, I/O
device etc.
The operating system must be able to create and delete
both user and system processes.
System Process: When System starts (when operating
system is booted), typically several processes are created.
These are system process. They provide various operating
system services (system point of view).
User Process: When you are creating programs, many
processes are created. These are user processes.
Two elements of the process are:
Program code (text section) :- It may be shared
with other process that are executing the same
program. It is represented by the vale of program
counter and the content’s of process’s register.
Data code:- It is set of data . Two processes may be
associated with it the same program, each of them is a
separate process, although text sections are
equivalent, the data section is different.
PROCESS STATE
As a process executes, it changes state. The state of a
process is defined in part by the current activity of that
process.
To keep a track of the state of all the processes,
operating system maintains a table known as a
process table. It stores all the information about each
process.
Inside this table, every process is listed along with
resources that the processes are using and current
state if the process.
EACH PROCESS MAY BE IN ONE OF THE
FOLLOWING STATE:-
1) New:- the process is being created.
2) Running:- running state means instructions of that
process are being executed or run. At a time, only one process
is in run state. In this state process has all the resources which
are needed for execution, and OS has given the permission to use
the processor. The remaining processes are in waiting state.
Which are waiting for I/O device or for event or in ready state
which are waiting for the permission to use the processed.
3) Waiting:- waiting state and read y state are implement as
queue. In this state process is waiting for some event to occur.
4) Ready:- the process is waiting to be assigned to a
processor.
5) Terminated:- The process has finished execution. A
process can terminate by completing its execution or it can be
killed explicitly.
PROCESS STATE
PROCESS CONTROL BLOCK/ TASK
CONTROL BLOCK (PCB/TCB)
Each process in operating system is represented by a
process control block. It is also called a task control
block.
PCB CONTAINS MANY PIECES OF INFORMATION
ASSOCIATED WITH SPECIFIC PROCESS.
IT INCLUDES
Pointer:- each process has a pointer that has address
of next process to be executed.
Process id: Process id is identification number for
the process through which we can uniquely identified.
Each and every process has its own unique-positive integer
number.
Process state:- it mention the state of particular
process. It may be new, ready, run, wait, and exit.
Program counter:- This counter includes the address
of the next instruction to be executed for this process.
CPU registers:- there are different type of registers
depending on the computer architecture. They include
accumulators, index register, stack pointer and general
purpose register etc. this information is must be saved
when interrupt occurs, so that that process can be
continued correctly afterwards.
CPU scheduling information:- This information
includes a process priority, pointers to scheduling
queues, etc.
I/O state information:- The information includes
the list of I/O devices allocated to which process, a
list of open files, etc.
Memory mgmt. information:- This information
includes value of base and limit registers, the page
tables or segment tables depending on the memory
system used by the OS.
Accounting information:- This information used
for billing purpose. It includes what kind of
resources the job used and for how long.
PROCESS SCHEDULING:-
Scheduling: Scheduling is the process of making a
choice of which process to run next whenever more
than one processes are simultaneously in the Ready
state.
SCHEDULING QUEUE.
Job Queue: When a user submits a process to the
system, a process is accepted by the system. They
are put into a job queue. This task is done by job
scheduler.(New state)
Suppose there are five processes than it will be stored
in queue like shown in Figure:
Ready Queue:
The processes that are residing in main memory and
are ready and waiting to execute are kept in Ready
queue, from NEW, process scheduler moves the
job to READY queue.
Ready queue is generally stored as a linked list. Ready
queue header contains pointer to the first and final
PCBs in the list.
A ready queue header contains pointers to the first and
final PCBs in the list. We extend each PCB to include a
pointer field that points to the next PCB in the ready
queue.
Here PCB A will store information of process A, also PCB A
contains address of PCB B, with the help of address in PCB
A, and processor will know which process has to be taken
next. With the help of pointer processor can fetch the
address of next PCB.
Process is allocated the CPU, it execute for a while and
eventually quits, because of interrupted, waits for a device
or a particular event, such as the completion of an I/O
request
Device Queue: The list of process waiting for a
particular I/O device is called device queue .
Each device has its own device queue.
A common representation of process scheduling is a
queuing diagram. Shown in following diagram:-
In the diagram, each rectangular box represents a
queue.
A new process is initially put in the ready queue. It
waits in the ready queue until is selected for
execution.
Once the process is assigned to the CPU and is
executing, one of several events could occur.
The process could issue an I/O request, and then be placed
in an I/O queue.
The process could create a new sub process and waits for its
termination. The process could create new sub process and
wait for its termination.
The process could be removed forcible format the CPU, as a
result of an interrupt, and be put back in the ready queue.
A process continues this cycle unit it terminates, at which
time it is removed form all queues and has its PCB and
resources deal located.
DEPENDING UPON THE BEHAVIOR OF
EXECUTION, PROCESSES CAN BE CLASSIFIED AS:
CPU bound process
Most of the processes in the ready queue spend more of
their time doing computation. It performs lots of
computation and does little I/O. It keeps CPU busy most of
the time. In this case, Device queue will be almost free.
I/O bound process
Most of the processes in the ready queue spend more of
their time doing/waiting for I/O. It performs lots of I/O
operations. In this case, Ready queue will almost empty.
The long term scheduler should select a good process mix of
I/O bound and CPU bound processes. If it selects only I/O
bound processes or only CPU bound processes then system
will be unbalanced. So, System with the best performance
will have a combination of CPU bound and I/O bound
processes.
SCHEDULER:
Scheduler makes a choice of which process run next whenever
more than one processes are simultaneously in the ready queue.
A process migrates between the various scheduling queues
throughout its lifetime. Scheduler selects processes from these
queues.
There are three types of schedulers depending upon the
scheduling queue and operating system:
Long term scheduler/Job Scheduler
It is a first level scheduler. It selects processes from new
state which are in main memory to ready state. It executes
less frequently compared to other schedulers.
Medium term scheduler
It is a second level scheduler. It can be found in operating
system where there is a support for “Swapping”.
Swapping is process of swap-in and swap-out.
Swap-out: Whenever there is a limited memory in main
memory, then it will be swapped out from main memory to
backing store (standard hard disk), that is known as swap
out process. So, process is temporary removed from the
main memory.
Swap-in: Whenever a process is swap in from backing
store to main memory. It is known as swap in.
Short term scheduler/Process Scheduler
It is third level scheduler. It selects process, which is ready
for the execution, from ready queue to run queue. It
executes much frequently than other scheduler.
Context Switch:
Switching the CPU from one process to another is known
as context switch. It requires saving the state of old
process and loading the saved state for the new process.
The context of the process is represented in the PCB of a
process.
OPERATIONS ON PROCESS:
Process Creation
Whenever we are working with multiple programs,
several processes are created and deleted dynamically.
They can be a user process or system process.
A running process may create several new processes via
create process system call. The creating process is called
a parent process, whereas the new processes are called
the children of the process.
Process needs certain resources to accomplish its task.
When process creates a sub process, there are two
possibilities:
Child process may obtain its resources directly from the
parent process.
Parent process may share their resources among their
child processes.
When a process creates a new process, two possibilities may exist
in term of execution:
1....1) The parent process and child process execute
concurrently.
1....2) The parent process waits until some or all of its children
have terminated.
When a process creates a new process, two possibilities may exist
in term of address space:
1....3) The parent process and child process may share the same
address space.
1....4) The Parent process and child process may have their
individual address space.
Each process is identified by its process identifier, which is unique
integer.
New process is created by the fork system call. If parent
process and child process share the address space, then they
can communicate easily. After fork system call, newly created
(child) process has process id 0 and parent process has always
process id nonzero.
Process Termination
Whenever process finish its execution it will be
terminated by operating system. Process may finish its
execution either normally or abnormally. Process will
terminated by the exit system call. Whenever
process terminates, all of its resources will be
deallocated.
When child process terminates, it may return data to
its parent process.
A Parent process may terminate the execution of its
children for different reasons:
The task assigned to the child process is no longer required.
In some cases, suppose parent process terminates first, then
OS will not allow a child to continue their execution. OS will
explicitly terminate all its child processes.
Cooperating Processes:
The concurrent processes executing in the operating
system may be either independent processes or
cooperating processes.
A Process is independent if it can not affect or affected
by the other processes executing in the system.
A Process is cooperating if it can affect or affected by the
other processes executing in the system. It means any
process that shares data as well as address space with
other processes is a cooperating process.
For several reasons, we want to provide an environment
that allows process cooperation.
Information Sharing: To share the information
among different processes, we need cooperating
environment.
Computation Speedup: If we want a particular
task to run faster, we must break it into
subtasks, each of them will be executing in
parallel with others.
Modularity: We may want to construct the
system in a modular fashion, dividing the system
functions into separate processes.
Convenience: An individual user may have many
tasks on which to work at one time. It is very
convenient.
Interprocess Communication:
Cooperating processes can communicate in the shared memory
environment.
Inter process communication provides a mechanism to allow
processes to communicate without sharing the same address space.
IPC is particularly useful in a distributed environment where the
communicating processes may reside on different computer
connected with a network. An example is a chat program used on
the World Wide Web.
An IPC Facility provides at least two operations: send(message) and
receive(message)
Messages sent by a process can be either fixed or variable size.
If two processes want to communicate, they must send messages and
receive messages from each other, a communication link must exist
between them.
Processes that want to communicate must have a way to refer to
each other. They can use either direct or indirect
communication.
DIRECT COMMUNICATION:
With direct communication, each process that wants to
communicate must explicitly name the recipient or sender of the
communication.
A communication link in this scheme has following properties:
A link is associated with exactly two processes.
Exactly one link (one to one) exists between each pair of processes.
Symmetric Communication: In this communication, both sender and
receiver processes must name the other to communicate.
In this scheme, the send and receive operations are defined as:
Send(P, message) : Send a message to process P
Receive(Q, massage) : Receive a message from process
Asymmetric Communication: Only the sender
names the recipient; the recipient is not required
to name the sender. In this scheme, the send and
receive operations are defined as follows:
Send(P, message): send a message to process P.
Receive(id, message) : Receive a message from
process.
Indirect Communication:
With Indirect Communication, the messages are sent to and received
from mailboxes, or ports.
Mailbox is shared data structure consisting of queues that can
temporarily hold messages.
Properties for communication link:
A link is established between a pair of processes only if both
members of the pair have a shared mail box.
A link may be associated with more than two processes.
A number of different links may exist between each pair of
communicating processes, with each link corresponding to one
mailbox.
A mailbox may be owned by either by a process or by a operating
system.
If a mailbox is owned by a process, then we can distinguish between
receiver and sender. Each mailbox has unique owner, So there can
be no confusion about who should receive message sent to this
mailbox.
When a process that owns a mailbox terminates, the mailbox
disappears.
RELATIONSHIP
The relationship between senders and receivers can be
one-to-one , many-to one, one-to-many, or many-to-
many.
A one-to-one relationship allows a private
communication link to be set up between two processes.
A many-to-one relationship is useful for client/server
interaction. One process provides service to a number of
other processes. In this case mailbox is referred to as a port.
A one-to-many relationship allows for a one sender and
multiple receivers, it is useful for applications where a
message or some information is to be broadcast to a set of
processes.
A many-to-many relationship allows multiple server
processes to provide concurrent service to multiple clients.
SYNCHRONIZATION
Communication between processes takes place by calls to
send and receive primitives.
Mutual understanding between two processes while
transferring information is known as synchronization.
There are different design options for implementing each
primitive. Message passing may be blocking or non-
blocking – also known as synchronous and asynchronous.
a. Blocking send. The sending process is blocked until
the message is received by the receiving process or by the
mailbox.
b. Non-blocking send. The sending process sends the
message and resumes operation.
c. Blocking receive. The receiver blocks until a message
is available.
d. Non-blocking receive. The receiver retrieves either a
valid message or a null.
BUFFERING
Whether the communication is direct or indirect message exchanged
by communicating processes reside in a temporary queue. Basically,
such a queue can be implemented in three ways:
1. Zero capacity. The queue has maximum length 0; thus, the
link cannot have any message waiting in it. In this case, the
sender must block until the recipient receives the message. It is
initialized with 0.
2. 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 latter is placed in the queue (either the
message is copied or a pointer to the message is kept), and the
sender can continue the execution without waiting. The queue has a
finite capacity, however, if the queue is full, the sender must block
until space is available.
3. Unbounded capacity. The queue has potentially infinite
length; thus any number of messages can wait in it. The sender
never blocks.
ASSIGNMENT 1: OPERATING SYSTEM’S
PROCESS AND PROCESS SYNCHRONIZATION
1. What is operating system? Explain different services of
operating system.
2. Define process. Explain different states of process.
3. Explain different process scheduling queues.
4. Explain different operation of process.
5. Write down the short note on IPC.
6. Explain process cooperation.
7. Define scheduler and explain different types of scheduler.
8. Define context switch.