Os 1
Os 1
COURSR MATERIAL
OPERATING SYSTEMS
S.N0 Topic
2 Memory Management
3 Processor Management
4 Device Management
5 File Management
Page 3
III B.Sc Computer Science - Operating Systems
Text Book:
1.Understanding Operating Systems, Ann McIver McHoes and Ida M. Flynn,
Course Technology, Cengage Learning, 2011.
Reference Book:
1.OperatingSystems,AchyutGodbole and AtulKahate , McGraw Hill Publishing,
2010
OPERATING SYSTEMS
TWO MARK QUESTIONS
• Memory Management
• Processor Management
• Device Management
• File Management
• Security
• Control over system performance
• Job accounting
• Error detecting aids
• Coordination between other software and users
Main memory provides a fast storage that can be accessed directly by the
CPU. For a program to be executed, it must in the main memory.
• Keeps tracks of primary memory, i.e., what part of it are in use by whom,
what parts are not in use?
• Keeps tracks of processor and status of process. The program responsible for
this task is known as traffic controller.
• Keeps tracks of all devices. Program responsible for this task is known as
the I/O controller.
• Decides which process gets the device when and for how much time.
• Allocates the device in the efficient way.
• De-allocates devices.
A file system is normally organized into directories for easy navigation and
usage. These directories may contain files and other directions.
• Keeps track of information, location, uses, status etc. The collective facilities
are often known as file system.
• Decides who gets the resources.
• Allocates the resources.
The kernel is the heart of the operating system. It is the first program loaded
when the computer starts up, it manages computer resources, and it handles
requests from system programs and applications.
The Cache Memory is the Memory which is very nearest to the CPU , all the
Recent Instructions are Stored into the Cache Memory.
External fragmentation
Internal fragmentation
A computer can address more memory than the amount physically installed
on the system. This extra memory is actually called virtual memory and it is a
section of a hard disk that's set up to emulate the computer's RAM.
Sequential access memory (SAM) is a class of data storage devices that read
stored data in a sequence.
Random Access Memory (RAM) where data can be accessed in any order.
Access Control is the process of mediating the requests for accessing data in
a system and determining whether the request should be granted or denied.
Definition
The first operating system was created by General Motors in 1956 to run a
single IBM mainframe computer. Other IBM mainframe owners followed suit and
created their own operating systems. As you can imagine, the earliest operating
systems varied wildly from one computer to the next, and while they did make it
easier to write programs, they did not allow programs to be used on more than one
mainframe without a complete rewrite.
In the 1960s, IBM was the first computer manufacturer to take on the task of
operating system development and began distributing operating systems with their
computers. However, IBM wasn't the only vendor creating operating systems
during this time. Control Data Corporation, Computer Sciences Corporation,
Burroughs Corporation, GE, Digital Equipment Corporation, and Xerox all
released mainframe operating systems in the 1960s as well.
In the late 1960s, the first version of the Unix operating system was
developed. Written in C, and freely available during it's earliest years, Unix was
easily ported to new systems and rapidly achieved broad acceptance. Many modern
operating systems, including Apple OS X and all Linux flavors, trace their roots
back to Unix.
• The kernel;
• System programs.
The kernel is the heart of the operating system. It is the first program loaded
when the computer starts up, it manages computer resources, and it handles
requests from system programs and applications.
System programs run on top of the kernel. They aren't used to perform
useful work, instead, they are the programs necessary to connect the kernel to user
applications and peripheral devices. Device drivers, file systems, networking
programs, and system utilities like disk defragmeters are all examples of system
programs.
Application programs aren't part of the operating system and are the
programs used to perform useful work. Word processing applications, browsers,
and media player are common types of application programs. Application
programs are managed and enabled by the kernel, and use system programs to
access computer periphery devices and hardware.
See e.g. Choices Object Oriented Operating System and Blue Abyss.
The memory is usually divided into two partitions: one for the resident operating
system, and one for the user processes. We may place the operating system in
either low memory or high memory. With this approach each process is contained
in a single contiguous section of memory.
One of the simplest methods for memory allocation is to divide memory into
several fixed-sized partitions. Each partition may contain exactly one process. In
this multiple-partition method, when a partition is free, a process is selected from
the input queue and is loaded into the free partition. When the process terminates,
the partition becomes available for another process. The operating system keeps a
table indicating which parts of memory are available and which are occupied.
Finally, when a process arrives and needs memory, a memory section large
enough for this process is provided.
Advantages
◆ Easy to implement, fast context switch
Problems
◆ Internal fragmentation : memory in a partition not used by a
Advantages
◆ No internal fragmentation : allocate just enough for process
Problems
◆ External fragmentation : job loading and unloading produces
empty holes scattered throughout memory
A table stores the information about all such segments and is called
Segment Table.
Segment Table: It maps two dimensional Logical address into one dimensional
Physical address.
• Base Address: It contains the starting physical address where the segments
reside in memory.
• Limit: It specifies the length of the segment.
Advantages of Segmentation:
• No Internal fragmentation.
• Segment Table consumes less space in comparison to Page table in paging.
Disadvantage of Segmentation:
• As processes are loaded and removed from the memory, the free memory
space is broken into little pieces, causing External fragmentation.
• Long-Term Scheduler
• Short-Term Scheduler
• Medium-Term Scheduler
It is almost absent or
It is also minimal in It is a part of Time sharing
4 minimal in time sharing
time sharing system systems.
system
It can re-introduce the
It selects processes from It selects those
process into memory and
5 pool and loads them into processes which are
execution can be
memory for execution ready to execute
continued.
- If jobs can request and hold files for duration of their execution, deadlock can
occur.Any other programs that require F1 or F2 are put on hold as long as this
situation continues. Deadlock remains until a programs is withdrawn or forcibly
removed and its file is released.
example:
Example:
Example:
-Deadlocks can happen when several processes request, and hold on to, dedicated
devices while other processes act in a similar manner.
Example:
-Most systems have transformed dedicated devices such as a printer into a sharable
device by installing a high-speed device, a disk, between it and the CPU. Disk
accepts output from several users and acts as a temporary storage area for all
output until printer is ready to accept it (spooling).
Example:
If printer needs all of a job's output before it will begin printing, but spooling
system fills available disk space with only partially completed output, then a
deadlock can occur.
-a network that's congested or has filled a large percentage of it's I/O buffer space
can become deadlocked if it doesn't have protocols to control the flow of messages
through the network.
-Disks are designed to be shared, so it’s not uncommon for 2 processes access
different areas of same disk. Without controls to regulate use of disk drive,
competing processes could send conflicting commands and deadlock the system.
Figure Represents
(A) Holding a resource
(B) Requesting a resource
(C) Deadlock
According to Hold, these graphs have the following two types of nodes:
Here, in this graph, an arc from a square (resource node) to a circle (process
node) means that the resource has previously been requested by, granted to, and is
currently held by that process.
As you can see from the figure given above, resource R is currently assigned
to process A in figure A. An arc from a process to a resource means that the
process is currently blocked waiting for that resource.
As you can see from the above figure, in the figure B, process B is waiting
for resource S. And, in the figure C, we see a deadlock, that is, the process C is
waiting for the resource T, which is currently held by the process D. Here, process
D is not about the release the resource T because it is waiting for resource U, held
by C. Here both processes will wait forever.
• Master/slave
• Loosely coupled
• Symmetric
• Asymmetric configuration.
• Single-processor system with additional “slave” processors.
• Each slave, all files, all devices, and memory managed by primary “master”
processor.
• Master processor maintains status of all processes in system, performs
storage management activities, schedules work for the other processors, and
executes all control programs.
Slave
Slave
Processor 1
Main I/O
Memory Processor 2
Devices
Processor 3
A removable storage device is any storage device defined by the person who
administers your system during system configuration to be an optional part of the
system DASD. The removable storage device can be removed from the system at
any time during normal operation. As long as the device is logically unmounted
first, the operating system does not detect an error.
Page 27
III B.Sc Computer Science - Operating Systems
The following types of devices are not considered DASD and are not supported
by the logical volume manager (LVM):
• Diskettes
• CD-ROM (compact disk read-only memory)
• DVD-ROM (DVD read-only memory)
• WORM (write-once read-many)
As of 2017, magnetic storage media, primarily hard disks, are widely used to
store computer data as well as audio and video signals. In the field of computing,
the term magnetic storage is preferred and in the field of audio and video
production, the term magnetic recording is more commonly used. The distinction
is less technical and more a matter of preference. Other examples of magnetic
storage media include floppy disks, magnetic recording tape, and magnetic stripes
on credit cards.
• Tape, magnetic disk, optical disc, flash storage – Network knowledge not needed
• Wait for rotational delay (sector containing record passes under read/write head)
Page 29
III B.Sc Computer Science - Operating Systems
File access mechanism refers to the manner in which the records of a file
may be accessed. There are several ways to access files −
• Sequential access
• Direct/Random access
• Indexed sequential access
Sequential access
Direct/Random access
Page 30
III B.Sc Computer Science - Operating Systems
When a computer (or network) has multiple users, the need for managing
and protecting the memory, input/output devices, and other resources is even
greater, since the users might otherwise interface with one another. In addition,
users often need to share not only hardware, but information (files, databases, etc.)
as well. In short, this view of the operating system holds that its primary task is to
keep track of which programs are using which resources, to grant resource
requests, to account for usage, and to mediate conflicting requests from different
programs and users.
1. Time Multiplexing
2. Space Multiplexing
1. Time Multiplexing
For example:
With only one CPU and multiple programs that want to run on it, operating
system first allocates the CPU to one long enough, another one gets to use the
CPU, then another and ten eventually the first one again.
Determining how the resource is time multiplexed – who goes next and for
how long – is the task of the operating system.
Page 31
III B.Sc Computer Science - Operating Systems
2. Space Multiplexing
In space multiplexing, instead of the customers taking turns, each one gets
part of the resource.
For example:
Batch processing
Page 32
III B.Sc Computer Science - Operating Systems
Advantages
• Batch processing takes much of the work of the operator to the computer.
• Increased performance as a new job get started as soon as the previous job is
finished, without any manual intervention.
Disadvantages
Multitasking
Page 33
III B.Sc Computer Science - Operating Systems
Multiprogramming
Sharing the processor, when two or more programs reside in memory at the
same time, is referred as multiprogramming. Multiprogramming assumes a single
shared processor. Multiprogramming increases CPU utilization by organizing jobs
so that the CPU always has one to execute.
The following figure shows the memory layout for a multiprogramming system.
Page 34
III B.Sc Computer Science - Operating Systems
Advantages
Disadvantages
3. Explain in detail about First fit and Best fit memory allocation
Best fit memory allocation:
Best-fit memory allocation makes the best use of memory space but slower
in making allocation. In the illustration below, on the first processing cycle, jobs 1
Page 35
III B.Sc Computer Science - Operating Systems
to 5 are submitted and be processed first. After the first cycle, job 2 and 4 located on
block 5 and block 3 respectively and both having one turnaround are replace by job
6 and 7 while job 1, job 3 and job 5 remain on their designated block. In the third
cycle, job 1 remain on block 4, while job 8 and job 9 replace job 7 and job 5
respectively (both having 2 turnaround). On the next cycle, job 9 and job 8 remain
on their block while job 10 replace job 1 (having 3 turnaround). On the fifth cycle
only job 9 and 10 are the remaining jobs to be process and there are 3 free memory
blocks for the incoming jobs. But since there are only 10 jobs, so it will remain free.
On the sixth cycle, job 10 is the only remaining job to be process and finally on the
seventh cycle, all jobs are successfully process and executed and all the memory
blocks are now free.
Page 36
III B.Sc Computer Science - Operating Systems
are 10 jobs so it will remain free. And job 10 occupies block 2 after job 1 finish its
turns. On the other hand, job 8 and job 9 remain on their block. Then on the fifth
cycle, only job 9 and job 10 are to be process while there are 3 memory blocks
free. In the sixth cycle, job 10 is the only remaining job to be process and lastly in
the seventh cycle, all jobs are successfully process and executed and all the
memory blocks are now free.
Memory Turnaround
Job
utilized time
Job1 100K 3
Job2 10K 1
Job3 30K 2
Job4 20K 1
Job5 25K 2
Page 37
III B.Sc Computer Science - Operating Systems
Job6 5K 1
Job7 25K 1
Job8 50K 2
Job9 90K 3
Job10 100K 3
Let us assume the memory size is 220k with 10k allocated to operating
system programs. The above table gives the data of number of jobs, memory
utilized by individual job and their respective turnaround time. There are 10 jobs to
be loaded into memory. Initially with 220k of memory, we can load job1 to job6
with free memory of 20k.
At first turnaround time, job2 of 10k, job4 of 20k, and job6 of 5k are
completed leaving job 1, job 3, and job 5 as it is with free memory of 55k, in other
words job1, job3, and job5 are still processing. Job 7 of 25k now enters into the
memory partition leaving only 30k free memory where neither of the remaining
jobs (job 8, job 9, and job 10) can accommodate.
At second turnaround time job3 of 30k, job5 of 25k, and job7 of 25k are
completed leaving job 1 of 100k with free memory of 110k. Now job 8 of 50K is
entered where 50k is allocated leaving 60K of free memory space where either job
9 or job 10 can accommodate.
Note: for job3 and job5 turnaround time is finished and at the same time
turnaround time 1 of job 7 is also finished.
Page 38
III B.Sc Computer Science - Operating Systems
Translating addresses
◆ Virtual address has two parts: virtual page number and offset
◆ Virtual page number (VPN) is an index into a page table
◆ Page table determines page frame number (PFN)
◆ Physical address is PFN::offset
Page tables
◆ Map virtual page number (VPN) to page frame number (PFN)
»VPN is the index into the table that determines PFN
◆ One page table entry (PTE) per page in virtual address space
»Or, one PTE per VPN
Page 39
III B.Sc Computer Science - Operating Systems
Paging Examples
Pages are 4K
◆ VPN is 20 bits (220 VPNs), offset is 12 bits
◆ The Modify bit says whether or not the page has been written
»It is set when a write to the page occurs
◆ The Reference bit says whether the page has been accessed
»It is set when a read or write to the page occurs
◆ The Valid bit says whether or not the PTE can be used
»It is checked each time the virtual address is used
◆ The Protection bits say what operations are allowed on page
»Read, write, execute
Page 40
III B.Sc Computer Science - Operating Systems
Paging Advantage
Paging Limitations
Page 41
III B.Sc Computer Science - Operating Systems
Paging virtual memory is large in size then the available memory the
demand paging allocation is shown in figure.
The page map table consists of a page number, page frame number, status and
judgement field. Initially the allocation algorithm places the first three pages of a
program in the main memory. The job starts execution in one of these pages.
Suppose in page O there is a transfer instruction to the location 9055. The hard ware
mechanism uses 9 as index to the page lable that is page 9 is required in the
execution. then the pagemap table is checked to find whether the page in the main
memory job not if the required page is not in the main memory then the page fault
occurs, then the hard ware generates interrept to the operating system then the
operating system searches the secondary storage device for page 9 and brought
Page 42
III B.Sc Computer Science - Operating Systems
into the memory by replacing one of the pages in the memory It may use a page
remove algorithms like FIFO(First in first out) LRU(Least Recently Use) for
removing a page. The decision which page has to replace it with judgement field in
the page map table. It is desirable to keep highly used pages in the memory.
Advantages :
1.Fragmentation is eliminated.
2.Large Virtual memory is available.
3.More efficient use of memory.
4.Demand paging is valuable in time sharing, systems.
Dis-Advantages :
1. Page address mapping hard ware increases the cost of the computer system
2.Extra memory, extra register needed for page map table.
Page 43
III B.Sc Computer Science - Operating Systems
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
• 3 frames (3 pages can be in memory
• Replaces the page that has not been referenced for the longest time:
– By the principle of locality, this should be the page least likely to be
referenced in the near future.
– performs nearly as well as the optimal policy.
Page 44
III B.Sc Computer Science - Operating Systems
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Page 45
III B.Sc Computer Science - Operating Systems
Why Interrupts?
“ Polling is like picking up your phone every few seconds to see if you have a call.
Interrupts are like waiting for the phone to ring. ”
• Interrupts win if processor has other work to do and event response time is not
critical
• Polling can be better if processor has to respond to an event ASAP
• May be used in device controller that contains
dedicated secondary processor
Page 46
III B.Sc Computer Science - Operating Systems
• Interrupt controller signals CPU that interrupt has occurred, passes interrupt
number
• Interrupts are assigned priorities to handle simultaneous interrupts
• Lower priority interrupts may be disabled during service
• CPU senses (checks) interrupt request line after every instruction; if raised, then:
• uses interrupt number to determine which handler to start
• interrupt vector associates handlers with interrupts
• Basic program state saved (as for system call)
• CPU jumps to interrupt handler
• When interrupt done, program state reloaded and program resumes
AND condition: a process that requires resources for execution can proceed
when it has acquired all those resources.
Page 47
III B.Sc Computer Science - Operating Systems
OR condition: a process that requires resources for execution can proceed when
it has acquired at least one of those resources.
Deadlock conditions
◼ The condition for deadlock in a system using the AND condition is the
existence of a cycle.
◼ The condition for deadlock in a system using the OR condition is the
existence of a knot.
A knot (K) consists of a set of nodes such that for every node a in K, all nodes
in K and only the nodes in K are reachable from node a.
Example: OR condition
Deadlock Prevention
Page 48
III B.Sc Computer Science - Operating Systems
◼ Drawback: over-cautious.
◼ 2. All resources are assigned unique numbers. A process may request a
resource with a unique number I only if it is not holding a resource with a
number less than or equal to I and therefore breaking the circular wait
condition.
◼ E.g. In the dining philosophers problem, each philosopher is required to pick
a fork that has a larger id than the one he currently holds. That is,
philosopher P5 needs to pick up fork F5 and then F1; the other philosopher
Pi should pick up fork Fi followed by Fi-1.
◼ Drawback: over-cautions.
◼ 3. Each process is assigned a unique priority number. The priority numbers
decide whether process Pi should wait for process Pj and therefore break the
non-preemption condition.
◼ E.g. Assume that the philosophers’ priorities are based on their ids, i.e., Pi
has a higher priority than Pj if i <j. In this case Pi is allowed to wait for Pi+1
for I=1,2,3,4. P5 is not allowed to wait for P1. If this case happens, P5 has to
abort by releasing its acquired fork(s) (if any).
◼ Drawback: starvation. The lower priority one may always be rolled back.
Solution is to raise the priority every time it is victimized.
◼ 4. Practically it is impossible to provide a method to break the mutual
exclusion condition since most resources are intrinsically non-sharable, e.g.,
two philosophers cannot use the same fork at the same time.
Wait-die
◼ Wound-wait
◼ Wants resource Hold resource
Page 49
III B.Sc Computer Science - Operating Systems
◼ Waits
An example
st
Process id priority length Retry interval
1 request
time
P1 2 1 1 1
P2 1 1.5 2 1
P3 4 2.1 2 2
P4 5 3.3 1 1
P5 3 4.0 2 3
Deadlock Avoidance
ABCD ABCD
P1 3011 4111
P2 0100 0212
P3 1110 4210
P4 1101 1101
Page 50
III B.Sc Computer Science - Operating Systems
P5 0000 2110
◼ Centralized approaches
◼ Distributed approaches
◼ Hierarchical approaches
Centralized approaches
Distributed approaches
◼ A copy of the global wait-for graph is kept at each site with the result that
each site has a global view of the system.
◼ The global wait-for graph is divided and distributed to different sites.
Page
51
III B.Sc Computer Science - Operating Systems
Hierarchical approaches
History
With each new generation of processors there were several developments such
as:
Page
52
III B.Sc Computer Science - Operating Systems
• Smaller size
• Faster
• Increased heat dissipation
• Greater Consumption of power
To execute the tasks faster you must increase the clock time.
Increasing clock times too high drastically increases power consumption and heat
dissipation to extremely high levels, making the processor inefficient.
Page
53
III B.Sc Computer Science - Operating Systems
Creating two cores or more on the same Die increases processing power while
keeping clock speeds at an efficient level.
A processor with 2 cores running at efficient clock speeds can process instructions
with similar speed to a single core processor running at twice the clock speed, yet
the dual core processor would still consume less energy.
Multi-Core Advantages
• While working with many threads, a Multi Core processor with n cores can
execute n threads simultaneously by assigning a core to each thread. If it
must process more than n threads , say x, it can apply multithreading
procedures with each core working with an average of x/n threads.
• A Single core processor must multithread with every single thread.
• The name “core dual” and similar names are good for marketing.
• It has lower manufacturing costs.
• Uses proven processor designs.
Implementations
• Two main ways to have multiple cores interact are the shared memory
model, and the distributed memory model.
• In the shared memory model, all cores share the same cache memory.
• In the distributed memory model, each core has its own cache memory.
Page
54
III B.Sc Computer Science - Operating Systems
• The Intel core duo design has a separate L1 cache memory for each core, but
Page
55
III B.Sc Computer Science - Operating Systems
Some of the current problems found with multi core processors include:
Synchronization Mechanisms
Page
56
III B.Sc Computer Science - Operating Systems
Lock-and-Key Synchronization
• When many processes are waiting to enter a critical region, starvation could
occur because processes gain access in an arbitrary fashion.
– Unless a first-come first-served policy were set up, some processes
could be favored over others.
– Waiting processes remain in unproductive, resource-consuming wait
loops (busy waiting).
– Consumes valuable processor time.
– Relies on the competing processes to test key.
Page
57
III B.Sc Computer Science - Operating Systems
• Modification of test-and-set.
• Adds 2 new operations, which are mutually exclusive and become part of the
process scheduler’s set of operations
– WAIT
– SIGNAL
– Operations WAIT and SIGNAL frees processes from “busy waiting”
dilemma and returns control to OS which can then run other jobs
while waiting processes are idle.
WAIT
SIGNAL
• Activated when a process exits the critical region and the condition code is
set to “free.”
• Checks queue of processes waiting to enter this critical region and selects
one, setting it to the READY state.
• Process Scheduler selects this process for running.
Semaphores
Page
58
III B.Sc Computer Science - Operating Systems
V(s): s: = s + 1
The CPU must have a way to pass information to and from an I/O device.
There are three approaches available to communicate with the CPU and Device.
This uses CPU instructions that are specifically made for controlling I/O
devices. These instructions typically allow data to be sent to an I/O device or read
from an I/O device.
Page
59
III B.Sc Computer Science - Operating Systems
Memory-mapped I/O
The advantage to this method is that every instruction which can access
memory can be used to manipulate an I/O device. Memory mapped IO is used for
most high-speed I/O devices like disks, communication interfaces.
Slow devices like keyboards will generate an interrupt to the main CPU after
each byte is transferred. If a fast device such as a disk generated an interrupt for
each byte, the operating system would spend most of its time handling these
interrupts. So a typical computer uses direct memory access (DMA) hardware to
reduce this overhead.
Direct Memory Access (DMA) means CPU grants I/O module authority to
read from or write to memory without involvement. DMA module itself controls
exchange of data between main memory and the I/O device. CPU is only involved
at the beginning and end of the transfer and interrupted only after entire block has
been transferred.
Step Description
1 Device driver is instructed to transfer disk data to a buffer address X.
2 Device driver then instruct disk controller to transfer data to buffer.
Page
60
III B.Sc Computer Science - Operating Systems
• File organization refers to the way data is stored in a file. File organization is
very important because it determines the methods of access, efficiency,
flexibility and storage devices to use. There are four methods of organizing
files on a storage media. This include:
• sequential,
• random,
• serial and
• indexed-sequential
• Records are stored and accessed in a particular order sorted using a key
field.
• Retrieval requires searching sequentially through the entire file record by
record to the end.
• Because the record in a file are sorted in a particular order, better file
searching methods like the binary search technique can be used to reduce the
time used for searching a file .
• Since the records are sorted, it is possible to know in which half of the file a
particular record being searched is located, Hence this method repeatedly
divides the set of records in the file into two halves and searches only the
half on which the records is found.
• For example, of the file has records with key fields 20, 30, 40, 50, 60 and the
computer is searching for a record with key field 50, it starts at 40 upwards
in its search, ignoring the first half of the set.
Page
61
III B.Sc Computer Science - Operating Systems
• The sorting does not remove the need to access other records as the search
looks for particular records.
• Sequential records cannot support modern technologies that require fast
access to stored records.
• The requirement that all records be of the same size is sometimes difficult to
enforce.
• It is simple
• It is cheap
Page
62
III B.Sc Computer Science - Operating Systems
• Almost similar to sequential method only that, an index is used to enable the
computer to locate individual records on the storage media. For example, on
a magnetic drum, records are stored sequential on the tracks. However,
each record is assigned an index that can be used to access it directly.
Page
63