OS_Assignment-2_Aman Ranjan_C.S.E/A- 1901000002122 1. A process control block (PCB) contains information about the process, i.e., registers, quantum, priority, etc. The process table is an array of PCBs, that means logically contains a PCB for all of the current processes in the system. Pointer – It is a stack pointer which is required to be saved when the process is switched from one state to another to retain the current position of the process. Process state – It stores the respective state of the process. Process number – Every process is assigned with a unique id known as process ID or PID which stores the process identifier. Program counter – It stores the counter which contains the address of the next instruction that is to be executed for the process. Register – These are the CPU registers which includes: accumulator, base, registers and general-purpose registers. Memory limits – This field contains the information about memory management system used by operating system. This may include the page tables, segment tables etc. Open files list – This information includes the list of files opened for a process. 2. Context Switching leads to an overhead cost because of TLB flushes, sharing the cache between multiple tasks, running the task scheduler etc. Context switching between two threads of the same process is faster than between two different processes as threads have the same virtual memory maps. 3. Process VS Thread Processes Threads Processes are independent Threads are a subset of processes Processes carry more unique information than threads Multiple threads within a process share resources Processes have separate memory addresses Threads share their address space Processes context switch relatively slowly Thread’s context switches quickly 4. Types of Schedulers [3]: Long-Term Scheduler: It is also called a job scheduler. A long-term scheduler determines which programs are admitted to the system for processing. It selects processes from the queue and loads them into memory for execution. Short-Term Scheduler: The short-term scheduler (also known as the CPU scheduler) decides which of the ready, in-memory processes is to be executed after a clock interrupt, an I/O interrupt, an operating system call or another form of signal. Medium-Term Scheduler: Medium-term (Process swap scheduler) scheduling is a part of swapping. It removes the processes from the memory. It reduces the degree of multiprogramming. It removes the suspended process from memory and make space for other processes, the suspended process is moved to the secondary storage. This process is called swapping, and the process is said to be swapped out or rolled out. 5. Different states of Process: Start: The Process is first created from a program. Ready: The Process is waiting to be assigned to a processor by the OS scheduler. Running: The Process instruction are executed by the processor. Waiting: The Process is set to waiting if it requires additional resources. Terminate: After code execution The Process is moved to a termination stage where it will eventually be removed from the main memory. 6. Process State Transition: I. New state: A process that just has been created but has not yet been admitted to the pool of execution processes by the operating system. Every new operation which is requested to the system is known as the new born process. II. Ready state: When the process is ready to execute but he is waiting for the CPU to execute then this is called as the ready state. After completion of the input and output the process will be on ready state means the process will wait for the processor to execute. III. Running state: The process that is currently being executed. When the process is running under the CPU, or when the program is executed by the CPU, then this is called as the running process and when a process is running then this will also provide us some outputs on the screen. IV. Waiting or blocked state: A process that cannot execute until some event occurs or an I/O completion. When a process is waiting for some input and output operations then this is called as the waiting state and in this process is not under the execution instead the process is stored out of memory and when the user will provide the input and then this will again be on ready state. V. Terminated state: After the completion of the process, the process will be automatically terminated by the CPU. So, this is also called as the terminated state of the process. After executing the complete process, the processor will also deallocate the memory which is allocated to the process. So, this is called as the terminated process. 7. 1) Processor Utilization: The ratio of busy time of the processor to the total time passes for & processes to finish. We would like to keep the processor as busy as possible. Processor Utilization = (Processor buy time) / (Processor busy time + Processor idle time) 2) Throughput: The measure of work done in a unit time interval. Throughput = (Number of processes completed) / (Time Unit) 3) Turnaround Time (tat): The sum of time spent waiting to get into the ready queue execution time and I/O time. tat = t (process completed) – t (process submitted) 4) Waiting Time (wt.): Time spent in ready queue. Processor scheduling algorithms only affect the time spent waiting in the ready queue. So, considering only waiting time instead of turnaround time is generally sufficient. 5) Response Time (rt): The amount of time it takes to start responding to a request. This criterion is important for interactive systems. rt = t (first response) – t (submission of request) 8. CPU Utilization o To make out the best use of the CPU and not to waste any CPU cycle, the CPU would be working most of the time (Ideally 100% of the time). Considering a real system, CPU usage should range from 40% (lightly loaded) to 90% (heavily loaded.) Throughput o It is the total number of processes completed per unit of time or rather says the total amount of work done in a unit of time. This may range from 10/second to 1/hour depending on the specific processes. Turnaround Time o It is the amount of time taken to execute a particular process, i.e. The interval from the time of submission of the process to the time of completion of the process (Wall clock time). Waiting Time o The sum of the periods spent waiting in the ready queue amount of time a process has been waiting in the ready queue to acquire get control on the CPU. OS_Assignment-2_Aman Ranjan_C.S.E/A- 1901000002122 Load Average o It is the average number of processes residing in the ready queue waiting for their turn to get into the CPU. Response Time o Amount of time it takes from when a request was submitted until the first response is produced. Remember, it is the time till the first response and not the completion of process execution (final response). In general CPU utilization and Throughput are maximized and other factors are reduced for proper optimization. 9. Ready Queue - P3, P1, P4, P2, P3, P6, P1, P4, P2, P3, P5, P4 Gantt Chart - Turn Around time = Exit time – Arrival time Waiting time = Turn Around time – Burst time Average Turn Around time = (27 + 23 + 30 + 29 + 4 + 15) / 6 = 128 / 6 = 21.33 unit Average waiting time = (22 + 17 + 23 + 20 + 2 + 12) / 6 = 96 / 6 = 16 unit 10. Rate monotonic scheduling is a priority algorithm that belongs to the static priority scheduling category of Real Time Operating Systems. It is preemptive in nature. The priority is decided according to the cycle time of the processes that are involved. If the process has a small job duration, then it has the highest priority. Thus, if a process with highest priority starts execution, it will preempt the other running processes. The priority of a process is inversely proportional to the period it will run for. 𝑪𝒊 A set of processes can be scheduled only if they satisfy the following equation: ∑𝜼𝚱=𝟏 𝑻𝒊 ≤ 𝑼 = 𝜼(𝟐𝟏/𝒏 − 𝟏) Where n is the number of processes in the process set, Ci is the computation time of the process, Ti is the Time period for the process to run and U is the processor utilization.