Basics of Computer Systems Lecture 5 - Multitasking PDF
Document Details
Uploaded by EfficientCentaur4176
Tags
Summary
This document is a lecture on multitasking in computer systems. It explores different types of multitasking, such as sequential, concurrent, and parallel, and discusses their pros and cons. The lecture also explains the concept of process scheduling algorithms like First Come First Serve (FCFS), Round Robin (RR), Shortest Job First (SJF), and Priority First (PF).
Full Transcript
Basics of Computer Systems Lecture 5 -- Multitasking **Multitasking** = Running multiple programs on a computer, simultaneously *Importance of multitasking* When executing programs, most of the times programs need to wait for other resources and cannot proceed with the next instructions. Example...
Basics of Computer Systems Lecture 5 -- Multitasking **Multitasking** = Running multiple programs on a computer, simultaneously *Importance of multitasking* When executing programs, most of the times programs need to wait for other resources and cannot proceed with the next instructions. Examples are - Waiting for a specific event - Loading data from network - Reading/writing data to storage devices With [multitasking], when a delay is encountered the CPU will not wait for this delay and instead will work on another program The CPU can even execute multiple tasks and wait for them at the same time, which prevent CPU from going idle Going idle = doing nothing and waiting for some event to occur *Importance of multitasking (2)* Multitasking bring a lot of benefits: - **Efficiency**: Working on another task instead of waiting will often lead to the set of tasks to be completed earlier in time and achieve higher amount of work that can be done. - **Resource** **Utilization**: With multitasking, you will prevent the CPU to go idle. This will allow utilization of the full capacity of the CPU - **User** **experience**: With increased speed and removed blockages the user will experience a seamless and smooth experience when working with the computer even with heavy tasks Multitasking is sometimes also referred to as a *[time-sharing operating system]* Evolution of executing multiple tasks in computing -------------------------------------------------- 1. Sequential (queue) 2. Concurrent 3. Parallel ***Sequential*** The Operating System chooses which task to execute first, and it **cannot switch between tasks** unless first tasks is done. Pros - Simple: Easy to understand, easy to implement - Deterministic: Predictable with no corner cases (problems) Cons - Slow experience: Tasks will be delayed when other tasks take long too complete, even may make the system unusable. ***Concurrent*** Concurrent execution makes tasks execution [appear] to be simultaneous by executing smaller chuncks of each tasks at a time. In both sequential and concurrent execution, one [one tasks] can be processes at a time, but **concurrent execution allows for switching between tasks** Pros - **Better responsiveness**: User experience less lags and overall smoother experience - **Fairness**: Time-sharing algorithms allow a more fair approach for executing programs - **Better Resource utilization**: CPU don't have to wait or I/O tasks Cons - **Complexity**: implementing fairness algorithms can introduce more complexity to system - **Limited parallelism**: Executing programs is still done on one core, it doesn't utilize multi-core CPU's ***Parallel*** Tasks are **[truly]** executed simultaneously. Parallel processing utilizes **multiple processors (CPU cores)** at the same time. It involves executing dividing tasks into smaller chunks that can be executed in smaller chunks that can be executed concurrently. In short, the evolution of executing multiple tasks introduces more complexity to the system, yet we mainly choose it because of its incredible performance. Pros - **High performance:** significant performance, especially for executing CPU intensive apps - **Resource utilization:** uses multiple CPU cores - **Scalability:** distributes tasks not only on multiple cores, but also multiple computers Cons - **Complexity:** sharing data between CPU core is limited, and introduces more complexity in program development - **Overhead:** complex synchronization between process states of same tasks complex Process scheduling algorithms ----------------------------- 1. First Come First Serve (FCFS) 2. Round Robin (RR) 3. Shortest Job First (SJF) 4. Priority First (PF) ***First Come First Serve (FCFS)*** Simple queue, the first tasks in the queue is executed first Pros - **Simple:** very easy to understand and easy to implement Cons - **Unfair delay:** any long process that arrives to queue earlier can make the other processes wait much longer, although this might not be necessary ***Round Robin (RR)*** Gives every process a fair share of time or CPU usage. For example, each task is processed for 1 second, then regardless of the process status, CPU will switch to next tasks. Or in case of CPU usage, CPU will execute for example 30 operations, then it will process 30 operations of the next tasks Pro - **Sameness**: fair time/power usage. Prevents long processes to delay other processes Cons - **Unequal equality:** scheduling results in critical system processes receiving the same time slices as less important or unnecessary tasks. Although this might look justice, but processes are not same neither equal. Different processes need different rights ***Shortest Job First (SJF)*** The process with the shortest execution time is executed next Pros - **Minimal waiting time average**: as shortest tasks are executed first, the waiting time average is minimized Cons - **Preprocess**: requires knowing the execution time of each process before starting the process - **Priority**: Longer jobs will have to wait so much longer if there are shorter jobs available. s ***Priority First (PF)*** Processes are added to queue with their priorities, and higher priority process will execute first. Pros - **Priority aware:** unlike other algorithms, in PF processes are respected with their priorities, so high priorities will always execute quickly Cons - **Priority inversion**: Low priority tasks might suffer from starvation *Questions about multitasking* **How does a [single] CPU core run multiple processes at the same time?** - You win, if only one person raises a hand. - You lose, if no one raises a hand or multiple persons raise a hand. 1. Check if anyone else raised a hand 2. If no one raised a hand, ill raise my hand