You are on page 1of 66

Operating System

Process
Management
CHLOE REOTUTAR
Is a program a
process?
What is a program?
• An inactive unit, such as a file
stored on a disk.
• A unit of work that has been
submitted by the user.
What is a process?
• is an instance of an application in execution.
• an active entity that requires a set of resources to
perform its function.
• a single instance of an executable program.
• also called a task.
Characteristics of a Process
• It requires space in main memory where it resides
during its execution.
• It passes through several states from its initial arrival
into the computer system to its completion.
Page 5

What is a thread?
• A lightweight process
• A unit smaller than a process
• A portion of a process that can run independently
What is a processor?
• The part of the machine that performs the calculations
and executes the programs.
What is multiprogramming?
• having multiple jobs in the system
• requires that the processor be allocated to each process
for a period of time and de-allocated at an appropriate
moment
• the stopping of one process and starting (or restarting)
of another process is called a context switch.
What is multitasking?
• Having multiple processes time slice on the same
processor (either on the same processor, or on different
processors)
What is multiprocessor?
• Using multiple processors for the same job or system
(i.e parallel computing)
Example... Assembling a toy
• In assembling the toy, instructions/directions need to be
followed.
⚬ Step 1 – join Part A to Part B with a 2-inch screw
⚬ Step 2 - Step 3 –
• just after completing the 3rd step,a neighbor who is
injured while working with a power tool cries for help.
• Quickly you check off step 3 in the directions so you know
where you left off, and race to neighbor’s side.
Example... Assembling a toy
• you are now engaged in a very different task: following
instructions in a first-aid book using bandages and
antiseptic.
• Once the injury has been successfully treated, you return
to your previous job.
• And as you pick up your tools, you refer to the
instructions and see that you should begin with Step 4.
• You then continue with this project until it is finally
completed.
Operating System Terminology
• In relation to the given example...
Process Management
• The OS must allocate resources to processes, enable
processes to share and exchange information, protect the
resources of each process from other processes and
enable synchronization among processes.
Scheduling
• Refers to the way processes are assigned priorities in a
priority queue.
• This assignment is carried out by software known as a
scheduler.
• Scheduler decides the process to run first by using a
scheduling algorithm
Job Scheduling and Process
Scheduling
• Job scheduling
⚬ is the process of allocating system resources to
many different tasks by an operating system (OS).
⚬ is performed using job schedulers.
⚬ have the ability to start and control jobs
automatically by running prepared job-control-
language statements or by means of similar
communication with a human operator.
Job Scheduling and Process
Scheduling
• Process scheduling
⚬ is the activity of the process manager that handles
the removal of the running process from the CPU
and the selection of another process on the basis of
a particular strategy.
⚬ is an essential part of a Multiprogramming
operating systems
Type of Processes
• I/O-bound process
⚬ spends more time doing I/O than computations
• CPU-bound process
⚬ spends more time doing computations
Sample Program:
{
printf(“\n Enter the first integer: ”);
scanf(“%d”, &a);
printf(“\nEnter the second integer: ”);
scanf(“%d”,&b);

c = a+b;
d= (a*b)-c;
e = a-b;
f = d/e;

printf(“\n a + b = %d”, c);


printf(“\n (a*b)-c = %d”, d);
printf(“\na-b = %d”, e);
printf(“\nd/e=%d”, f);

}
Process Scheduling Queues
• The OS maintains all PCBs in Process Scheduling
Queues
• The OS maintains a separate queue for each of the
process states and PCBs of all processes in the same
execution state are placed in the same queue.
• The Operating System maintains the following
important process scheduling queues
Process Control Blocks (PCB)
• is a data structure used by computer operating systems
to store all the information about a process.
• Each process in the system is represented by a data
structure called Process Control Block (PCB).
• It performs the same function as a traveler’s passport.
Process Control Blocks (PCB)
• It contains the basic information about the job including
what it is, where it’s going, how much of its processing
has been completed, where it’s stored, and how much it
has spent in using resources.
• Queues use PCBs to track jobs the same way customs
officials use passports to track international visitors.
Process Control Blocks (PCB)
• The Operating System maintains the following important
process scheduling queues:
⚬ Job queue
■ this queue keeps all the processes in the system.
Process Control Blocks (PCB)
⚬ Ready queue
■ this queue keeps a set of all processes residing in
main memory, ready and waiting to execute. A
new process is always put in this queue.
⚬ Device queues
■ the processes which are blocked due to
unavailability of an I/O device constitute this
queue.
Scheduling Algorithms
• refers to the way processes are assigned priorities in a
priority queue.
• This assignment is carried out by software known as a
scheduler.
⚬ Scheduler decides the process to run first by using a
scheduling algorithm
Scheduling Algorithms
• the method by which processes are given access to
system resources, usually processor time.
• The need for a scheduling algorithm arises from the
requirement of most modern systems to execute more
than one process at a time
Type of
Scheduling
Algorithms
Performance Metrics
• CPU Efficiency
• Throughput
• Turnaround time
• Waiting Time
• Response Time
• Fairness
Preemptive Scheduling
• A process scheduling strategy in which the processing of
a job is interrupted and the CPU is transferred to another
job. Also called context switching.
• Temporarily suspend the logically runnable processes
Non-Preemptive Scheduling
• A job scheduling strategy in which the job captures the
processor and begins execution and runs uninterrupted
until it issues an IO request or it is finished.
• Run a process to completion
CPU Utilization
• is the main task in which the operating system needs to make
sure that the CPU remains as busy as possible.
• It can range from 0 to 100 percent.
• However, for the RTOS, it can range from 40 percent for low-
level and 90 percent for the high-level system.
• Formula
TBT
----- x 100%
TFT
Throughput
• the number of jobs completed in a unit of time.
• If there are more jobs completed, there should be more
happy users.
• Maximize the number of jobs processed per hour
• Formula
#Jobs
-------
TFT
Turnaround Time
• the average time from submitting a job until it terminates.
• This is the sum of the time spent waiting in the queue, and
the time actually running.

