SlideShare a Scribd company logo
1 of 26
Operating System Concepts and Techniques

Multiprogramming, Multithreading,
Multiprocessing, and Multitasking
Gaurav Meena
Assistant Professor
Department of Computer Science
Definitions
Program: a set of instructions which is
prepared to perform a specific
assignment if executed by a computer.
Program need not be connected; it
could be stored on a flash memory and
placed in one’s pocket.
Program is not an active entity. It is
completely passive.
2
Definitions…
Process: is created by operating system from
a program


To do so, it has to perform many activities, like
assigning a name, allocating space, (partially)
loading the corresponding program, etc.

Roughly speaking, A process is an active
program
A process is created to run a program by
using computer facilities such as CPU; like a
human who is born to live his life

3
Single programming
Single-programming: there exist at the most one user
process at any given time in the computer; thus there is
usually one ongoing activity at a time


That is, from many devices within the computer often one device
is active at any given time
 If a process has asked for a data from the user, the system has
to wait until this data is entered before being able to proceed
 If this data entry takes one second the CPU could have done
millions of instructions if it did not have to wait

With single-programming the computer resources are not
used efficiently

4
Process States in Single-Programming
With single-programming, right after a process is born the
system starts running it
It continues until the process has to wait for data, output results,
or wait for an event
There are special purpose processors called Input/Output (I/O)
processors for transferring data from input devices to main
memory and from main memory to output devices


It is understandable that such a processor will perform the specific
task better than a general-purpose processor, i.e., CPU

While an I/O operation is in progress, the CPU has to wait and
do nothing. After the I/O operation is completed, the CPU will
resume the execution of the program
This cycle, of going through process states of running and
input/output, may be repeated over and over, until the job is
completed or, for some reason, the process is aborted
The life cycle of a process in a single-programming environment
is shown in Figure 1
5
Process’s life cycle
Process
birth

Blocked for
I/O
Running

Input/Output

I/O completed

Process
Termination

Figure 1: The life cycle of a process in single-programming environments
6
Processor wait ratio
If the average execution time of a program with
single-programming is e and the average I/O
time is b, then the following ratio is the CPU wait
fraction (w). It is actually the fraction of the time
the CPU is idle.
b
w=

e+b

For example, if execution time of programs is
10, of which 9 seconds is spent on I/O, then w =
9/10 = 0.9. This means, on the average, 90% of
the CPU time is wasted.
7
The Multiprogramming Concept
Multiprogramming: is a technique that allows more
than one program to be ready for execution (process)
and provides the ability to switch from one process to
another, even if the former is not completed


Of course, sometimes in the future we will have to switch
back to the first process and resume (not restart) its
computation

This technique works for both single-processor (like
some personal computers) and multiprocessor (such
as large main frame) computers.
Multiprogramming is mainly accomplished by the
operating system. The hardware provides some
specific circuitry that may be used by the operating
system in the course of facilitating multiprogramming

8
Multiprogramming and PCs
Do we need multiprogramming for PCs? Yes. All PC
users like to run many applications simultaneously


Nobody runs for example an Internet explorer looking for an
information while staring at the monitor for the results for a
long time.

In this era of computer usage, every general-purpose
operating system must have the following capabilities:

It must provide an environment to run processes in a
multiprogramming fashion.
 It must act as a service provider for all common services that
are usually needed by computer users, such as copying files,
making new folders, compressing information, sending and
receiving messages from/to other computers in the network,
etc.
 Its user interface must be easy to use and pleasant to work
with.


9
Multiprogramming productivity
Multiprogramming increases productivity
If CPU wait time is represented by w in singleprogramming environment, the CPU wait time
decreases to approximately wn for a system
running n processes simultaneously.
 Example: If w = .9 then wn =0.59 ; meaning that if
we have five processes running simultaneously, the
CPU utilization is increased by (0.41-.10)/0.1*100 =
310%.


By increasing the CPU utilization other device’s
utilization is also increased.
10
Process State Transition Diagram
The life cycle of a process in multiprogramming has three states



