You are on page 1of 6

What happens when interrupt occurs?

The interrupt causes the transfer of control to the


appropriate interrupt service routine program. The address of the interrupted instruction must then
be saved.While an interrupt is serviced, typically other interrupts are disabled.Events are signaled to
the operating system by interrupts or traps. A trap or exception is a software generated interrupt,
that is caused by an error or a user request such as writing some value in some memory location.
How are interrupts handled? When an interrupt occurs the hardware transfers thecontrol to
operating system. The operating system preserves the state of the CPU by storing the registers which
are special data storage and manipulation areas on the microprocessor. This includes the Program
Counter (PC) register, which keeps track of the address of the next instruction to be loaded into the
instruction register (IR). Types of Interrupts Hardware - AsynchronousDevice informs CPU that
something has happened e.g. a key has been pressed on the keyboard.Hardware - SynchronousCPU
has tried to do something that has caused the interrupt. e.g. tried to read from an invalid memory
location. (This is not always a problem, it may just mean that the needed data is on disk and needs to
be fetched).SoftwareA software interrupt occurs when an application program terminates or
requests certain services from the OS.Interrupt Handling Interrupt handling is a very important part
of the operating system.Before turning control over to an interrupt handler, the operating system
must preserve the state of the CPU by storing all registers.Determine which type of interrupt has
occurred:by polling - ask each device if it caused the interrupt orby vectored interrupt system -
device identifies itself when it causes the intrruptDetermine which I/O device caused the interrupt,
then index into the device table for that device, and modify the table entry to reflect the occurrence
of the interrupt.Separate segments of code determine what action should be taken for each type of
interrupt. Synchronous or Blocking I/O: Once synchronous I/O started, then control returns to user
program only upon I/O completion. The CPU sits idle or waiting for an interrupt, and only one
interrupt can take place, i.e. after the I/O. completion. Asynchronous or Non-Blocking I/O: After I/O
starts, control returns to user program without waiting for I/O completion. Direct Memory Access
(DMA) Structure DMA stands for “Direct Memory Access” and is a method of transferring data from
the computer‘s RAM to another part of the computer without processing it using the CPU.While
most data that is input or output from your computer is processed by the CPU, some data does not
require processing, or can be processed by another device.In these situations, DMA can save
processing time and is a more efficient way to move data from the computer’s memory to other
devices. DMA is used for high speed I/O devices that are able to transmit information at close to
memory speeds. For example, a PCI controller and a hard drive controller each have their own set of
DMA channels. Storage Structure Main memory is the only large storage media that the CPU can
access directly. This is done through the instruction cycle:Fetch: Get an instruction from memory,
store it in instruction register (IR), and increment the Program Counter (PC).(An instruction register
holds a machine instruction that is currently being executed.)A program counter is a register in a
computer processor that contains the address (location) of the instruction being executed at the
current time.)Execute: Decode and execute instruction, possibly fetching the operands and storing in
internal registers Registers In Computer Architecture, the Registers are very fast computer memory
which are used to execute programs and operations efficiently. The sole purpose of having register is
fast retrieval of data for processing by CPU. Though accessing instructions from RAM is
comparatively faster with hard drive, it still isn’t enough for CPU. Types of regiters Memory Address
Registers (MAR): It holds the address of the location to be accessed from memory. MAR and MDR
(Memory Data Register) together facilitate the communication of the CPU and the main memory.
Memory Data Registers (MDR): It contains data to be written into or to be read out from the
addressed location. Program Counter (PC): Program Counter (PC) is used to keep the track of
execution of the program. It contains the memory address of the next instruction to be
fetched.Instruction Register (IR): The IR holds the instruction which is just about to be executed. The
instruction from PC is fetched and stored in IR. Cache Memory Cache Memory is a special very high-
speed memory. It is used to speed up and synchronize with high-speed CPU. Cache memory is
costlier than main memory or disk memory but more economical than CPU registers. Electronic Disk
Energy Efficiency: Due to an HDD’s dependency on lots of mechanical operations, it’s power-hungry
storage. In contrast, SSDs are more energy-efficient and consume less power, prolonging battery
life.No Overheating: SSDs are more heat-resistant, whereas HDDs tend to overheat, compromising
the system’s overall performance.Build: Having no moving parts gives an SSD an edge over HDD in
terms of durability. It’s a more reliable storage device, doesn’t vibrate, and can endure shocks, which
HDD can’t. SSDs are also quiet, whereas HDDs are noisy.Weight: SSDs are lightweight compared to
HDDs, making them more efficient in performance and functionality. Difference between Magnetic
Disk and Optical Disk Magnetic disk: A magnetic disk is a storage device that uses a magnetization
process to read, write, rewrite and access data. The Magnetic disk is made of a set of circular
platters. It is covered with a magnetic coating and stores data in the form of tracks, spots, and
sectors. Optical disk: An optical disk is any computer disk that uses optical storage techniques and
technology to read and write data. It is a storage device for optical (light) energy. It is a computer
storage disk that stores data digitally and uses laser beams to read and write data. Operating System
Services An operating system provides an environment for the execution of programs.It provides
certain services to programs and to the users of those programs. User interface Almost all operating
systems have a user interface (UI).This interface can take several forms.Command-Line Interface
(CLI).Batch Interface.Graphics User Interface (GUI).Command-line interface(CLI):CLI uses text
commands and a method for entering them.Typing in commands in a specific format with specific
options. Batch interface:In Batch interface, commands and directives to control those commands
are entered into files, and those files are executeGraphical user interface (GUI):This interface uses a
pointing device to direct I/O, choose from menus, and make selections and a keyboard to enter text.

