Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

OS Module 2

Easy and amazing notes on Operating System for Mumbai university students Sem 4

Uploaded by

razakhan09877
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

OS Module 2

Easy and amazing notes on Operating System for Mumbai university students Sem 4

Uploaded by

razakhan09877
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Process / Concept of Process

•A process is a program at the time of execution. A


process is more than the program code, it includes the
program counter, the process stack and the contents of
process register.
•Process is also called task. Task is an single unit/instance
of an executable program.
•Process is a dynamic entity that executes a program by
using resources allocated by the OS.
•A process can start execution only when all the
requested hardware and software resources have been
allocated to the process.
Components of Process
•Object program : Code to be executed.
•Data : Data to be used for executing the program
•Resources : While executing the program, it may
require some resources.
•Status : Verifies the status of process execution.
Process Control Block / Process Description
•Process control block (PCB) is the data structure used by the OS to
keep track on the processes. When OS creates process, it creates
this process control block. There is separate PCB for each process.
Process Control Block / Process Description
•Process ID : Each process is assigned an unique
identification number by OS.
•Process priority : It describes the priority of the process,
whether its a high priority or low priority process.
•Pointer : This field points to PCB of another process. It
is used for maintaining scheduling list.
•Process state : Process can be in one of the following
states, may be new, ready, waiting, etc.
•Program counter : This field stores the address of the next
instruction to be executed for this process.
Process Control Block / Process Description
•Accounting : This field keeps an account of information about
resources used so far for determine if more resources are
required, how much CPU times is used, how much more time
it will require.
•Memory allocation : This includes information such as address
space allocated to the process.
•I/O status information : It maintains the information about
the files currently opened by the process.
•Event information : This field contains the information for
which process is in the blocked state.
•PCB stores all the information of a specific process. PCB allows
OS to locate key information about the process. OS uses this
information and performs operations on the process.
Process States
•When a process comes in execution, it changes its state. The
state of a process is defined in part by the current activity of
that process. Each process may be in one of the following state
during the time of its execution.
Process States
•New : In this state, the process is being created.
•Ready : In this state, the process is waiting to be assigned
to a CPU through a short term scheduler.
•Waiting : In this state, the process is waiting/blocked for
some event to occur such as input/output operation.
•Running : In this state, instructions are being executed.
•Terminated : In this state, the process has finished the
execution.
In a Uniprocessor system only one process can be in a
running state at a single instant of time, although many
processes may be in ready/waiting state.
Operations on Process
•Create a process
•Destroy a process.
•Resume a process.
•Change the priority of process.
•Wakeup a process.
•Dispatch a process.
•Enable a process to communicate with other process.
Operations on Process
•When a user initiates to execute a program, the operating
system creates a process to represent the execution of
this program. The creation of executable programs includes
many steps, consider the following Fig. 2.3.
Operations on Process
•The source code is translated into object program with the
help of compiler. The relocated object module is
converted to absolute program by linker. The absolute
programs are converted to executable programs by loaders.
Finally processor executes this program. A processor in
execution mode is said to be a process.
•A process consists of the machine code image of program
in memory, plus PCB.
Operations on Process
•Each process is represented in the operating system by its
own process control block (PCB) PCB consists of a specific
process.
•The PCB is a control central of information that allows the
OS to locate all the key information about the process.
•The OS uses this information and performs the operations
on the process.
•The operations include suspend a process, resume a
process, change the priority of a process, dispatch a
process, name the process and so on.
Spawning
•A process creating a new process is named as the parent,
while the created process is called the child. This method
of creating a new process is said to be spawning process. A
child process could itself spawn a process, resulting into a
tree of process, such creation yields a "Hierarchies Process
Structure"

Spawning
Process Termination
•A process terminating from running state includes many causes.
Generally a process terminates when execution is completed.
Some other causes are as follows.
•Time slot expired : When the process execution does not
complete within the "time slice", then the process preempts
from running state. The CPU picks the next job in the ready
queue to execute.
•Memory bound violation : If a process needs more memory
than the available memory, then the process terminates from
running state.
•I/O failure : A process needs an I/O operation at the time of
execution. But if an I/O device is not available at that time, then
process moves to waiting state. If OS does not provides I/O
device in waiting state, then process terminates.
Process Termination
•Parent termination : When the parent process
terminates, the child process also terminates
automatically. The parent process has the authority to
terminate any of its child processes.
•Parent request : If a parent process requests a child
process to terminate, then the child process terminates
automatically.
•Invalid instruction : If a process has illegal instructions and
the CPU fails to execute those instructions, then the
process terminates.
Threads
•A process is divided into number of light weight processes
where, each light weight process is said to be a thread. The
thread has a program counter that keeps track of which
instruction to execute next.
•Because threads have some properties same as process, they
operate in many respects in the same manner as process.
Thread can be in one of the several states viz. ready, blocked,
running, terminated.
•Like process, thread shares the CPU and only one thread at a
time is active or running.
•Threads can create child process and unlike process, threads
are not independent of one another.
Threads
•A thread is said to be in one of the following thread states,
Threads
•Born state : A thread that has just been created.
•Ready state : A thread waiting for CPU.
•Running : CPU is being assigned to the thread and it is
executing.
•Blocked state : A thread is waiting for an I/O device.
•Sleep : A sleeping thread may become ready after the
designated sleep time expires.
•Dead : The execution of the thread is finished.
Process vs. Thread
Process vs. Thread
Multithreading
•A process is divided into number of smaller tasks, each task is
called a 'thread'. Number of threads within a process, executing
simultaneously is called multithreading. Supporting multithreading is
the additional capability of operating system.
•Based on functionality threads are divided into 4 categories as
shown in Fig. 2.8.
Multithreading
Scheduling
•Scheduling refers to the set of policies and mechanisms that an
OS supports for determining the order of execution of
processes. A scheduler is a program that determines the next
pending job to be admitted to the system for execution.