Ready: ready to use CPU, however CPU is busy
 Running: Uses CPU
 Wait/Blocked
 Wait: process is waiting for a device or an event

 Blocked: process is waiting for its I/O to be completed by

an I/O processor

May switch between states many times during
its life

11
Process’s life cycle
Process
Termination
Running
A process is
picked to run

Preempted for the
interest of others

Needs I/O or
circumstance

Process birth
Wait/Blocked

Ready

Running obstacle is
vanished

Figure 2: Basic process state transition diagram in multiprogramming
12
Requirements of Multiprogramming
Process Switching possibility: the system must be
able to safely switch from one process to another and
be able to return in the future
 This is called context switching.
Direct Memory Access: I/O processors must be able
to directly access main memory without interference
and conflictions
The Interrupt System: I/O processors and monitoring
devices must be able to safely communicate with the
CPU to report or to get new assignments

13
To context switch
Save enough information from current
process to be able to return to it and continue
Save all temporary storage information such
as registers and flags
Load/initialize the information of new process
Change PC
Need some help from Hardware to make the
switching process fast

14
Interrupt
Interrupt: a signal that is sent to the CPU to
capture its attention. It may be issued by
different sources such as:

By a fault detecting hardware that is trying to
informs the CPU of a circuitry malfunction
By a monitoring circuit within the ALU that controls
the acceptability of the data size for the operation
being performed and, consequently, the operation
result size
By a user that may press a special key like “break”
at any time
 By an slave processor that wants to inform the
CPU of the completion of the assigned task
 By a timer etc.






15
Interrupt masking
Some interrupts are maskable by user
programs
Masked interrupts are ignored by the CPU


This is analogous to ignoring a door knock

Some interrupts are not user-maskable


It is not reasonable to let the computer continue in
the presence of a hardware failure.

However, all interrupts are maskable within
the kernel of an operating system.

16
Interrupt Categorization
Interrupts are categorized into few classes
Different classes of interrupts require different
handling consideration
Each category of interrupts is represented by a
bit in interrupt vector within the CPU
Each interrupt category has a priority
When handling a higher priority interrupt
handling any lower priority interrupt is
postponed
17
Program execution suspension
A non-masked interrupt causes the suspension of the
currently executing program.
Usually possible to resume the execution of the program
after the interrupt is handled.
Interrupt signals reach the CPU and are stored in the
interrupt vector. The interrupt(s) is ignored until the
currently executing machine instruction is completed.
There are very few exceptions. One example might be the
“move” instruction in some computers that is suppose to
move a big chunk, say 256 bytes, of data from one location
of main memory to another.
The CPU always looks for interrupt signals just before
fetching a new instruction to execute. If there are any
interrupt signals, the system handles them in the order of
priorities and urgencies.
18
Fetch-Execute Cycle with interrupt
Fetch cycle
Handle all non-masked interrupts

Read the instruction pointed out
by the Program Counter (PC)
register from main memory and
move it to the CPU
Find out what this instruction is

Execute cycle
Move the data upon which the
instruction has to be executed from
main memory to the CPU.

Execute the instruction, i.e.,
perform what is requested by the
instruction. Perhaps this may
readjust the PC.

Adjust PC for the next instruction

