Saturday, 11 April 2020

CPU Scheduling Algorithms in Operating Systems

What is CPU Scheduling?

CPU Scheduling is a process of determining which process will own CPU for execution while another process is on hold. The main task of CPU scheduling is to make sure that whenever the CPU remains idle, the OS at least select one of the processes available in the ready queue for execution. The selection process will be carried out by the CPU scheduler. It selects one of the processes in memory that are ready for execution.
In this CPU scheduling tutorial, you will learn:

Types of CPU Scheduling

Here are two kinds of Scheduling methods:

Preemptive Scheduling

In Preemptive Scheduling, the tasks are mostly assigned with their priorities. Sometimes it is important to run a task with a higher priority before another lower priority task, even if the lower priority task is still running. The lower priority task holds for some time and resumes when the higher priority task finishes its execution.

Non-Preemptive Scheduling

In this type of scheduling method, the CPU has been allocated to a specific process. The process that keeps the CPU busy will release the CPU either by switching context or terminating. It is the only method that can be used for various hardware platforms. That's because it doesn't need special hardware (for example, a timer) like preemptive scheduling.

When scheduling is Preemptive or Non-Preemptive?

To determine if scheduling is preemptive or non-preemptive, consider these four parameters:
  1. A process switches from the running to the waiting state.
  2. Specific process switches from the running state to the ready state.
  3. Specific process switches from the waiting state to the ready state.
  4. Process finished its execution and terminated.
Only conditions 1 and 4 apply, the scheduling is called non- preemptive.
All other scheduling are preemptive.

Important CPU scheduling Terminologies

  • Burst Time/Execution Time: It is a time required by the process to complete execution. It is also called running time.
  • Arrival Time: when a process enters in a ready state
  • Finish Time: when process complete and exit from a system
  • Multiprogramming: A number of programs which can be present in memory at the same time.
  • Jobs: It is a type of program without any kind of user interaction.
  • User: It is a kind of program having user interaction.
  • Process: It is the reference that is used for both job and user.
  • CPU/IO burst cycle: Characterizes process execution, which alternates between CPU and I/O activity. CPU times are usually shorter than the time of I/O.

CPU Scheduling Criteria

A CPU scheduling algorithm tries to maximize and minimize the following:

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. However, for the RTOS, it can be range from 40 percent for low-level and 90 percent for the high-level system.
Throughput: The number of processes that finish their execution per unit time is known Throughput. So, when the CPU is busy executing the process, at that time, work is being done, and the work completed per unit time is called Throughput.

Minimize:

Waiting time: Waiting time is an amount that specific process needs to wait in the ready queue.
Response time: It is an amount to time in which the request was submitted until the first response is produced.
Turnaround Time: Turnaround time is an amount of time to execute a specific process. It is the calculation of the total time spent waiting to get into the memory, waiting in the queue and, executing on the CPU. The period between the time of process submission to the completion time is the turnaround time.
Timer interruption is a method that is closely related to preemption. When a certain process gets the CPU allocation, a timer may be set to a specified interval. Both timer interruption and preemption force a process to return the CPU before its CPU burst is complete.
Most of the multi-programmed operating system uses some form of a timer to prevent a process from tying up the system forever.

What is Dispatcher?

It is a module that provides control of the CPU to the process. The Dispatcher should be fast so that it can run on every context switch. Dispatch latency is the amount of time needed by the CPU scheduler to stop one process and start another.
Functions performed by Dispatcher:
  • Context Switching
  • Switching to user mode
  • Moving to the correct location in the newly loaded program.

Types of CPU scheduling Algorithm

There are mainly six types of process scheduling algorithms
  1. First Come First Serve (FCFS)
  2. Shortest-Job-First (SJF) Scheduling
  3. Shortest Remaining Time
  4. Priority Scheduling
  5. Round Robin Scheduling
  6. Multilevel Queue Scheduling
Scheduling Algorithms

First Come First Serve

First Come First Serve is the full form of FCFS. It is the easiest and most simple CPU scheduling algorithm. In this type of algorithm, the process which requests the CPU gets the CPU allocation first. This scheduling method can be managed with a FIFO queue.
As the process enters the ready queue, its PCB (Process Control Block) is linked with the tail of the queue. So, when CPU becomes free, it should be assigned to the process at the beginning of the queue.

Characteristics of FCFS method:

  • It offers 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.
  • However, this method is poor in performance, and the general wait time is quite high.

Shortest Remaining Time

The full form of SRT is Shortest remaining time. It is also known as SJF preemptive scheduling. In this method, the process will be allocated to the task, which is closest to its completion. This method prevents a newer ready state process from holding the completion of an older process.

