Unit II I
Unit II I
Maximize:
CPU utilization: CPU utilization is the main task in which the
operating system needs to make sure that CPU remains as busy
as possible. It can range from 0 to 100 percent.
Throughput: The number of processes that finish their execution
per unit time is known Throughput.
Cont.
Minimize
Waiting time: Waiting time is an amount of time, that specific
process needs to wait in the ready queue.
Response time: It is an amount of time in which the request was
submitted, the first response is produced.
Turnaround Time: Turnaround time is an amount of time to execute
a specific process. The period between the time of process
submission to the completion time is the turnaround time.
Scheduling Algorithm Optimization
Criteria
Waiting time
Wt[i]=bt[i-1]+wt[i-1]
For process p1
For process p3
Wt[1]=bt[1-1]+wt[1-1] Wt[3]=bt[3-
=bt[0]+wt[0]
=0+0 1]+wt[3-1]
=0
For process p2
=bt[2]+wt[2]
Wt[2]=bt[2-1]+wt[2-1] =2+10 =12
=bt[1]+wt[1]
=10+0
=10
Cont…
Shortest Job First is a non-preemptive AND pre-emptive scheduling algorithm in which the
process with the shortest burst or completion time is executed first by the CPU. That means
the lesser the execution time, the sooner the process will get the CPU. If two processes have
the same burst time, then First Come First Serve (FCFS) scheduling is used to break the tie.
The pre-emptive mode of SJF scheduling is known as the Shortest Remaining Time
For the priority scheduling algorithm, read the number of processes/jobs in the
system, their CPU burst times, and the priorities. Arrange all the jobs in order with
respect to their priorities.
In Priority Preemptive Scheduling, the tasks are mostly assigned with their
priorities.
Priority Scheduling is a method of scheduling processes that are based on
priority. In this algorithm, the scheduler selects the tasks to work as per the priority.
The processes with higher priority should be carried out first, whereas jobs with
equal priorities are carried out on an FCFS basis.
Advantages
Processes are executed based on priority so high priority does not need to wait for long which
saves time.
If two jobs having the same priority are READY, it works on a FIRST COME, FIRST SERVED
basis.
In priority scheduling, a number is assigned to each process that indicates its priority level.
In this type of scheduling algorithm, if a newer process arrives, that is having a higher priority
Disadvantages
If the system eventually crashes, all low priority processes get lost.
P3 P2 P1
Round-Robin Scheduling Algorithm
Suppose that multiple processes are stored in a Process Control Block (PCB). One
process is running state to execute its task with the use of CPUs. As the process is
running, another process arrives in the ready queue, which has a high priority of
completing its task using the CPU. Here we used context switching which switches
the current process with the new process requiring the CPU to finish its tasks. While
switching the process, a context switch saves the status of the old process in
registers. When the process reloads into the CPU, it starts the execution of the
process when the new process stops the old process. If we do not save the state of
the process, we have to start its execution at the initial level. In this way, context
switching helps the operating system to switch between the processes and store or
reload the process when it requires executing its tasks.
Cont.…
The Context switching is a technique or method used by the operating system to switch a
process from one state to another to execute its function using CPUs in the system. When
switching perform in the system, it stores the old running process's status in the form of
registers and assigns the CPU to a new process to execute its tasks. While a new process
is running in the system, the previous process must wait in a ready queue. The execution of
the old process starts at that point where another process stopped it.
There are three major triggers for context switching. These
are given as follows −
Ready queue − This queue keeps a set of all processes residing in the 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 the unavailability of
an I/O device constitute this queue.
The OS can use different policies to manage each queue (FCFS, SJF, Round
Robin, Priority).
The OS scheduler determines how to move processes between the ready and
run queues which can only have one entry per processor.
Process Scheduling Queues
Process Management System Calls-
fork, exit, wait, waitpid, exec
It acts as a link between the operating system and a process, allowing user-level
programs to request operating system services. The kernel system can only be
accessed using system calls.
Process control is the system call that is used to direct the processes.
Some process control examples include creating, load, abort, end, execute, process, terminate the
process, etc.
Functions:
• End and Abort
• Load and Execute
• Create Process and Terminate Process
• Wait
•
fork()
Processes use this system call to create processes that are a copy of
themselves. With the help of this system Call parent process creates a
child process, and the execution of the parent process will be suspended
till the child process executes.
• A new process is created by the fork() system call.
• A new process may be created with fork() without a new program being
run-the new sub-process simply continues to execute exactly the same
program that the first (parent) process was running.
• It is one of the most widely used systems calls under process
management.
exit()
The exit() system call is used to terminate program execution.
The exit() system call is used by a program to terminate its execution.
The operating system reclaims resources that were used by the process after the
exit() system call.
exec()
A new program will start executing after a call to exec()
Running a new program does not require that a new process be created first: any
process may call exec() at any time. The currently running program is immediately
terminated, and the new program starts executing in the context of the existing
process.
Exit(): This call indicates that the thread execution is complete, which is especially useful in
multi-threaded environments.
wait()
In some systems, a process needs to wait for another process to complete its execution.
This type of situation occurs when a parent process creates a child process, and the
execution of the parent process remains suspended until its child process executes.
Waitpid():
The waitpid() system call suspends execution of the current process until a child
specified by pid argument has changed state. By default, waitpid() waits only for
terminated children.