Services of OS Services of OSProgram execution:The system must be able to load a program into
memory and to run that program. The program must be able to end its execution, either normally or
abnormally (indicating error).I/O Operations:A running program may require I/O, which may involve
a file or an I/O device.For specific devices, special functions may be desired (such as recording to a
CD or DVD drive). For efficiency and protection, users usually cannot control I/O devices directly.
File-system:The file system is of particular interest. Obviously, programs need to read and write files
and directories.They also need to create and delete them by name, search for a given file, and list
file information. Error detection:The operating system needs to be detecting and correcting errors
constantly. Errors may occur:in the CPU and memory hardware: such as a memory error or a power
failure. In I/O devices:such as a parity error on disk, a connection failure on a network, or lack of
paper in the printer. Resource allocation: When there are multiple users or multiple jobs running at
the same time, resources must be allocated to each of them. The operating system manages many
different types of resources. Some (such as CPU cycles, main memory, and file storage) may have
special allocation code. Accounting: We want to keep track of which users use how much and what
kinds of computer resources Protection and security: Protection: The owners of information stored
in a multiuser or networked computer system may want to control use of that information
Protection involves ensuring that all access to system resources is controlled. Security: Security of
the system from outsiders is also important. Such security starts with requiring each user to
authenticate himself or herself to the system, usually by means of a password, to gain access to
system resources. Command Interpreters Some operating systems include the command
interpreter in the kernel. Others, such as Windows and UNIX, treat the command interpreter as a
special program that is running when a job is initiated or when a user first logs on. On systems with
multiple command interpreters to choose from, the interpreters are known as shells Shell is an
environment in which we can run our commands, programs, and shell scripts. There are different
flavors of a shell, just as there are different flavors of operating systems. For example, on UNIX and
Linux systems, a user may choose among several different shells, including the Bourne shell, C-shell,
Bourne-Again shell, Korn shell, and others. Graphical User Interfaces Here, rather than entering
commands directly via a command-line interface, users employ a mouse-based window and menu
system characterized by a desktop metaphor. The user moves the mouse to position its pointer on
images, or icons, on the screen (the desktop) that represent programs, files, directories, and system
functions Command Line Commands (Activity) driverquery – Lists All Installed Drivers. systeminfo –
Shows Your PC's Details. ping – Shows a Website IP Address, Lets you Know How Long it Takes to
Transmit Data and a Get Response. color attr – Changes the Text Color of the Command Prompt Cls –
Clear Screen powercfg /batteryreport – Check the battery health. start website-address – Logs on to
a Website from the Command LineDifference between System Call and Interrupt: A system call is
call by software running on the OS to services provided by the OS. An interrupt is usually external
hardware component notifying the CPU/Microprocessor about an event that needs handling in
software (usually a driver). Routine: In computer programming, a routine is nothing but a sequence
of code, intended for the execution of user programs and input/output operations. It can range from
a subroutine, co-routine to a function. It is called repeatedly by other codes, during the execution of
a program. Process: The process is a program in execution and represents the basic unit of CPU
utilization. A process is an active entity that is created when an executable file gets loaded into the
main memory for execution.Scenario of System Call Writing a simple program to read data from one
file and copy them to another file. The first input that the program will need is the names of the two
files: the input file and the output file. These names can be specified in many ways, depending on
the operating-system design. One approach is for the program to ask the user for the names. In an
interactive system, this approach will require a sequence of system calls. First to write a prompting
message on the screen and then to read from the keyboard the characters that define the two files.
An application programming interface (API) is code that enables two software programs to
communicate. An API defines how a developer should request services from an operating system
(OS) or other application, and expose data within different contexts and across multiple channels.
Api 2 benefit One benefit concerns program portability. An application programmer designing a
program using an API can expect his/her program to compile and run on any system that supports
the same API Actual system calls can often be more detailed and difficult to work with than the API
available to an application programmer. The caller need know nothing about how the system call is
implemented Just needs to obey API and understand what OS will do as a result call. Most details of
OS interface hidden from programmer by API. Managed by run-time support library (set of functions
built into libraries included with compiler) Three general methods used to pass parameters to the
OS Simplest: pass the parameters in registers In some cases, may be more parameters than
registers Parameters stored in a block, or table, in memory, and address of block passed as a
parameter in a register This approach taken by Linux and Solaris Parameters placed, or pushed, onto
the stack by the program and popped off the stack by the operating system Block and stack methods
do not limit the number or length of parameters being passed Types of System Calls Process
Control A running program needs to be able to end its execution either normally (end()) or
abnormally (abort()). Process control system calls include end, abort load, execute create process,
File Management File management system calls include create file delete file Open Close Read
Device Management Device management system calls include request device release device read,
write, reposition get/set device attributes Information Maintenance Information maintenance
system calls include calls to get/set the time, date, system data, and process, file, or device
attributes. Communication Communication system calls create/delete communication connection
send/receive messages transfer status information Protection Protection provides mechanisms for
controlling which users / processes have access to which system resources. System calls allow the
access mechanisms to be adjusted as needed, and for non-priveleged users to be granted elevated
access permissions under carefully controlled temporary circumstances File modification &
Programming-language support File modification: Several text editors may be available to create
and modify the content of files stored on disk or other storage devices. There may also be special
commands to search contents of files or perform transformations of the text. Programming-
language support Compilers, assemblers, debuggers, and interpreters for common programming
languages (such as C, C++, Java, and PERL) are often provided with the operating system or available
as a separate download. Microkernels The basic idea behind micro kernels is to remove all non-
essential services from the kernel, and implement them as system applications instead, thereby
making the kernel as small and efficient as possible. Most microkernels provide basic process and
memory management, and message passing between other services, and not much more.

