Multiprogramming and multithreading....which of these are better
multiprogramming multitasking multiprocessing multithreading pptMultiprogramming is used for improving CPU utilization. We know that in uni programming or mono programming only one process is executed at one time i.e. program loaded and executed at the command typed by the user and after the completion of process Operating System gives control back to the user by prompting on the terminal and wait for the next command.
Although mono programming is sometimes used on small computers but on large computers with multiple users it is not used. Reasons for Multiprogramming
• Applications are made easier to program if we split them into two or more processes.
• Large computers are used by several people which leads to the presence of more than one process in the memory.
• Large computers are very expensive, so if CPU remains idle, precious time of CPU is wasted. To utilize the CPU more efficiently more processes need to be in the memory, so that if one process waits another may be given the control of CPU.
In mono programming, if a process is waiting for an I/O to complete and it takes 40msec to complete the I/O operation and the computation takes 10msec then the CPU was idle waiting for I/O operation to complete 80 percent of the time.
CPU Utilization = [ ( CPU Time / Total time ) x 100 ] CPU Utilization = [ ( 10 / 50 ) x 100 ]
CPU Utilization = 20 %
CPU Wastage = [ ( I/O Time / Total time ) x 100 ] CPU Wastage = [ ( 40 / 50 ) x 100 ]
CPU Wastage = 80 %
Calculate CPU Utilization and CPU Wastage of the following timeline of processes.
In multiprogramming, CPU will not sit idle, as the Operating System will switch it to the next job. When that job needs to wait, the CPU will again be switched to another job, and so on.
Process / Job execution in Multi-Programmed Operating System
CPU Utilization = {[CPU Times of P1 + P2 + P3 + P4 / Total Time (CPU + I/O)] x 100} CPU Utilization = [(12 + 6 + 4 + 8 / 36 ) x 100]
CPU Utilization = 83.33 %
Calculate CPU Utilization and CPU Wastage of the following timeline of processes.
In multiprogramming CPU sits idle only when there is no job to execute.
Multiprogramming is done in two ways.
- Multiprogramming with Fixed partition.
- Multiprogramming with Variable partition.