Figure 4: A simplified functional model of a computer with interrupt
19
Privileged instructions
Privileged instructions are those which are not
usable by assembly application programmers
Privileged instructions are executable only
within the operating system kernel
Other parts of the OS and application
programmers may execute privileged
instruction by special means that are provided
by the operating system
Disable interrupt which disables all interrupts
is a sample privileged instruction
20
Multiprocessing
If you think clearly, you will notice that we
should have used multiprocessing instead of
multiprogramming. This is true. Unfortunately,
the term “multiprogramming” is recognized for
this technique of the operating system and we
will stick to it
On the other hand, “multiprocessing” is used
for systems with more than one processor.
Processors, in such a system, can collectively
run many tasks simultaneously
21
Multitasking
Computer users like to have many application programs simultaneously
operational. This is necessary because some application programs
require long processing times before the desired results can be
produced.
It is true that by having more than one application program operational,
the time that it takes for each process to complete its task increases.
However, the overall system productivity
These simultaneously executing programs are called tasks . Therefore,
a system with the capability of multitasking allows users to activate
more than one task, or application program, at a time. An Internet
browser that searches for some information and A word-processing
software that is activated to perform the word-processing task are
applications.
The operating system will switch between tasks based on the tasks
current states and their requirements and priorities.
Multitasking is only possible when multiprogramming is the
fundamental capability of simultaneously executing pieces of software.
Most modern operating systems, like UNIX, Linux, and Windows,
support multitasking.

22
Multithreading
A multithreading operating system is one that is capable of
handling processes and threads at the same time and in which
from each process the system is able to generate more than one
thread.
In such an operating system, there must be facilities for thread
creation, deletion, switching, etc.
Such an operating system allows users to generate more than
one request to a process at a time. For example, a browser can
be made to search simultaneously for more than one topic, even
though there is only one copy of the “browser program” in main
memory.
The multiprogramming methodology and technique are essential
in the implementation of multithreading. In this new environment,
a thread becomes the smallest functional object to which CPU
(or a PU) is assigned.

23
Summary
The ultimate goal in the design and implementation of an operating
system is to produce a handy software program that manages computer
resources in the most efficient way so as to serve computer users
correctly, reliably and fairly.
This is not achievable in single-programming environments.
Modern operating systems are built with the capabilities of
multiprogramming, multitasking, and multithreading.
Providing these capabilities requires many hardware and software
methodologies and techniques.
A good understanding of process creation, life cycle, and termination,
along with its state transition conditions is most essential in elucidating
the needs of different mechanisms within the operating system.
Some of these mechanisms, namely process switching, interrupt system
and handling, and direct memory access, are briefly explained in this
chapter.
Multithreading, as an offspring of multiprogramming, has become an
essential part of all modern operating systems.

24
Find out
How many interrupt classes your computer’s
processor has
Some privileged instructions and the reasons
for being privileged
How are interrupts actually masked
The exact differences of multiprogramming
and multiprocessing
What an ultra DMA is
The exact differences between program and
process
25
Any questions?

26

More Related Content

What's hot

Indexing structure for files
Indexing structure for filesIndexing structure for files
Indexing structure for filesZainab Almugbel
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMSkoolkampus
 
Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentationhamza haseeb
 
Locking base concurrency control
  Locking base concurrency control  Locking base concurrency control
Locking base concurrency controlPrakash Poudel
 
File systems versus a dbms
File systems versus a dbmsFile systems versus a dbms
File systems versus a dbmsRituBhargava7
 
Distributed Database System
Distributed Database SystemDistributed Database System
Distributed Database SystemSulemang
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed SystemsRupsee
 
Memory management
Memory managementMemory management
Memory managementcpjcollege
 
Register transfer language
Register transfer languageRegister transfer language
Register transfer languageSanjeev Patel
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentationusmankiyani1
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computingSVijaylakshmi
 
Multi Processors And Multi Computers
 Multi Processors And Multi Computers Multi Processors And Multi Computers
Multi Processors And Multi ComputersNemwos
 

What's hot (20)

Indexing structure for files
Indexing structure for filesIndexing structure for files
Indexing structure for files
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS
 
DDBMS Paper with Solution
DDBMS Paper with SolutionDDBMS Paper with Solution
DDBMS Paper with Solution
 
cache memory
cache memorycache memory
cache memory
 
Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentation
 
Locking base concurrency control
  Locking base concurrency control  Locking base concurrency control
Locking base concurrency control
 
Mutual exclusion and sync
Mutual exclusion and syncMutual exclusion and sync
Mutual exclusion and sync
 
File systems versus a dbms
File systems versus a dbmsFile systems versus a dbms
File systems versus a dbms
 