CPU-scheduling information: This information includes a process priority, pointers to scheduling


queues, and any other scheduling parameters. Memory-management information: This information
may include such items as the value of the base and limit registers and the page tables, or the
segment tables, depending on the memory system used by the operating system. Accounting
information: This information includes the amount of CPU and real time used, time limits, account
numbers, job or process numbers, and so on. I/O status information: This information includes the
list of I/O devices allocated to the process, a list of open files, and so on. Schedulers are special
system software which handle process scheduling in various ways. Their main task is to select the
jobs to be submitted into the system and to decide which process to run. Schedulers are of three
types: 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 Schedule It is also called as CPU scheduler. Its
main objective is to increase system performance in accordance with the chosen set of criteria. It is
the change of ready state to running state of the process.r Medium-Term Scheduler Medium-term
scheduling is a part of swapping. It removes the processes from the memory. It reduces the degree
of multiprogramming. Context switches are computationally intensive since register and memory
state must be saved and restored. To avoid the amount of context switching time, some hardware
systems employ two or more sets of processor registers. When the process is switched, the following
information is stored for later use. Program Counter Scheduling information Base and limit register
value Currently used register Changed State I/O State information Accounting informationWhy do
processes become zombies? If the parent decides not to wait for the child's termination and
executes its subsequent task, then at the termination of the child, the exit status is not read. Hence,
there remains an entry in the process table even after the termination of the child. What happens
with the zombie processes? wait() system call is used for removal of zombie processes. wait() call
ensures that the parent doesn't execute or sits idle till the child process is completed. When the
child process completes executing ,the parent process removes entries of the child process from the
process table. This is called "reaping of child". Why are lots of zombie processes harmful to the
system? A lot of zombie processes in OS are harmful as: The OS has one process table of finite size ,
so lots of zombie processes will results in a full process table. A full process table means that OS
cannot create a new process when required and Zombie processes in OS are of no use as the process
has died but it's entry is occupying the space in memory. What will happen with the orphan
processes? In the real world orphans are adopted by guardians who look after them. Similarly, the
orphan process in linux is adopted by a new process , which is mostly init process (pid=1) . This is
called re-parenting. Reparenting is done by the kernel, when the kernel detects an orphan process in
OS, and assigns a new parent process. Why are too many Orphan processes harmful to the system?
Orphan processes in OS hold resources when present the system. Orphan processes in a large
number can overload the init process and hang-up a system. A thread is a flow of execution through
the process code, with its own Program counter that keeps track of which instruction to execute
next. System registers which hold its current working variables. There are four major categories of
benefits to multi-threading: Responsiveness - One thread may provide rapid response while other
threads are blocked or slowed down doing intensive calculations. Resource sharing - By default
threads share common code, data, and other resources, which allows multiple tasks to be performed
simultaneously in a single address space. Economy - Creating and managing threads ( and context
switches between them ) is much faster than performing the same tasks for processes. Scalability,
i.e. Utilization of multiprocessor architectures - A single threaded process can only run on one CPU,
no matter how many may be available, whereas the execution of a multi-threaded application may
be split amongst available processes Explanation of tree kthreadd process is responsible for
creating additional processes that perform tasks on behalf of the kernel. The sshd process is
responsible for managing clients that connect to the system by using ssh (which is short for secure
shell).. Threads are implemented in following two ways User Level Threads -- User managed
threads Kernel Threads Level -- Operating System managed threads acting on kernel, an operating
system core. User Level Threads In this case, application manages thread management kernel is not
aware of the existence of threads. The thread library contains code for creating and destroying
threads, for passing message and data between threads, for scheduling thread execution and for
saving and restoring thread contexts. The application begins with a single thread and begins running
in that thread. Kernel Level Threads In this case, thread management done by the Kernel. There is no
thread management code in the application area. Kernel threads are supported directly by the
operating system. Multithreading models are three types Many-To-One Model One-To-One Model
Many-To-Many Model Threading Issues As fork() creates a new process by producing a duplicate of
the current calling process, whereas, exec() replace the entire current calling process with a new
program altogether. Signal Handling A signal is used in UNIX systems to notify a process that a
particular event has occurred. Examples of signal - illegal memory access and division by 0. If a
running program performs either of these actions, a signal is generated. When a multi-threaded
process receives a signal, There are four major options: Deliver the signal to the thread to which
the signal applies. Deliver the signal to every thread in the process. Deliver the signal to certain
threads in the process. Assign a specific thread to receive all signals in a process. Cancellation of a
target thread may occur in two different scenarios: Asynchronous Cancellation cancels the thread
immediately. Deferred Cancellation sets a flag indicating the thread should cancel itself when it is
convenient. Resource allocation and inter-thread data transfers can be problematic with
asynchronous cancellation. Thread Cancellation Thread cancellation involves terminating a thread
before it has completed. For example, if multiple threads are concurrently searching through a
database and one thread returns the result, the remaining threads might be canceled. CPU
Scheduling is a process of determining which process will own CPU for execution while another
process is on hold. Types of CPU Scheduling Preemptive Scheduling: In Preemptive Scheduling, the
tasks are mostly assigned with their priorities. Sometimes it is important to run a task with a higher
priority before another lower priority task, even if the lower priority task is still running. The lower
priority task holds for some time and resumes when the higher priority task finishes its execution
Non-Preemptive Scheduling: In this type of scheduling method, the CPU has been allocated to a
specific process. The process that keeps the CPU busy will release the CPU either by switching
context or terminating. When scheduling is Preemptive or Non-Preemptive? To determine if
scheduling is preemptive or non-preemptive, consider these four parameters: A process switches
from the running to the waiting state. Specific process switches from the running state to the ready
state. Specific process switches from the waiting state to the ready state. Process finished its
execution and terminated.Process state: The state may be new, ready, running, waiting, halted, and
so on. Program counter: The counter indicates the address of the next instruction to be executed for
this process Scheduling QueuesThe processes that are residing in main memory and are ready and
waiting to execute are kept on a list called the ready queue Process Scheduling The process
scheduling is the activity of the process manager that handles the removal of the running process
from the CPU and the selection of another process on the basis of a particular strategy. An orphan
process is formed when it's parent dies, while the process continues to execute. A zombie process is
a process which has terminated but it's entry is there in the system What is difference between
thread and process? In the world of computer science both process and thread are counted as
important terms. Process is the program under action whereas a thread is the smallest segment of
instructions that can be handled independently by a scheduler. Dispatch latency: is the amount of
time needed by the CPU scheduler to stop one process and start another.

You might also like