Unit 1
Unit 1
Unit 1
of Technology, Gorakhpur
Neha Singh
Department of Information Technology &
Computer Application, Madan Mohan Malaviya
University of Technology
Gorakhpur-273010,India
21-05-2023 Side 1
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Content
Introduction: Basic architectural concepts, Operating System Services,
interrupt handling, concepts of batch processing, multiprogramming,
time-sharing, real-time operations; Resource Manager view, process view
and hierarchical view of an OS.
Memory management: Partitioning, paging, concepts of virtual memory
demand paging, page replacement algorithms, segmentation,
Segmentation and demand-paging, Cache memory management.
21-05-2023 Side 2
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Operating System
Operating system is a collection of set of programs, which manages all the resources
of computer system. It is an intermediate between the user and computer hardware.
The Operating System performs basic tasks such as-
Controlling and allocating memory.
Controlling Input and Output device and facilitating networking and managing
files.
Examples of Operating System- Windows, Unix, Linux, Mac OS etc.
Characteristics
1. Scheduling
2. Memory Management
3. Security
4. Interact with different software
5. Device Management
6. File Management
21-05-2023 Side 3
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 4
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Advantages
1. OS provides a GUI interface for the users in the form of menu, icons
and buttons.
2. OS also allow us to sharing the resources with other users.
3. It helps users to understand the function of a computer.
4. It is very easy to use.
5. It can be easily updated.
Disadvantages
1. If the OS is corrupted than it will affect entire system and computer
system will not work.
2. Only same task run at a time.
21-05-2023 Side 5
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Applications
AAAAAPPPPPPPPPPPPPPPPAAAAAaksxk
jxskkfjhfjhjhvfvfbmvbfmdnnvbncm
Operating System
Hardware
CPU I/O Secondary RAM
Devices Memory
21-05-2023 Side 6
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 7
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 8
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Program execution
Operating systems handle many kinds of activities from user programs to
system programs like printer spooler, name servers, file server, etc. Each of
these activities is encapsulated as a process.
Following are the major activities of an operating system with respect to
program management −
Loads a program into memory.
Executes the program.
Handles program's execution.
Provides a mechanism for process synchronization.
Provides a mechanism for process communication.
Provides a mechanism for deadlock handling
21-05-2023 Side 9
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
I/O Operation
An I/O subsystem comprises of I/O devices and their corresponding driver
software. Drivers hide the peculiarities of specific hardware devices from the
users. An Operating System manages the communication between user and
device drivers.
I/O operation means read or write operation with any file or any specific
I/O device.
Operating system provides the access to the required I/O device when
required.
21-05-2023 Side 10
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 11
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Communication
In case of distributed systems which are a collection of processors that do not
share memory, peripheral devices, or a clock, the operating system manages
communications between all the processes.
Following are the major activities of an operating system with respect to
communication −
Two processes often require data to be transferred between them both the
processes can be on one computer or on different computers, but are
connected through a computer network.
Communication may be implemented by two methods, either by Shared
Memory or by Message Passing.
21-05-2023 Side 12
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Error Handling
Errors can occur anytime and anywhere. An error may occur in CPU, in I/O
devices or in the memory hardware. Following are the major activities of an
operating system with respect to error handling −
The OS constantly checks for possible errors.
The OS takes an appropriate action to ensure correct and consistent
computing.
Resource Management
In case of multi-user or multi-tasking environment, resources such as main
memory, CPU cycles and files storage are to be allocated to each user or job.
Following are the major activities of an operating system with respect to resource
management −
The OS manages all kinds of resources using schedulers.
CPU scheduling algorithms are used for better utilization of CPU
21-05-2023 Side 13
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Protection
Protection refers to a mechanism or a way to control the access of
programs, processes, or users to the resources defined by a computer
system. Following are the major activities of an operating system with
respect to protection −
The OS ensures that external I/O devices are protected from invalid
access attempts.
The OS provides authentication features for each user by means of
passwords.
21-05-2023 Side 14
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Interrupt Handling
21-05-2023 Side 15
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 16
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Jobs are processed in the order of submission i.e. first come first served
fashion. When job completes its execution, its memory is released and the
output for the job gets copied into an output spool for later printing or
processing.
Job 1 Batch
Operating CPU
Job 2 Batch
System
Job n Batch
21-05-2023 Side 17
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Advantages
1. Batch processing takes much of the work of the operator to the
computer.
2. It is useful when we, working with large files which can take
more time to execute.
Disadvantages
1. Once the job is submitted, the user did not have any interaction
with it.
21-05-2023 Side 18
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Multiprogramming
When two or more programs are residing in memory at the same time, then sharing
the processor is referred to the multiprogramming. Multiprogramming assumes a
single shared processor. Multiprogramming increases CPU utilization by
organizing jobs.
Operating system does the following activities related to multiprogramming.
The operating system keeps several jobs in memory at a time.
This set of jobs is a subset of the jobs kept in the job pool.
The operating system picks and begins to execute one of the job in the memory.
21-05-2023 Side 19
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Operating System
Job 1
Job 2
:
:
:
Job n
Empty Space
21-05-2023 Side 20
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Advantages
1. High and efficient CPU utilization.
2. User feels that many programs are allotted CPU almost
simultaneously.
Disadvantages
1. CPU scheduling is required.
2. To accommodate many jobs in memory, memory
management is required.
21-05-2023 Side 21
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Time –Sharing
The time sharing operating system works with time sharing concept.
Here, the CPU will provide a same time period to each an every
process to complete its task as soon as possible weather it is a long
process or short process.
Process 1 Process 4
CPU
Process 2 Process 5
Process 3 Process 6
21-05-2023 Side 22
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 23
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Real-Time Operations-
Real time operating system is very useful where we required a quick
response for example – missile systems, where the missile has to be
launched at certain time.
In this operating system CPU provides maximum effort's to its task with
quick response. There are two types of real-time operating systems-
Hard Real-Time Systems- Hard real-time systems guarantee that
critical tasks complete on time is called hard real-time systems.
Soft Real-Time Systems- Soft real time systems are less restrictive.
Soft real time systems does not guarantee that a job will be complete
within a specified time period.
21-05-2023 Side 24
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 25
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
The operating system is the resource manager view i.e. it can manage
the resource of a computer system internally. The resources are
processor, memory, files, and I/O devices. In this role, the operating
system keeps track of the status of each resource, and decides who gets
a resource, for how long and when.
The operating system can be viewed as a resource allocator. A
computer system consists of many resources like - hardware and
software - that must be managed efficiently. The operating system acts
as the manager of the resources, and controls the execution of
programs, etc.
21-05-2023 Side 26
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Process View
21-05-2023 Side 27
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 28
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 29
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Hierarchical View of OS
21-05-2023 Side 30
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Level Functions
3 File Management
2 Memory Management
1 I/O Supervision
0 Resource Management
Each layer or level of the structure can use the functions provided by lower
levels just as if they were part of the real machine.
Level 0, often called the kernel of the operating system, deals directly with
the underlying hardware.
User program deals with the highest-level interface.
Operating system routines at a given level can use the relatively simple
functions and interfaces provided by lower levels.
21-05-2023 Side 31
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 32
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Memory Management
21-05-2023 Side 33
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Partitioning
Memory is divided into different blocks or partitions. Each process is
allocated according to the requirement. Partition allocation is an ideal
method to avoid internal fragmentation.
Below are the various partition allocation schemes :
First Fit: In this type fit, the partition is allocated, which is the first
sufficient block from the beginning of the main memory.
Best Fit: It allocates the process to the partition that is the first smallest
partition among the free partitions.
Worst Fit: It allocates the process to the partition, which is the largest
sufficient freely available partition in the main memory.
Next Fit: It is mostly similar to the first Fit, but this Fit, searches for the
first sufficient partition from the last allocation point
21-05-2023 Side 34
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 35
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Paging
Paging is a technique in which physical memory is broken into blocks
of the same size called pages. When a process is to be executed, it's
corresponding pages are loaded into any available memory frames.
Logical address space of a process can be non-contiguous and a process
is allocated physical memory whenever the free memory frame is
available. Operating system keeps track of all free frames. Operating
system needs n free frames to run a program of size n pages. Address
generated by CPU is divided into tow parts-
Page number (p) - Page number is used as an index into a page table
which contains base address of each page in physical memory.
Page offset (d) - Page offset is combined with base address to define
the physical memory address.
21-05-2023 Side 36
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 37
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 38
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 39
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 40
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Demand Paging
A demand paging system is quite similar to a paging system with swapping. When
we want to execute a process, we swap it into memory. Rather than swapping the
entire process into memory, however, we use a lazy swapper called pager.
When a process is to be swapped in, the pager guesses which pages will be used
before the process is swapped out again. Instead of swapping in a whole process,
the pager brings only those necessary pages into memory. Thus, it avoids reading
into memory pages that will not be used in anyway, decreasing the swap time and
the amount of physical memory needed.
Hardware support is required to distinguish between those pages that are in
memory and those pages that are on the disk using the valid-invalid bit scheme.
Where valid and invalid pages can be checked by checking the bit. Marking a page
will have no effect if the process never attempts to access the page. While the
process executes and accesses pages that are memory resident, execution proceeds
normally.
21-05-2023 Side 41
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 42
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Access to a page marked invalid causes a page-fault trap. This trap is the result of the
operating system's failure to bring the desired page into memory. But page fault can
be handled as following-
21-05-2023 Side 43
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Step 1: Check an internal table for this process, to determine whether the reference was a
valid or it was an invalid memory access.
Step 2: If the reference was invalid, terminate the process. If it was valid, but page have not
yet brought in, page in the latter.
Step 4: Schedule a disk operation to read the desired page into the newly allocated frame.
Step 5: When the disk read is complete, modify the internal table kept with the process and
the page table to indicate that the page is now in memory.
Step 6: Restart the instruction that was interrupted by the illegal address trap. The process
can now access the page as though it had always been in memory. Therefore, the operating
system reads the desired page into memory and restarts the process as though the page had
always been in memory.
21-05-2023 Side 44
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 46
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 47
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Least Recently Used (LRU) Algorithm
Page which has not been used for the longest time in main memory is the one which
will be selected for replacement.
In this algorithm page will be replaced which is least recently used.
21-05-2023 Side 48
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 49
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 50
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Segmentation
21-05-2023 Side 51
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 52
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Segmentation and Demand Paging
S.No. Demand Paging Segmentation
In demand paging, the pages are of While in segmentation, segments can be of
1.
equal size. different size.
Page size is fixed in the demand Segment size may vary in segmentation as it
2.
paging. grants dynamic increase of segments.
3. It does not allows sharing of the pages. While segments can be shared in segmentation.
Page map table in demand paging Segment map table in segmentation demonstrates
5.
manages record of pages in memory. every segment address in the memory.
It provides large virtual memory and It provides virtual memory and maximum size of
6.
have more efficient use of memory. segment is defined by the size of memory.
21-05-2023 Side 53
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 54
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
Cache Performance
The cache performance can be explained using the following steps −
If a process needs some data, it first searches in the cache memory. If the
data is available in the cache, this is termed as a cache hit.
If the data is not in the cache then it is termed as a cache miss. Then the data
is obtained from the main memory. After that the data is transferred to the
cache memory.
The performance of the cache is measured using the hit ratio. It is the
number of cache hits divided by the total cache accesses. The formula for
this is:
21-05-2023 Side 55
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 56
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
21-05-2023 Side 57
Madan Mohan Malaviya Univ. of Technology, Gorakhpur
THE END
21-05-2023 Side 58