Ch09
Ch09Ch09
Ch09
 
Distributed Database System
Distributed Database SystemDistributed Database System
Distributed Database System
 
Dbms architecture
Dbms architectureDbms architecture
Dbms architecture
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
 
Ordbms
OrdbmsOrdbms
Ordbms
 
Database Management System ppt
Database Management System pptDatabase Management System ppt
Database Management System ppt
 
Memory management
Memory managementMemory management
Memory management
 
Register transfer language
Register transfer languageRegister transfer language
Register transfer language
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computing
 
Multi Processors And Multi Computers
 Multi Processors And Multi Computers Multi Processors And Multi Computers
Multi Processors And Multi Computers
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 

Viewers also liked

Viewers also liked (20)

Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
Operating system; Multitasking
Operating system; MultitaskingOperating system; Multitasking
Operating system; Multitasking
 
Preprocessors
Preprocessors Preprocessors
Preprocessors
 
Preprocessor in C
Preprocessor in CPreprocessor in C
Preprocessor in C
 
Threads and multi threading
Threads and multi threadingThreads and multi threading
Threads and multi threading
 
Basic concept
Basic conceptBasic concept
Basic concept
 
Unit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - ThreadsUnit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - Threads
 
pipelining
pipeliningpipelining
pipelining
 
Understanding memory management
Understanding memory managementUnderstanding memory management
Understanding memory management
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
process management
 process management process management
process management
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Multithreading Concepts
Multithreading ConceptsMultithreading Concepts
Multithreading Concepts
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
 
pipelining
pipeliningpipelining
pipelining
 
Chapter 5 Process Management
Chapter 5 Process ManagementChapter 5 Process Management
Chapter 5 Process Management
 
Process management
Process managementProcess management
Process management
 
Memory management
Memory managementMemory management
Memory management
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
Operating Systems and Memory Management
Operating Systems and Memory ManagementOperating Systems and Memory Management
Operating Systems and Memory Management
 

Similar to Operatingsystems lecture2

Operating System and related questions
Operating System and related questionsOperating System and related questions
Operating System and related questionsimdurgesh
 
Lecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdfLecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdfTaufeeq8
 
Os files 2
Os files 2Os files 2
Os files 2Amit Pal
 
3330701_unit-1_operating-system-concepts.pdf
3330701_unit-1_operating-system-concepts.pdf3330701_unit-1_operating-system-concepts.pdf
3330701_unit-1_operating-system-concepts.pdfrohitbaweja26
 
Operating System
Operating SystemOperating System
Operating Systemguest8b0942
 
Operating system
Operating systemOperating system
Operating systemMark Muhama
 
Fundamentals of operating system
Fundamentals of operating systemFundamentals of operating system
Fundamentals of operating systemJayesh Chauhan
 
Advanced computer architecture lesson 1 and 2
Advanced computer architecture lesson 1 and 2Advanced computer architecture lesson 1 and 2
Advanced computer architecture lesson 1 and 2Ismail Mukiibi
 
OPERATING SYSTEM - SHORT NOTES
OPERATING SYSTEM - SHORT NOTESOPERATING SYSTEM - SHORT NOTES
OPERATING SYSTEM - SHORT NOTESsuthi
 
Ch2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.pptCh2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.pptMohammad Almuiet
 
LM1 - Computer System Overview, system calls
LM1 - Computer System Overview, system callsLM1 - Computer System Overview, system calls
LM1 - Computer System Overview, system callsmanideepakc
 
Operating Systems Unit Two - Fourth Semester - Engineering
Operating Systems Unit Two - Fourth Semester - EngineeringOperating Systems Unit Two - Fourth Semester - Engineering
Operating Systems Unit Two - Fourth Semester - EngineeringYogesh Santhan
 
OS - Ch1
OS - Ch1OS - Ch1
OS - Ch1sphs
 

Similar to Operatingsystems lecture2 (20)

Operating system
Operating systemOperating system
Operating system
 