Characteristics of SRT scheduling method:

  • 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.

Priority Based Scheduling

Priority scheduling is a method of scheduling processes based on priority. In this method, the scheduler selects the tasks to work as per the priority.
Priority scheduling also helps OS to involve priority assignments. The processes with higher priority should be carried out first, whereas jobs with equal priorities are carried out on a round-robin or FCFS basis. Priority can be decided based on memory requirements, time requirements, etc.

Round-Robin Scheduling

Round robin is the oldest, simplest scheduling algorithm. The name of this algorithm comes from the round-robin principle, where each person gets an equal share of something in turn. It is mostly used for scheduling algorithms in multitasking. This algorithm method helps for starvation free execution of processes.

Characteristics of Round-Robin Scheduling

  • 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.

Shortest Job First

SJF is a full form of (Shortest job first) is a scheduling algorithm in which the process with the shortest execution time should be selected for execution next. This scheduling method can be preemptive or non-preemptive. It significantly reduces the average waiting time for other processes awaiting execution.

Characteristics of SJF Scheduling

  • It is associated with each job as a unit of time to complete.
  • In this method, when the CPU is available, the next process or job with the shortest completion time will be executed first.
  • It is Implemented with non-preemptive policy.
  • This algorithm method is useful for batch-type processing, where waiting for jobs to complete is not critical.
  • It improves job output by offering shorter jobs, which should be executed first, which mostly have a shorter turnaround time.

Multiple-Level Queues Scheduling

This algorithm separates the ready queue into various separate queues. In this method, processes are assigned to a queue based on a specific property of the process, like the process priority, size of the memory, etc.
However, this is not an independent scheduling OS algorithm as it needs to use other types of algorithms in order to schedule the jobs.

Characteristic of Multiple-Level Queues Scheduling:

  • Multiple queues should be maintained for processes with some characteristics.
  • Every queue may have its separate scheduling algorithms.
  • Priorities are given for each queue.

The Purpose of a Scheduling algorithm

Here are the reasons for using a scheduling algorithm:
  • The CPU uses scheduling to improve its efficiency.
  • It helps you to allocate resources among competing processes.
  • The maximum utilization of CPU can be obtained with multi-programming.
  • The processes which are to be executed are in ready queue.

Summary:

  • CPU scheduling is a process of determining which process will own CPU for execution while another process is on hold.
  • In Preemptive Scheduling, the tasks are mostly assigned with their priorities.
  • In the Non-preemptive scheduling method, the CPU has been allocated to a specific process.
  • Burst time is a time required for the process to complete execution. It is also called running time.
  • CPU utilization is the main task in which the operating system needs to make sure that CPU remains as busy as possible
  • The number of processes that finish their execution per unit time is known Throughput.
  • Waiting time is an amount that specific process needs to wait in the ready queue.
  • It is an amount to time in which the request was submitted until the first response is produced.
  • Turnaround time is an amount of time to execute a specific process.
  • Timer interruption is a method that is closely related to preemption,
  • A dispatcher is a module that provides control of the CPU to the process.
  • Six types of process scheduling algorithms are:
  • First Come First Serve (FCFS), 2) Shortest-Job-First (SJF) Scheduling 3) Shortest Remaining Time 4) Priority Scheduling 5) Round Robin Scheduling 6) Multilevel Queue Scheduling
  • In the First Come First Serve method, the process which requests the CPU gets the CPU allocation first.
  • In the Shortest Remaining time, the process will be allocated to the task, which is closest to its completion.
  • In, Priority Scheduling the scheduler selects the tasks to work as per the priority.
  • In, this Round robin scheduling works on principle, where each person gets an equal share of something in turn
  • In Shortest job first the shortest execution time should be selected for execution next
  • In Multilevel scheduling, method separates the ready queue into various separate queues. In this method, processes are assigned to a queue based on a specific property
  • The CPU uses scheduling to improve its efficiency
A Process Scheduler schedules different processes to be assigned to the CPU based on particular scheduling algorithms. There are six popular process scheduling algorithms which we are going to discuss in this chapter −
  • First-Come, First-Served (FCFS) Scheduling
  • Shortest-Job-Next (SJN) Scheduling
  • Priority Scheduling
  • Shortest Remaining Time
  • Round Robin(RR) Scheduling
  • Multiple-Level Queues Scheduling
These algorithms are either non-preemptive or preemptive. Non-preemptive algorithms are designed so that once a process enters the running state, it cannot be preempted until it completes its allotted time, whereas the preemptive scheduling is based on priority where a scheduler may preempt a low priority running process anytime when a high priority process enters into a ready state.

