# Priority-based schedulling
The goal is to design the processor scheduler for the new VenanciOS operating system. For this purpose, a preemptive algorithm has been devised with dynamic priorities between 0 and 31, where low numbers indicate low priority and high numbers indicate high priority. Processes always start with a fixed priority of value 15. If their quantum is exhausted, their priority decreases by one unit (at least to the value 0) and, if the process does not exhaust and is ejected, it remains with the same priority. If the process goes to sleep waiting for a resource, when it wakes up it increases its priority (boosting), depending on the type of resource, according to the following table:
| Recurso | Incremento de prioridad |
|---------|-------------------------|
| R₁ | 1 |
| R₂ | 2 |
| R₃ | 3 |
| R₄ | 4 |
Characteristics of Scheduling:
- The priority increment is applied to the priority level the process had when it went to sleep.
- If two or more processes are blocked on the same resource, they will be served in FIFO order.
- The system uses a **quantum** value of 2 time units.
- A process that moves to the ready state after waiting is enqueued at the end of the queue corresponding to its priority.
- A process that exhausts its **quantum** is enqueued at the end of the queue corresponding to its priority.
- A process preempted by another with higher priority is enqueued at the head of the queue corresponding to its priority.
- When a preempted process resumes, it is reassigned a full **quantum**.
The following table shows the CPU bursts of different tasks as well as the access times for each device:
| Process | CPU | E/S | CPU | E/S | CPU |
|---------|-----|--------|-----|---------|-----|
| P₁ | 5 | 4R₄ | 3 | 5R₁ | 1 |
| P₂ | 1 | 6R₂ | 7 | 14R₂ | 1 |
| P₃ | 6 | 7R₂ | 5 | 10R₂ | 1 |
| P₄ | 1 | 12R₁ | 3 | 6R₁ | 3 |
Assume that all the processes are activated in t=0 and that they are sorted first $P_1$, then $P_2$, $P_3$ and at the end $P_4$.
With this, answer the following questions with the first moment in time in which this happen:
- Quantum exhaustion.
- Preemption after a I/O operation
- Priority boosting
- Priority decay
- Wait after I/O