Each bar represents a random task for the CPU to carry out. The length of the bar represents
the time each task will take (the more instructions required the more time the task will take) relative to each other.
A small proportion of these tasks are IO-bound (coloured blue). These tasks often require connection between the CPU
and input or output devices; this means that the task takes a longer time since time is wasted during communication between
the two components. Interrupts can randomly spawn. These are tasks of a higher priority than normal tasks (e.g. a user pressing
a button on their keyboard) and need to be carried out before previous tasks. The interrupts are marked in red and assigned
a priority number (between 1-5). An interrupt causes there to be a stack in the CPU where the CPU remembers what task it was currently
doing however does the interrupt before running. Interrupts can be interrupted by interrupts of a higher priority. Interrupts
of a lower priority are simply added to this stack.
There are different algorithms that you can choose above. They are different ways in which CPUs decide to complete following tasks.
First come first served
Tasks are arranged in a queue. The task that arrived the earliest is carried out by the CPU. The next task that arrived is then
carried out and so on... although this means that all tasks are eventually carried out while not wasting too much time, a large task
could end up taking up huge amounts of CPU memory.
Round Robin
A fixed number of cycles are spent on a task. The CPU then switches tasks and does the same number of cycles in this task and so on...
This ensures that all tasks are carried out; however, time is lost when the CPU switches between tasks.
Shortest Job Next & Shortest Remaining Time
The tasks are sorted in order by length. The shortest subsequent task is carried out first followed by the next shortest task. This is
how I often deal with homeworks. While this optimises time and energy use, I often procrastinate on the harder and longer homeworks.
In technical terms, long processes may require to wait for a long time before they get carried out. This is known as process
starvation.
Shortest remaining time sorts tasks by the number of cycles left for each cycle. This is very similar to Shortest Job Next with only
differences with when new short tasks emerge. Therefore, SRT has the same advantages and disadvantages as SJN.
As always, Enjoy!