What has higher priority on MLFQ? - operating-system

Hello I'm undergraduate student of computer programming
I take operating system class and I have question about MLFQ scheduling
Suppose that MLFQ has two ready queues, and they use both round-robin scheduling method which of time quantum is 3 seconds and 5 seconds each
Of course priority of Q1 is higher.
Then suppose that there are no ready process in Q1, so process in Q2 can be allocated on CPU.
However, a process that finished IO bound burst returns to Q1, and process in CPU which belonged to Q2 is not done(just 3 seconds gone)
In this situation, What happen?
Is the process in Q1 preempt the CPU right now?
Or process in CPU now(which is come from Q2) is allocated on CPU until time quantum of it(still 2 seconds needed) is reached?
Thank you for reading.

The process that arrives after completing I/O burst in Q1, will preempte the process in Q2. Quoting from the Operating Systems principles by Galvin,Gagne and Silberchatz:
A process that arrives in Q1, will preempt a process in Q2. A process
in Q1 will in turn be preempted by a process arriving in Q0(if Q0
exists).
SO,Any process that arrives in a higher priority Q, will preempt the process of a lower priority Q, even if the time quantum of lower process is not reached. A process gets to have the CPU as long as the ready Q of higher priority is empty.

Related

In Short Job First (SJF) scheduling algorithm does IO bound jobs get priority over CPU bound jobs?

Recently I came across the statement that
In SJF IO bound jobs get priority over CPU bound jobs.
I found this statement in page 4 of this slide and also in page 3 of this slide. I decide to attach the corresponding pictures below, if in case the link breaks in the future.
But I am having difficulty to understand the above and it seems rather counter intuitive to me. My argument is as follows:
I assume a CPU bound process is one which uses has higher CPU burst:(CPU Burst+IO Burst) and I assume a process as IO bound which has higher IO Burst:(CPU Burst+IO Burst). I assumed it from the knowledge I have received after reading the textbook "Operating Concepts" by Galvin et. al and the excerpt is below:
An I/O-bound process is one that spends more of its time doing I/O than it spends doing computations. A CPU-bound process, in contrast, generates I/O requests infrequently, using more of its time doing computations.
Which I guess agrees with what the professor says here.
Based on this I came up with the following examples:
Suppose I have two jobs
JOB 1: CPU BURST = 10 units; IO BURST =100 units
JOB 2: CPU BURST= 100 units; IO BURST=10 units...
SJF shall schedule JOB1 first which is IO Bound...
———————————————————————————
suppose I have two other jobs
JOB 3: CPU BURST = 10 units; IO BURST =1 units
JOB 4: CPU BURST= 100 units; IO BURST=200 units...
SJF shall schedule JOB3 first which is CPU bound...
From the above example I do not find any such correlation that SJF gives priority to IO bound jobs.

What fraction of the CPU time is wasted ? (Modern Operating Systems, 4th ed)

it's my first post here.
I'm currently learning Modern Operating Systems and I'm stuck at this question : A computer system has enough room to hold five programs in its main memory. These programs are idle waiting for I/O half of the time. What fraction of the CPU time is wasted?
The answer is 1/32, but why ?
The answer is 1/32, but why ?
The sentence "These programs are idle waiting for I/O half of the time" is ambiguous. Let's look at a few different ways of interpreting this sentence and see if they match the expected answer:
a) "Each of the 5 programs spends 50% of the total time waiting for IO". In this case, while one program is waiting for IO the CPU could be being used by other programs; and all programs combined could use 100% of CPU time with no time wasted. In fact, you'd be able to use 100% of CPU time with only 2 programs (the 1st program uses the CPU while the 2nd program waits for IO, then the 2nd program uses the CPU while the 1st task waits for IO, then ...). This can't be the intended meaning of "These programs are idle waiting for I/O half of the time" because the answer (possibly zero CPU time wasted) doesn't match the expected answer.
b) "All of the programs are idle waiting for I/O at the same time, for half the time". This can't be the intended meaning of the question because the answer would obviously be "50% of CPU time is wasted" and doesn't match the expected answer.
c) "Each program spends half of the time available to it waiting for IO". In this case, the first program has 100% of CPU time available to it but spends 50% of the time using the CPU and waits for IO for the other 50% of the time, leaving 50% of CPU time available for the next program; then the 2nd program uses 50% of the remaining CPU time (25% of total time) using the CPU and 50% of the remaining CPU time (25% of total time) waiting for IO, leaving 25% of CPU time available for the next program; then the third program uses 50% of the remaining CPU time (12.5% of total time) using the CPU and 50% of the remaining CPU time (12.5% of total time) waiting for IO, leaving 12.5% of CPU time available to the next programs, then...
In this case, the remaining time is halved by each program, so you get a "negative power of 2" sequence (1/2, 1/4, 1/8, 1/16, 1/32) that arrives at an answer that matches the expected answer.
Because we get the right answer for this interpretation, we can assume that this is what "These programs are idle waiting for I/O half of the time" was supposed to mean.