First Come First Serve (FCFS)

  • Jobs are executed on first come, first serve basis.
  • It is a non-preemptive, pre-emptive scheduling algorithm.
  • Easy to understand and implement.
  • Its implementation is based on FIFO queue.
  • Poor in performance as average wait time is high.
First Come First Serve Scheduling Algorithm
Wait time of each process is as follows −
ProcessWait Time : Service Time - Arrival Time
P00 - 0 = 0
P15 - 1 = 4
P28 - 2 = 6
P316 - 3 = 13
Average Wait Time: (0+4+6+13) / 4 = 5.75

Shortest Job Next (SJN)

  • This is also known as shortest job first, or SJF
  • This is a non-preemptive, pre-emptive scheduling algorithm.
  • Best approach to minimize waiting time.
  • Easy to implement in Batch systems where required CPU time is known in advance.
  • Impossible to implement in interactive systems where required CPU time is not known.
  • The processer should know in advance how much time process will take.
Given: Table of processes, and their Arrival time, Execution time
ProcessArrival TimeExecution TimeService Time
P0050
P1135
P22814
P3368
Shortest Job First Scheduling Algorithm
Waiting time of each process is as follows −
ProcessWaiting Time
P00 - 0 = 0
P15 - 1 = 4
P214 - 2 = 12
P38 - 3 = 5
Average Wait Time: (0 + 4 + 12 + 5)/4 = 21 / 4 = 5.25

Priority Based Scheduling

  • Priority scheduling is a non-preemptive algorithm and one of the most common scheduling algorithms in batch systems.
  • Each process is assigned a priority. Process with highest priority is to be executed first and so on.
  • Processes with same priority are executed on first come first served basis.
  • Priority can be decided based on memory requirements, time requirements or any other resource requirement.
Given: Table of processes, and their Arrival time, Execution time, and priority. Here we are considering 1 is the lowest priority.
ProcessArrival TimeExecution TimePriorityService Time
P00510
P113211
P228114
P33635
Priority Scheduling Algorithm
Waiting time of each process is as follows −
ProcessWaiting Time
P00 - 0 = 0
P111 - 1 = 10
P214 - 2 = 12
P35 - 3 = 2
Average Wait Time: (0 + 10 + 12 + 2)/4 = 24 / 4 = 6

Shortest Remaining Time

  • Shortest remaining time (SRT) is the preemptive version of the SJN algorithm.
  • The processor is allocated to the job closest to completion but it can be preempted by a newer ready job with shorter time to completion.
  • Impossible to implement in interactive systems where required CPU time is not known.
  • It is often used in batch environments where short jobs need to give preference.

Round Robin Scheduling

  • Round Robin is the preemptive process scheduling algorithm.
  • Each process is provided a fix time to execute, it is called a quantum.
  • Once a process is executed for a given time period, it is preempted and other process executes for a given time period.
  • Context switching is used to save states of preempted processes.
Round Robin Scheduling Algorithm
Wait time of each process is as follows −
ProcessWait Time : Service Time - Arrival Time
P0(0 - 0) + (12 - 3) = 9
P1(3 - 1) = 2
P2(6 - 2) + (14 - 9) + (20 - 17) = 12
P3(9 - 3) + (17 - 12) = 11
Average Wait Time: (9+2+12+11) / 4 = 8.5

Multiple-Level Queues Scheduling

Multiple-level queues are not an independent scheduling algorithm. They make use of other existing algorithms to group and schedule jobs with common characteristics.
  • Multiple queues are maintained for processes with common characteristics.
  • Each queue can have its own scheduling algorithms.
  • Priorities are assigned to each queue.
For example, CPU-bound jobs can be scheduled in one queue and all I/O-bound jobs in another queue. The Process Scheduler then alternately selects jobs from each queue and assigns them to the CPU based on the algorithm assigned to the queue.

Friday, 10 April 2020

Global COVID-19 Death Count Crosses 1,00,000: Report

The number of deaths linked to the novel coronavirus reached 100,000 on Friday, as the tally of cases passed 1.6 million, according to a Reuters tally.

The first death came in the central Chinese city of Wuhan on January 9. It took 83 days for the first 50,000 deaths to be recorded and just eight more for the toll to climb to 100,000.

The count has been accelerating at a daily rate of between 6% and 10% over the past week, and there were almost 7,300 deaths globally reported on Thursday.

The death count now compares with that of London's Great Plague in the mid-1660s, which killed an estimated 100,000 people, about a third of the city's population at the time.
But it is still far short of the so-called Spanish flu, which began in 1918 and is estimated to have killed more than 20 million people by the time it petered out in 1920.