ATAT = (Finish Time – Arrival Time) / #jobs


Waiting Time
• the time a job waits (in the ready state) until it runs
• reducing the time a job waits until it runs also reduces its
response time
• As the system has direct control over the waiting time, but
little control over the actual run time, it should focus on the
wait time

AWT = (Response Time – Arrival Time) / # jobs


Response Time
• Minimize response time by quickly dealing with interactive
requests, and letting batch requests wait.
• This normalizes all jobs to the same scale: long jobs can wait
more, and don’t count more than short ones.
First-Come First-Served (FCFS)
• A non-preemptive scheduling algorithm that handles jobs
according to their arrival time.
• It uses FIFO queue

⚬ behavior: what comes in first is handled first, what


comes in next waits until the first is finished, etc.
Characteristics of (FCFS) method
• It supports non-preemptive and pre-emptive scheduling
algorithm.
• Jobs are always executed on a first-come, first-serve
basis.
• It is easy to implement and use.
• This method is poor in performance, and the general wait
time is quite high.
Advantage of FCFS
• Here, are pros/benefits of using FCFS scheduling
algorithm:
⚬ The simplest form of a CPU scheduling algorithm
⚬ Easy to program
⚬ First come first served
Disadvantage of FCFS
• Here, are cons/ drawbacks of using FCFS scheduling
algorithm:
⚬ It is a Non-Preemptive CPU scheduling algorithm, so
after the process has been allocated to the CPU, it will
never release the CPU until it finishes executing.
⚬ The Average Waiting Time is high.
⚬ Short processes that are at the back of the queue have
to wait for the long process at the front to finish.
⚬ Not an ideal technique for time-sharing systems.
⚬ Because of its simplicity, FCFS is not very efficient.
First-Come First-Served (FCFS)
Here is an example of five processes arriving at different
times. Each process has a different burst time.
Process Burst time Arrival time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
Shortest Job Next (SJN)
• Also known as Shortest Job First (SJF)
• The job which has the shortest burst time gets the CPU
• Associate the length of the next CPU burst with each
process
Characteristics of SJF
• It is associated with each job as a unit of time to
complete.
• This algorithm method is helpful for batch-type
processing, where waiting for jobs to complete is not
critical.
Characteristics of SJF
• It can improve process throughput by making sure that
shorter jobs are executed first, hence possibly have a
short turnaround time.
• It improves job output by offering shorter jobs, which
should be executed first, which mostly have a shorter
turnaround time.
Advantages of SJF
• SJF is frequently used for long term scheduling.
• It reduces the average waiting time over FIFO (First in
First Out) algorithm.
• SJF method gives the lowest average waiting time for a
specific set of processes.
• It is appropriate for the jobs running in batch, where run
times are known in advance.
Advantages of SJF
• For the batch system of long-term scheduling, a burst
time estimate can be obtained from the job description.
• For Short-Term Scheduling, we need to predict the value
of the next burst time.
• Probably optimal with regard to average turnaround time.
Disadvantages of SJF
• Job completion time must be known earlier, but it is hard
to predict.
• It is often used in a batch system for long term
scheduling.
• SJF can’t be implemented for CPU scheduling for the
short term. It is because there is no specific method to
predict the length of the upcoming CPU burst.
Disadvantages of SJF
• This algorithm may cause very long turnaround times or
starvation.
• Requires knowledge of how long a process or job will run.
• It leads to the starvation that does not reduce average
turnaround time.
• It is hard to know the length of the upcoming CPU request.
• Elapsed time should be recorded, that results in more
overhead on the processor.
Shortest Job Next (SJN)
Shortest Job Next (SJN)
Consider the following five processes each having its own
unique burst time and arrival time.
Process Burst time Arrival time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
Preemptive Priority Scheduling