Is it possible that you have the same arrival time in CPU Scheduling?

I have searched the internet for examples for the algorithms in cpu scheduling and I have never seen any examples with the same arrival time.
Is it possible to make the processes have the same arrival time?
For example:
Algorithm: Round Robin
Process ---- Arrival Time ----- Burst Time
P1 ----------------- 3 ------------------ 4 -----
P2 ----------------- 1 ------------------ 5 -----
P3 ----------------- 1 ------------------ 3 -----
Quantum = 1
What would be the gantt chart look like?
Is it possible to make the processes have the same arrival time?
Yes, for normal definitions of "same time" (e.g. excluding "in the same Planck time quantum") it's possible for processes to have the same arrival time.
For an example, imagine if 100 tasks sleep until midnight. When midnight occurs a timer IRQ handler processes a list of tasks waiting to wake up and wakes up 100 tasks at the "same" time.
Now, for this example you could say that "same time" is stricter; and that the timer IRQ handler processes the list of tasks sequentially and adds them to scheduler's queues sequentially, and that it's only "almost at the same time". In this case it's still possible to have N CPUs running in parallel (with a different timer for each CPU) that happen to wake (up to) N tasks at the same time.
Of Course, multiple processes can have the same arrival time i.e the time they came for looking the CPU to execute them. And its the responsibility of the Processor to handle and schedule them accordingly as per the appropriate Scheduling Algorithms.
When the Arrival time for two or more processes are same, then the RR-Scheduling follows FCFS {First come first serve} approach. Here in Round robin scheduling with quantum = 1, we have
Gantt Chart
At time 0, no process
At time 1 , we have P2 and P3 with P2 first then after a quantum RR executes P3,
At time 3 we have all three processes with order P2,P3,P1 hence the RR-Algorithm will keep switching between them until they complete their execution (burst) time.
And we will get all executed at time 13.

When is SJF worse than FCFS?

In operating systems of supercomputers, which handles a big quantity of tasks at the same time, is there any situation when SJF policy is taking longer than FCFS policy, speaking of waiting time metric?
It can be assumed that more than one core are present in the system.
First I thought that it is not possible, then I took some time and finally arrived at this result:
Yes it can be.
Suppose that ready queue is filled with processes with equal burst times(all = x):
Process Burst time
P1 x
P2 x
P3 x
P4 x
. .
. .
. .
Pn x
Now in this case what FCFS would do, the process that would come first will be allocated the CPU and then the next process which comes first will be allocated the CPU and so on without wasting any time.
But what SJF will do is :it will first find the job with the shortest burst time from the available jobs in the ready queue which in this case is wastage of time as all have equal burst times and SJF would end up traversing the ready queue without any fruitful result.

How to distinguish between I/O bound and CPU bound jobs ?

How does a long term scheduler decide which job is I/O bound and which one is CPU bound?
I heard that by using cpu burst we can distinguish between I/O bound and CPU bound jobs, but how is the CPU burst calculated without processing the program?
Generally, the CPU scheduler assigns time slices to processes/threads and switches between them whenever a) the time slice has run out or b) the process/thread blocks for I/O.
An I/O-bound job will be blocking for I/O very often, while a process/thread that always makes use of his full time slice can be assumed to be CPU-bound. So by distinguishing whether a process/thread blocks at the end of the time slice or by calling some wait_for_io_completion() function, you can effectively characterize those types of processes.
Note, that in real life, things get more complicated, because most of the time applications are not either I/O-bound or CPU-bound but switch roles all the time. This is why scheduling is about heuristics and not about correct solutions, because you cannot (always) predict the future.
CPU bound uses more of its time doing computations than I/O bound.
answered by tumaini kami david
Answers. Generally, the CPU scheduler assigns time slices to processes/threads and switches between them whenever a) the time slice has run out or b) the process/thread blocks for I/O. ... CPU bound uses more of its time doing computations than I/O bound.strong text
IO BOUND PROCESS :
Io bound process spends more time doing io than computations,many short cpu burst.
COU BOUND PROCESS :
process spends more time doing computations;few very long cpu bursts.