•Goals of Scheduling
To provide fair deal as possible to all pending jobs and
processes.
To optimize the utilization of system resources.
To ensure that more critical processes get priority over others.
Types of Schedulers
•Long term scheduler
•Long term scheduling refers to the OS decision of admitting
the pending process to the system for processing and loading
processes in to main memory and taking them up for
execution.
•Each ready queue contains programmer specified or system
assigned parameters of resource needs, in terms of expected
execution time, memory and I/O requirements. These
specifications enables OS to decide their order of execution.
•The primary goal of long term scheduling is to achieve a
proper mix of I/O bound and CPU bound jobs, so as to keep
the CPU and I/O devices as occupied as possible.
•Long term scheduler controls the degree of
multiprogramming.
Types of Schedulers
•Medium term scheduler
•When a process is suspended after making an I/O request,
it cannot make any progress till the requested I/O is
completed. Such suspended process is removed from main
memory and shifted to secondary memory (HDD)
(swap-out) to make space for another process. This
swapping function is done by medium term scheduler.
•It determines when a swapped out process can be moved
back into the memory (swap-in) and resumed from the
same point, where it was swapped-out.
•Medium term scheduler also reduces the degree of
multiprogramming.
Types of Schedulers
•Short term scheduler
•The function of the short term scheduler is to select a
job\process from the ready queue and give the control of
the CPU to that process with the help of dispatcher.
•A dispatcher is a module, that connects the CPU to the
process selected by the short term scheduler. The main
function of the dispatcher is switching, it means switching
the CPU from one process to another process.
•Short term scheduler selects a process from the ready
queue using CPU scheduling algorithms, such as FCFS, RR,
SJF, Priority.
•Short term scheduler reduces the degree of
multiprogramming.
Types of Scheduling
•Preemptive Scheduling
•Preemptive scheduling allows a process to be interrupted
in the middle of its execution, freeing the CPU and
allocating it to other requesting process. If highest priority
process arrives in the system, CPU's time from currently
executing low priority process is allocated to it.
•Example: Round Robin method, Priority Scheduling
•Non-Preemptive Scheduling
•Non-preemptive scheduling answers that a process
releases the control of CPU only when it finishes with its
current CPU burst/execution time.
•Example - FCFS Method.
Compare
Compare
Long Term Scheduler Medium Term Scheduler Short Term Scheduler
Scheduling Criteria
•The main aim of scheduling is to improve performance by
keeping CPU busy all the time. We can determine which
algorithm is the best algorithm and which is the worst
algorithm using some performance metrics as follows :
•Throughput : Number of jobs completed by CPU within a
time period.
•Waiting time : It is the sum of the periods spent waiting
by a process in the ready queue. CPU scheduling
algorithm having the least average waiting time is said to
be the best algorithm.
•Turnaround time : The time interval between submission
of the process and time of it's completion is the
turnaround time.
Scheduling Criteria
•Response time : It is the time duration between the
submission and first response from the CPU.
•CPU utilization : It is the amount of time the processor
remains busy.
•Fairness : Every process should get equal share of CPU
time.
•Priority : If the OS assigns priorities to processes, scheduler
should favor the higher priority processes first.
Context Switching
•Context of a process is saved in its PCB Switching of CPU's
time from one process to another requires saving of the
state of the old process in its PCB and loading of the saved
state of the new process. This task is performed by OS and
is known as "Context Switching".
The context switching involves the following steps,
Saving the context (state) of the running process in its PCB.
If the running process is being terminated, context
switching will not be required. In that case the process will
be deleted, causing the deletion of its PCB and freeing the
memory occupied by the running process.
Context Switching
Selection of a process from the 'Ready queue' to take
control of the CPU. The state of the newly selected process
will be loaded into the system. This is called as context
loading. The new process will be enabled to run by loading
the address of its next instruction in the program counter
(PC).
During context switch, system does not perform any useful
work. So context switch is a pure overhead on the system.

You might also like