Operating System and related questions
Operating System and related questionsOperating System and related questions
Operating System and related questions
 
Lecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdfLecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdf
 
Os files 2
Os files 2Os files 2
Os files 2
 
3330701_unit-1_operating-system-concepts.pdf
3330701_unit-1_operating-system-concepts.pdf3330701_unit-1_operating-system-concepts.pdf
3330701_unit-1_operating-system-concepts.pdf
 
Operating System
Operating SystemOperating System
Operating System
 
Os unit 1
Os unit 1Os unit 1
Os unit 1
 
Operating system
Operating systemOperating system
Operating system
 
Ch1
Ch1Ch1
Ch1
 
Fundamentals of operating system
Fundamentals of operating systemFundamentals of operating system
Fundamentals of operating system
 
Advanced computer architecture lesson 1 and 2
Advanced computer architecture lesson 1 and 2Advanced computer architecture lesson 1 and 2
Advanced computer architecture lesson 1 and 2
 
Firo
FiroFiro
Firo
 
OPERATING SYSTEM - SHORT NOTES
OPERATING SYSTEM - SHORT NOTESOPERATING SYSTEM - SHORT NOTES
OPERATING SYSTEM - SHORT NOTES
 
Ch2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.pptCh2_Processes_and_process_management_1.ppt
Ch2_Processes_and_process_management_1.ppt
 
LM1 - Computer System Overview, system calls
LM1 - Computer System Overview, system callsLM1 - Computer System Overview, system calls
LM1 - Computer System Overview, system calls
 
OS-Process.pdf
OS-Process.pdfOS-Process.pdf
OS-Process.pdf
 
Operating Systems Unit Two - Fourth Semester - Engineering
Operating Systems Unit Two - Fourth Semester - EngineeringOperating Systems Unit Two - Fourth Semester - Engineering
Operating Systems Unit Two - Fourth Semester - Engineering
 
Operating System.ppt
Operating System.pptOperating System.ppt
Operating System.ppt
 
Unit 2 notes
Unit 2 notesUnit 2 notes
Unit 2 notes
 
OS - Ch1
OS - Ch1OS - Ch1
OS - Ch1
 