• Gives preferential treatment to important jobs.


• It allows the programs with the highest priority to be
processed first, and they aren’t interrupted until their
CPU cycles are completed or a natural wait occurs.
• Jobs with the same priority are treated FCFS.
Preemptive Priority Scheduling
Preemptive Priority Scheduling
Process Priority Burst time Arrival time

P1 1 4 0

P2 2 3 0

P3 1 7 6

P4 3 4 11

P5 2 2 12
Characteristics of Priority
Scheduling
• A CPU algorithm that schedules processes based on
priority.
• It used in Operating systems for performing batch
processes.
• If two jobs having the same priority are READY, it works
on a FIRST COME, FIRST SERVED basis.
Characteristics of Priority
Scheduling
• In priority scheduling, a number is assigned to each
process that indicates its priority level.
• Lower the number, higher is the priority.
• In this type of scheduling algorithm, if a newer process
arrives, that is having a higher priority than the currently
running process, then the currently running process is
preempted.
Advantages of Priority Scheduling
• Easy to use scheduling method
• Processes are executed on the basis of priority so high
priority does not need to wait for long which saves time
• This method provides a good mechanism where the
relative important of each process may be precisely
defined.
• Suitable for applications with fluctuating time and
resource requirements.
Disadvantages of Priority Scheduling
• If the system eventually crashes, all low priority
processes get lost.
• If high priority processes take lots of CPU time, then the
lower priority processes may starve and will be
postponed for an indefinite time.
• This scheduling algorithm may leave some low priority
processes waiting indefinitely.
Shortest Remaining Time First
(SRTF)
• Preemptive version of shortest job next scheduling
• Preemptive in nature (only at arrival time)
• The processor is allocated to the job closest to completion.
• Can’t be implemented on interactive system because it
requires advance knowledge of required CPU time.
Characteristics of SRT Scheduling
• This method is mostly applied in batch environments where short
jobs are required to be given preference.
• This is not an ideal method to implement it in a shared system
where the required CPU time is unknown.
• Associate with each process as the length of its next CPU burst. So
that operating system uses these lengths, which helps to schedule
the process with the shortest possible time.
Shortest Remaining Time First
(SRTF)
Round Robin (RR)
• Preemptive in nature
• Preemption based on time slices or time quanta; Time
quantum between 10 and 100 milliseconds
• All user processes are treated to be at the same priority
• No process is allocated CPU for more than 1 quantum in
a row
• Timer interrupt results in context switch and the process
is put at the rear of the ready queue.
Characteristics of Round Robin (RR)
• Round robin is a hybrid model which is clock-driven
• Time slice should be minimum, which is assigned for a specific task
to be processed. However, it may vary for different processes.
• It is a real time system which responds to the event within a
specific time limit.
Advantage of Round Robin (RR)

• It doesn’t face the issues of starvation or convoy effect.


• All the jobs get a fair allocation of CPU.
• It deals with all process without any priority
• If you know the total number of processes on the run queue, then
you can also assume the worst-case response time for the same
process.
Advantage of Round Robin (RR)
• This scheduling method does not depend upon burst time. That’s
why it is easily implementable on the system.
• Once a process is executed for a specific set of the period, the
process is preempted, and another process executes for that given
time period.
• Allows OS to use the Context switching method to save states of
preempted processes.
• It gives the best performance in terms of average response time.
Disadvantage of Round Robin (RR)
• If slicing time of OS is low, the processor output will be reduced.
• This method spends more time on context switching
• Its performance heavily depends on time quantum.
• Priorities cannot be set for the processes.
• Round-robin scheduling doesn’t give special priority to more important
tasks.
• Decreases comprehension
• Lower time quantum results in higher the context switching overhead in
the system.
• Finding a correct time quantum is a quite difficult task in this system.
Round Robin (RR)
Thank you!
Do you have a question?

You might also like