The novel coronavirus is believed to have emerged in a Wuhan market where wild animals were sold late last year. It quickly spread through China and around the world.

Much remains to be determined about it, including just how lethal it is. Estimates vary widely.

Friday's figures - 100,000 deaths of out 1.6 million cases - would suggest a fatality rate of 6.25% but many experts believe the actual rate is lower given that many mild and asymptomatic cases, when infected people don't show symptoms, are not included in case totals.

Some countries, including Italy, France, Algeria, the Netherlands, Spain and Britain are reporting that more than 10% of all confirmed cases have been fatal.

One of the largest studies of the fatality of the disease, involving 44,000 patients in China, put the rate at about 2.9%.

The same study reported that 93% of recorded fatalities were people over the age of 50, and more than half were over 70.

Despite that, there are growing numbers of young adults and teenagers included in the global toll.

While North America now accounts for more than 30% of cases, Europe has reported a disproportionate number of fatalities, as countries with older populations like Spain and Italy have been severely affected.

Southern Europe alone accounts for more than a third of global deaths, despite recording just 20% of cases.

In many countries, official data includes only deaths reported in hospitals, not those in homes or nursing homes.

Top ten Corona updates 10-4-2020 india


  1. Punjab has become the second state, after Odisha, to extend the Prime Minister's nationwide "total lockdown". The lockdown had been scheduled to end on April 14 but will now continue, in Punjab and Odisha at least, till the end of the month. Punjab has registered 132 coronavirus cases, as of Friday despite the strict three-week lockdown. Odisha has 44 cases and one person has died due to the virus.
  2. Addressing a virtual press conference today the Punjab Chief Minister also flagged concerns the country is "moving into" community transmission. Mr Singh pointed to 27 COVID-19 patients in the state who were, he said, cases of secondary transmission. The centre was swift to deny this claim, with Lav Aggarwal, a Joint Secretary in the Health Ministry, saying: "I reiterate, there is no community transmission yet across the country".
  3. Prime Minister Modi is likely to address the nation again - his third address since the lockdown was ordered - to clarify whether the lockdown will end on Tuesday. Sources say the lockdown may be extended but with many changes this time around. Interstate movement will remain restricted, except for essential services. Schools, colleges and religious institutions are likely to stay closed.
  4. Meanwhile, amid fears expressed by medical experts that the country has entered Stage 3 - i.e., community transmission of the virus, the World Health Organisation (WHO) admitted an error in its daily report. Earlier today the global health watchdog said India was experiencing "community transmission", something the government has repeatedly denied. When contacted by NDTV the organisation said the error had been fixed and clarified that India had only a "cluster of cases".
  5. However, random coronavirus tests on patients with severe respiratory diseases indicates that more and more people with no travel history, or contact with those who have one, are contracting the COVID-19 virus. Data compiled by the ICMR (Indian Council for Medical Research, the government's nodal body in the fight against the virus) shows 38 per cent of such patients had no travel history.
  6. Two weeks ago, when asked about the possibility of community transmission of coronavirus, the ICMR had responded in the negative. The ICMR had been conducting random tests on SARI (severe acute respiratory illness) patients to determine whether there was community transmission of the novel coronavirus. ICMR data also shows that in the weeks before March 14 no SARI patient tested positive for the novel coronavirus.
  7. Meanwhile, the ICMR has amped up testing in hotspots identified and sealed in Delhi and other states. Now people in the hotspots, whether connected to the patients or not, will be tested if they show symptoms of the disease for at least a week, the medical body has said.
  8. Dilshad Garden in northeast Delhi is the first novel coronavirus hotspot to be declared infection-free, Health Minister Satyendra Jain told NDTV today. Under an extensive exercised codenamed "Operation Shield" the Delhi government set up 123 medical teams to screen over 15,000 people living in 4,032 houses in the area before declaring it "coronavirus-free". On Wednesday the Delhi government released a list of 20 hotspots, including Nizamuddin Basti - where the Tablighi Jamaat's religious gathering was held last month.
  9. A bipartisan group of top United States lawmakers have urged China to shut down all operating "wet markets" as these could expose humans to health risks through the introduction of zoonotic diseases such as COVID-19. A "wet market" sells fresh meat, fish, produce, and other perishable goods as distinguished from "dry markets" and gets its name because the floors are usually wet from the spraying of fresh produce and cleaning of meat and seafood stalls.
  10. Worldwide more than 16 lakh people have been infected by the COVID-19 virus that originated in China's Wuhan district in December last year. Nearly 97,000 others have died. India this week has exported large quantities of hydroxychloroquine, an anti-malarial drug believed effective in treating the virus, to the United States and Israel, while exporting raw material to produce the drug to Brazil.