Operatingsystems lecture2

  • 1. Operating System Concepts and Techniques Multiprogramming, Multithreading, Multiprocessing, and Multitasking Gaurav Meena Assistant Professor Department of Computer Science
  • 2. Definitions Program: a set of instructions which is prepared to perform a specific assignment if executed by a computer. Program need not be connected; it could be stored on a flash memory and placed in one’s pocket. Program is not an active entity. It is completely passive. 2
  • 3. Definitions… Process: is created by operating system from a program  To do so, it has to perform many activities, like assigning a name, allocating space, (partially) loading the corresponding program, etc. Roughly speaking, A process is an active program A process is created to run a program by using computer facilities such as CPU; like a human who is born to live his life 3
  • 4. Single programming Single-programming: there exist at the most one user process at any given time in the computer; thus there is usually one ongoing activity at a time  That is, from many devices within the computer often one device is active at any given time  If a process has asked for a data from the user, the system has to wait until this data is entered before being able to proceed  If this data entry takes one second the CPU could have done millions of instructions if it did not have to wait With single-programming the computer resources are not used efficiently 4
  • 5. Process States in Single-Programming With single-programming, right after a process is born the system starts running it It continues until the process has to wait for data, output results, or wait for an event There are special purpose processors called Input/Output (I/O) processors for transferring data from input devices to main memory and from main memory to output devices  It is understandable that such a processor will perform the specific task better than a general-purpose processor, i.e., CPU While an I/O operation is in progress, the CPU has to wait and do nothing. After the I/O operation is completed, the CPU will resume the execution of the program This cycle, of going through process states of running and input/output, may be repeated over and over, until the job is completed or, for some reason, the process is aborted The life cycle of a process in a single-programming environment is shown in Figure 1 5
  • 6. Process’s life cycle Process birth Blocked for I/O Running Input/Output I/O completed Process Termination Figure 1: The life cycle of a process in single-programming environments 6
  • 7. Processor wait ratio If the average execution time of a program with single-programming is e and the average I/O time is b, then the following ratio is the CPU wait fraction (w). It is actually the fraction of the time the CPU is idle. b w= e+b For example, if execution time of programs is 10, of which 9 seconds is spent on I/O, then w = 9/10 = 0.9. This means, on the average, 90% of the CPU time is wasted. 7
  • 8. The Multiprogramming Concept Multiprogramming: is a technique that allows more than one program to be ready for execution (process) and provides the ability to switch from one process to another, even if the former is not completed  Of course, sometimes in the future we will have to switch back to the first process and resume (not restart) its computation This technique works for both single-processor (like some personal computers) and multiprocessor (such as large main frame) computers. Multiprogramming is mainly accomplished by the operating system. The hardware provides some specific circuitry that may be used by the operating system in the course of facilitating multiprogramming 8
  • 9. Multiprogramming and PCs Do we need multiprogramming for PCs? Yes. All PC users like to run many applications simultaneously  Nobody runs for example an Internet explorer looking for an information while staring at the monitor for the results for a long time. In this era of computer usage, every general-purpose operating system must have the following capabilities: It must provide an environment to run processes in a multiprogramming fashion.  It must act as a service provider for all common services that are usually needed by computer users, such as copying files, making new folders, compressing information, sending and receiving messages from/to other computers in the network, etc.  Its user interface must be easy to use and pleasant to work with.  9
  • 10. Multiprogramming productivity Multiprogramming increases productivity If CPU wait time is represented by w in singleprogramming environment, the CPU wait time decreases to approximately wn for a system running n processes simultaneously.  Example: If w = .9 then wn =0.59 ; meaning that if we have five processes running simultaneously, the CPU utilization is increased by (0.41-.10)/0.1*100 = 310%.  By increasing the CPU utilization other device’s utilization is also increased. 10
  • 11. Process State Transition Diagram The life cycle of a process in multiprogramming has three states  Ready: ready to use CPU, however CPU is busy  Running: Uses CPU  Wait/Blocked  Wait: process is waiting for a device or an event  Blocked: process is waiting for its I/O to be completed by an I/O processor May switch between states many times during its life 11
  • 12. Process’s life cycle Process Termination Running A process is picked to run Preempted for the interest of others Needs I/O or circumstance Process birth Wait/Blocked Ready Running obstacle is vanished Figure 2: Basic process state transition diagram in multiprogramming 12
  • 13. Requirements of Multiprogramming Process Switching possibility: the system must be able to safely switch from one process to another and be able to return in the future  This is called context switching. Direct Memory Access: I/O processors must be able to directly access main memory without interference and conflictions The Interrupt System: I/O processors and monitoring devices must be able to safely communicate with the CPU to report or to get new assignments 13
  • 14. To context switch Save enough information from current process to be able to return to it and continue Save all temporary storage information such as registers and flags Load/initialize the information of new process Change PC Need some help from Hardware to make the switching process fast 14
  • 15. Interrupt Interrupt: a signal that is sent to the CPU to capture its attention. It may be issued by different sources such as: By a fault detecting hardware that is trying to informs the CPU of a circuitry malfunction By a monitoring circuit within the ALU that controls the acceptability of the data size for the operation being performed and, consequently, the operation result size By a user that may press a special key like “break” at any time  By an slave processor that wants to inform the CPU of the completion of the assigned task  By a timer etc.    15
  • 16. Interrupt masking Some interrupts are maskable by user programs Masked interrupts are ignored by the CPU  This is analogous to ignoring a door knock Some interrupts are not user-maskable  It is not reasonable to let the computer continue in the presence of a hardware failure. However, all interrupts are maskable within the kernel of an operating system. 16
  • 17. Interrupt Categorization Interrupts are categorized into few classes Different classes of interrupts require different handling consideration Each category of interrupts is represented by a bit in interrupt vector within the CPU Each interrupt category has a priority When handling a higher priority interrupt handling any lower priority interrupt is postponed 17
  • 18. Program execution suspension A non-masked interrupt causes the suspension of the currently executing program. Usually possible to resume the execution of the program after the interrupt is handled. Interrupt signals reach the CPU and are stored in the interrupt vector. The interrupt(s) is ignored until the currently executing machine instruction is completed. There are very few exceptions. One example might be the “move” instruction in some computers that is suppose to move a big chunk, say 256 bytes, of data from one location of main memory to another. The CPU always looks for interrupt signals just before fetching a new instruction to execute. If there are any interrupt signals, the system handles them in the order of priorities and urgencies. 18
  • 19. Fetch-Execute Cycle with interrupt Fetch cycle Handle all non-masked interrupts Read the instruction pointed out by the Program Counter (PC) register from main memory and move it to the CPU Find out what this instruction is Execute cycle Move the data upon which the instruction has to be executed from main memory to the CPU. Execute the instruction, i.e., perform what is requested by the instruction. Perhaps this may readjust the PC. Adjust PC for the next instruction Figure 4: A simplified functional model of a computer with interrupt 19
  • 20. Privileged instructions Privileged instructions are those which are not usable by assembly application programmers Privileged instructions are executable only within the operating system kernel Other parts of the OS and application programmers may execute privileged instruction by special means that are provided by the operating system Disable interrupt which disables all interrupts is a sample privileged instruction 20
  • 21. Multiprocessing If you think clearly, you will notice that we should have used multiprocessing instead of multiprogramming. This is true. Unfortunately, the term “multiprogramming” is recognized for this technique of the operating system and we will stick to it On the other hand, “multiprocessing” is used for systems with more than one processor. Processors, in such a system, can collectively run many tasks simultaneously 21
  • 22. Multitasking Computer users like to have many application programs simultaneously operational. This is necessary because some application programs require long processing times before the desired results can be produced. It is true that by having more than one application program operational, the time that it takes for each process to complete its task increases. However, the overall system productivity These simultaneously executing programs are called tasks . Therefore, a system with the capability of multitasking allows users to activate more than one task, or application program, at a time. An Internet browser that searches for some information and A word-processing software that is activated to perform the word-processing task are applications. The operating system will switch between tasks based on the tasks current states and their requirements and priorities. Multitasking is only possible when multiprogramming is the fundamental capability of simultaneously executing pieces of software. Most modern operating systems, like UNIX, Linux, and Windows, support multitasking. 22
  • 23. Multithreading A multithreading operating system is one that is capable of handling processes and threads at the same time and in which from each process the system is able to generate more than one thread. In such an operating system, there must be facilities for thread creation, deletion, switching, etc. Such an operating system allows users to generate more than one request to a process at a time. For example, a browser can be made to search simultaneously for more than one topic, even though there is only one copy of the “browser program” in main memory. The multiprogramming methodology and technique are essential in the implementation of multithreading. In this new environment, a thread becomes the smallest functional object to which CPU (or a PU) is assigned. 23
  • 24. Summary The ultimate goal in the design and implementation of an operating system is to produce a handy software program that manages computer resources in the most efficient way so as to serve computer users correctly, reliably and fairly. This is not achievable in single-programming environments. Modern operating systems are built with the capabilities of multiprogramming, multitasking, and multithreading. Providing these capabilities requires many hardware and software methodologies and techniques. A good understanding of process creation, life cycle, and termination, along with its state transition conditions is most essential in elucidating the needs of different mechanisms within the operating system. Some of these mechanisms, namely process switching, interrupt system and handling, and direct memory access, are briefly explained in this chapter. Multithreading, as an offspring of multiprogramming, has become an essential part of all modern operating systems. 24
  • 25. Find out How many interrupt classes your computer’s processor has Some privileged instructions and the reasons for being privileged How are interrupts actually masked The exact differences of multiprogramming and multiprocessing What an ultra DMA is The exact differences between program and process 25