Interrupts
Interrupts
Whenever an interrupt occurs, it causes the CPU to stop executing the current
program. Then, comes the control to interrupt handler or interrupt service routine.
These are the steps in which ISR handles interrupts. These are as follows −
Step 2 − When an interrupt occurs the program value is stored on the process
stack and the program counter is loaded with the address of interrupt service
routine.
Step 3 − Once the interrupt service routine is completed the address on the
process stack is popped and placed back in the program counter.
•An operating system acts as an intermediary between the user of a computer and
computer hardware. The purpose of an operating system is to provide an
environment in which a user can execute programs conveniently and efficiently.
•An operating system (OS) is system software that manages computer hardware,
software resources, and provides common services for computer programs.
•A more common definition is that the operating system is the one program
running at all times on the computer (usually called the kernel), with all else being
application programs.
Objectives of Operating system
● Heap: This is dynamically allocated memory to a process during its run time.
● Text: This includes the current activity represented by the value of Program Counter and the
contents of the processor's registers.
● Ready: The process is waiting to be assigned to a processor. Ready processes are waiting to have the
processor allocated to them by the operating system so that they can run. Process may come into this state
after Start state or while running it by but interrupted by the scheduler to assign CPU to some other process.
● Running: Once the process has been assigned to a processor by the OS scheduler, the process state is set
to running and the processor executes its instructions.
● Waiting: Process moves into the waiting state if it needs to wait for a resource, such as waiting for user
input, or waiting for a file to become available.
● Terminated or Exit: Once the process finishes its execution, or it is terminated by the operating system, it is
moved to the terminated state where it waits to be removed from main memory.
Process Control Block (PCB)
● A Process Control Block is a data structure maintained by the Operating
System for every process. The PCB is identified by an integer process ID
(PID). A PCB keeps all the information needed to keep track of a process
PCB
Information associated with each process
(also called task control block)
● Process state – running, waiting, etc.
● Program counter – location of instruction to next execute
● CPU registers – contents of all process-centric registers
● CPU scheduling information- priorities, scheduling queue pointers
● Memory-management information – memory allocated to the process
● Accounting information – CPU used, clock time elapsed since start, time limits
● I/O status information – I/O devices allocated to process, list of open files
Two state process model
● The simplest model in the process state will be a two-state model as it consists of only two states
that are given below:
● Running State- A state in which the process is currently being executed.
● Not Running State- A state in which the process is waiting for execution.
Queuing Diagram
Process State of five state model
● As a process executes, it changes state
○ new: The process is being created
○ running: Instructions are being executed
○ waiting: The process is waiting for some event to occur
○ ready: The process is waiting to be assigned to a processor
○ terminated: The process has finished execution
Diagram of Process States
Process States of five state model
1.New: A program which is going to be picked up by the OS into the main memory is called a new
process.
2. Ready: Whenever a process is created, it directly enters in the ready state, in which, it waits for the
CPU to be assigned. The OS picks the new processes from the secondary memory and put all of them in
the main memory.
The processes which are ready for the execution and reside in the main memory are called ready state
processes. There can be many processes present in the ready state.
3. Running: One of the processes from the ready state will be chosen by the OS depending upon the
scheduling algorithm. Hence, if we have only one CPU in our system, the number of running processes for
a particular time will always be one. If we have n processors in the system then we can have n processes
running simultaneously.
4. Block or wait
● From the Running state, a process can make the transition to the block or wait state depending
upon the scheduling algorithm or the intrinsic behavior of the process.
● When a process waits for a certain resource to be assigned or for the input from the user then the
OS move this process to the block or wait state and assigns the CPU to the other processes.
5. Completion or termination
● When a process finishes its execution, it comes in the termination state. All the context of the
process (Process Control Block) will also be deleted the process will be terminated by the Operating
system.
6. Suspend ready
● A process in the ready state, which is moved to secondary memory from the main memory due to
lack of the resources (mainly primary memory) is called in the suspend ready state.
● If the main memory is full and a higher priority process comes for the execution then the OS have to
make the room for the process in the main memory by throwing the lower priority process out into
the secondary memory. The suspend ready processes remain in the secondary memory until the
main memory gets available.
7. Suspend wait
● Instead of removing the process from the ready queue, it's better to remove the blocked process
which is waiting for some resources in the main memory. Since it is already waiting for some
resource to get available hence it is better if it waits in the secondary memory and make room for
the higher priority process. These processes complete their execution once the main memory gets
available and their wait is finished.