Professional Documents
Culture Documents
On
Module Contributor(s):
1
Operating System (BCA 301)
Module Objectives: This module consists of four units related to assessment of Learning. Every unit is
divided into lessons according to the content of each unit. The module focuses on the core concepts of
operating systems. It primarily includes the concepts of operating systems including memory management,
process management, information management and device management.
Unit-I: In this unit you will be acquainted with different concepts associated with the various available
Operating Systems. It discusses about the different types of operating systems including , Simple Batch
Systems, Multiprogrammed Batches systems, Time-Sharing Systems, Personal-computer systems, Parallel
systems, Distributed Systems, Real-Time Systems Memory Management: The unit also discusses the concept
of memory management schemes of operating systems that includes swapping, Contiguous allocation, Paging,
Segmentation. It also reflects the importance of Virtual Memory on the basis of Demand Paging, Page
Replacement, Page-replacement Algorithms, Performance of Demand Paging, Allocation of Frames and
Thrashing.
Unit-II: This unit will make you enable to acquire the features of Processes in operating systems. It discusses
the Process Concept, Process Scheduling and various Operation on Processes. The unit also discusses the
concept of CPU Scheduling, different Scheduling Criteria and various Scheduling Algorithms. The
mechanism of Process Synchronization is also taken up in this unit which is further achieved by understanding
The Critical-Section Problem implemented with the help of Synchronization Hardware, Semaphores and also
the Classical Problems of Synchronizations are discussed as an integral part of the unit.
Unit-III: This unit will empower you to understand the need and process of Deadlocks and Device
Management. The unit includes the very important topic of Deadlocks in operating system. It includes the
concept of System Model, Deadlock Characterization and Methods for Handling Deadlocks. Apart from this
it includes the various Deadlock Prevention, Deadlock Avoidance and Deadlock Detection techniques. Apart
from this the recovery mechanism from deadlocks is also discussed in this unit. The Device Management:
Techniques are discussed in this unit. Starting with the various types for Devices including Dedicated Devices,
Shared Devices, Virtual Devices; Input or Output Devices and Storage Devices. The device management also
talks about the techniques of Buffering and Secondary Storage Structure. The detailed study of Disk Structure
is also performed in this unit. Also the techniques of Disk Scheduling, Disk Management, Swap-Space
Management and Disk Reliability is also taken up as a part of this unit.
Unit-IV: You will be recognizing the concept of Information Management. It discusses the different file
systems approaches including A Simple File System and General Model of a File System. The Types of File
Systems and File-System Interface are also taken up in this unit. Apart from the concept of Files the various
Access Methods are also discussed. Along with file system the Directory Structure is also included. The
Protection Goals of file system is discussed. The various Access rights are also studied to ensure the protection
and security to the file systems. It is performed through the concept of Consistency Semantics Security along
with Authentication mechanism. It avoids various kinds of Program threats and System threats. The
Encryption techniques are discussed to enable the security parameter to the files in operating system.
2
CONTENTS
Unit No. Unit Name Page Number
I Operating System and concepts
II Processes
III Deadlocks
75-84
Lesson 1: Deadlock Detection and Protection
Lesson 2: Device management
IV Information Management
85-108
Lesson 1: File System Interface
Lesson 2: Protection and File Security
Glossary/Key Words 109
References and Further Readings 109
3
UNIT-I OPERATING SYSTEM AND CONCEPTS
B) Introduction
An Operating System (OS) is an interface between a computer user and computer hardware. An operating
system is a software which performs all the basic tasks like file management, memory management, process
management, handling input and output, and controlling peripheral devices such as disk drives and printers.
Memory management is the functionality of an operating system which handles or manages primary memory
and moves processes back and forth between main memory and disk during execution. Memory management
keeps track of each and every memory location, regardless of either it is allocated to some process or it is free.
It checks how much memory is to be allocated to processes. It decides which process will get memory at what
time. It tracks whenever some memory gets freed or unallocated and correspondingly it updates the status.
Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as though it
were part of main memory. The addresses a program may use to reference memory are distinguished from the
addresses the memory system uses to identify physical storage sites, and program generated addresses are
translated automatically to the corresponding machine addresses. The size of virtual storage is limited by the
addressing scheme of the computer system and amount of secondary memory is available not by the actual
number of the main storage locations.
It is a technique that is implemented using both hardware and software. It maps memory addresses used by a
program, called virtual addresses, into physical addresses in computer memory.
C) Body of Content
Lesson 3: Virtual memory and its concepts. Demand Paging, Different Page-replacement Algorithms,
Performance of Demand Paging, Allocation of Frames, Thrashing, Other Considerations.
An operating system is a program that acts as an interface between the user and the computer hardware and
controls the execution of all kinds of programs.
2. Operating system – controls and coordinates the use of the hardware among the various application
programs for the various users.
3. Applications programs – define the ways in which the system resources are used to solve the computing
problems of the users (compilers, database systems, video games, business programs).
5
Functions of Operating System
Memory Management
Processor Management
Device Management
File Management
Security
Control over system performance
Job accounting
Error detecting aids
Coordination between other software and users
Memory Management
Memory management refers to management of Primary Memory or Main Memory. Main memory is a large
array of words or bytes where each word or byte has its own address.
Main memory provides a fast storage that can be accessed directly by the CPU. For a program to be executed,
it must be in the main memory. An Operating System does the following activities for memory management
−
• Keeps tracks of primary memory, i.e., what part of it are in use by whom, what part are not in use.
• In multiprogramming, the OS decides which process will get memory when and how much.
• Allocates the memory when a process requests it to do so.
• De-allocates the memory when a process no longer needs it or has been terminated.
6
Processor Management
In multiprogramming environment, the OS decides which process gets the processor when and for how much
time. This function is called process scheduling. An Operating System does the following activities for
processor management −
• Keeps tracks of processor and status of process. The program responsible for this task is known as
traffic controller.
• Allocates the processor (CPU) to a process.
• De-allocates processor when a process is no longer required.
Device Management
An Operating System manages device communication via their respective drivers. It does the following
activities for device management −
• 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.
File Management
A file system is normally organized into directories for easy navigation and usage. These directories may
contain files and other directions.
An Operating System does the following activities for file management −
• Keeps track of information, location, uses, status etc. The collective facilities are often known as file
system.
• Decides who gets the resources.
7
aids.
Coordination between other softwares and users − Coordination and assignment of compilers, interpreters,
assemblers and other software to the various users of the computer systems.
9
The disadvantages of network operating systems are as follows −
• High cost of buying and running a server.
• Dependency on a central location for most operations.
• Regular maintenance and updates are required.
10
• When a 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.
Advantages
Batch processing takes much of the work of the operator to the computer.
Increased performance as a new job gets started as soon as the previous job is finished,
without any manual intervention.
Disadvantages
Multitasking
Multitasking is when multiple jobs are executed by the CPU simultaneously by switching between them.
Switches occur so frequently that the users may interact with each program while it is running. An OS does
the following activities related to multitasking −
The user gives instructions to the operating system or to a program directly, and receives an immediate
response.
The OS handles multitasking in the way that it can handle multiple operations / executes multiple programs
at a time.
Multitasking Operating Systems are also known as Time-sharing systems.
These Operating Systems were developed to provide interactive use of a computer system at a reasonable
cost.
A time-shared operating system uses the concept of CPU scheduling and multiprogramming to provide
each user with a small portion of a time-shared CPU.
Each user has at least one separate program in memory
11
A program that is loaded into memory and is executing is commonly referred to as a process.
When a process executes, it typically executes for only a very short time before it either finishes or needs
to perform I/O.
Since interactive I/O typically runs at slower speeds, it may take a long time to complete. During this time,
a CPU can be utilized by another process.
The operating system allows the users to share the computer simultaneously. Since each action or command
in a time-shared system tends to be short, only a little CPU time is needed for each user.
As the system switches CPU rapidly from one user/program to the next, each user is given the impression
that he/she has his/her own CPU, whereas actually one CPU is being shared among many users.
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.
User feels that many programs are allotted CPU almost simultaneously.
Disadvantages
CPU scheduling is required.
12
To accommodate many jobs in memory, memory management is required.
Interactivity
Interactivity refers to the ability of users to interact with a computer system. An Operating system does the
following activities related to interactivity −
Distributed Environment
A distributed environment refers to multiple independent CPUs or processors in computer system. An
operating system does the following activities related to distributed environment −
The OS distributes computation logics among several physical processors.
The processors do not share memory or a clock. Instead, each processor has its own local
memory.
The OS manages the communications between the processors. They communicate with each
other through various communication lines.
13
Lesson 2: Memory Management
Memory Management
Memory management is the functionality of an operating system which handles or manages primary memory
and moves processes back and forth between main memory and disk during execution. Memory management
keeps track of each and every memory location, regardless of either it is allocated to some process or it is free.
It checks how much memory is to be allocated to processes. It decides which process will get memory at what
time. It tracks whenever some memory gets freed or unallocated and correspondingly it updates the status.
Single process monitor
Mono programming or uni programming system.
Program must be brought (from disk) into memory and placed within a process for it to be executed.
Input queue – collection of processes on the disk that are waiting to be brought into memory for execution.
User programs go through several steps before being executed
Binding of Instructions and Data to Memory
Address binding of instructions and data to memory addresses can happen at three different stages
Compile time: If memory location known a priori, absolute code can be generated; must recompile code
if starting location changes.
Load time: Must generate relocatable code if memory location is not known at compile time
Execution time: Binding delayed until run time if the process can be moved during its execution from one
memory segment to another. Need hardware support for address maps (e.g., base and limit registers)
Multistep Processing of a User Program
Dynamic Loading
If the routines are loaded in the main memory at the time of execution or running then it is called dynamic
loading.
Routine is not loaded until it is called.
Advantages - Better memory-space utilization; unused routine is never loaded.
Useful when large amounts of code are needed to handle infrequently occurring cases.
No special support from the operating system is required implemented through program design.
Dynamic Linking
Linking at the time of execution is known as dynamic linking.
Linking is postponed until execution time.
Small piece of code, stub (is used to locate the appropriate memory-resident library routine.) is included in
the image for each library routine reference.
When the stub is executed, it checks to see whether the needed routine is already in memory if not it loads
it into the memory.
Stub replaces itself with the address of the routine, and executes the routine.
Unlike dynamic loading, dynamic linking generally requires help from the operating system.
Swapping
A Process needs to be in memory to be executed.
A process can be swapped temporarily out of memory to a backing store, and then brought back into
memory for continued execution. (fig.)
15
Backing store – fast disk large enough to accommodate copies of all memory images for all users; must
provide direct access to these memory images.
Roll out, roll in variant – swapping variant used for priority-based scheduling algorithms; lower-priority
process is swapped out so higher-priority process can be loaded and executed.
Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory
swapped.
Modified versions of swapping are found on many systems, i.e., LINUX and Microsoft Windows.
System maintains a ready queue of ready-to-run processes which have memory images on disk
Contiguous Allocation
16
Partitioning
Single-partition allocation
In this type, relocation register scheme are used to protect user processes from each other, and from changing
operating-system code and data.
Relocation register contains value of smallest physical address and limit register contains range of logical
addresses. Each logical address must be less than the limit register.
Multiple-partition allocation
In this type, main memory is divided into a number of fixed sized partitions where each partition should
contain only one process. When a partition is free a process is selected from the input queue and is loaded
into free partition. When the process terminates the partition becomes available for another process. It supports
multiprogramming
Hole – block of available memory; holes of various size are scattered throughout memory.
o When a process arrives, it is allocated memory from a hole large enough to accommodate it.
o Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
When process 8 terminates then it creates a hole. Then process 9 starts and so on
17
There are many solutions to this problem. The set of holes is searched to determine which hole is best to
allocate. There are some common strategies (algorithms) used to select a free hole from the set of available
holes -
o First-fit: Allocates the process in first hole or first free large enough partition.
o Best-fit: Allocates the process in the smallest possible hole or memory partition.
o Worst-fit: Allocates the process in the largest hole or largest possible memory partition; must also search
entire list
o Next-fit: It is same as first fit but doesn’t start from first partition. It starts from the place where the last
partition ended. It is fast in searching.
o External fragmentation – it exists when enough total memory space exists to satisfy a request, but it is not
contiguous. Storage is fragmented into a large number of small holes.
o
o Internal fragmentation – allocated memory may be slightly larger than requested memory; this size
difference is memory internal to a partition, but not being used.
o One solution to the problem of external fragmentation is compaction.
The goal is to shuffle memory contents to place all free memory together in one large block.
Compaction is possible only if relocation is dynamic, and is done at execution time.
Eg. The three holes of sizes 100k, 300k and 260k can be compacted into one hole of size 660k
As Compaction is not always possible in every case so we have other solutions also.
Paging
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 that's set up to emulate the computer's RAM.
Paging technique plays an important role in implementing virtual memory.
Paging is a memory management technique in which process address space is broken into blocks of the same
size called pages (size is power of 2, between 512 bytes and 8192 bytes). The size of the process is measured
in the number of pages.
Similarly, main memory is divided into small fixed-sized blocks of (physical) memory called frames and the
size of a frame is kept the same as that of a page to have optimum utilization of the main memory and to
avoid external fragmentation.
18
Paging Hardware Architecture
Memory Protection
Segmentation
Segmentation is a memory management technique in which each job is
divided into several segments of different sizes, one for each module that
contains pieces that perform related functions. Each segment is actually a different logical address space of
the program.
20
Lesson 3: Virtual Memory
Virtual Memory
Virtual memory – is a separation of user logical memory from physical memory. In this method, we keep only
a part of the user’s point of view process in the memory and other part on the disk (Secondary storage). Here,
we need to maintain entire image of the process in disk storage.
Advantages-
Only part of the program needs to be in memory for execution
Logical address space can therefore be much larger than physical address space
Need to allow pages to be swapped in and swapped out.
Demand Paging
o Complete process should be in the disk in the form of pages.
o In this technique, a page is brought into the memory for its execution only when it is demanded.
The process of loading the page into memory on demand (whenever page fault occurs) is known as demand
paging.
21
The process includes the following steps:
Advantages
Less I/O needed
Reduces memory requirement.
Swap time is also reduced.
Faster response
More users
22
Also known as Lazy Swapper method as it swaps the pages only when it is needed.
Page Fault
o When the page (data) requested by the program is not available in the memory, it is called page fault. This
usually results in the application being shut down.
o It is used in the performance measurement.
o If there is a reference to a page, first reference to that page will trap to operating system:
23
Page Replacement Algorithm
o It is the technique used by operating system to decide which memory pages to swap out.
o It is also decided that in memory, how many frames to allocate to each process.
o When page replacement is required, we must select the frames that are to be replaced.
o Prevent over-allocation of memory by modifying page-fault service routine to include page replacement
o Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are written to disk
o Page replacement completes separation between logical memory and physical memory – large virtual
memory can be provided on a smaller physical memory
24
o Want lowest page-fault rate
o Evaluate algorithm by running it on a particular string of memory references (reference string) and
computing the number of page faults on that string
25
26
Counting Algorithms
o Keep a counter of the number of references that have been made to each page
o LFU Algorithm (Least Frequently used): replaces page with smallest count or frequency
o MFU Algorithm (Most Frequently Used) : replaces a page that has the maximum frequency count of all
pages.
Allocation of Frames
OS allocates Frames to Main Memory using these allocation schemes -
Global replacement – process selects a replacement frame from the set of all frames; one process can take a
frame from another process.
o That is, Process P1 can take frame from Process P2 and vice versa.
o Here we can store page of Process P1 in Frame of Process P2 also and vice versa.
o Disadvantage is that the paging behavior of one process depends upon paging behavior of another process.
Local replacement – each process selects from only its own set of allocated frames
Thrashing
Thrashing is a situation if the system spends more time in paging instead of their execution.
OR
Thrashing is a process where processes are busy swapping pages in and out.
If a process does not have “enough” pages for execution then the page-fault rate will be very high. This leads
to:
o low CPU utilization
o operating system thinks that it needs to increase the degree of multiprogramming
o another process added to the system
28
working-set window i.e a fixed number of page references
Example: 10,000 instruction
Three cases arise-
l if too small will not encompass entire locality
l if too large will encompass several localities
l if = will encompass entire program
if D (demand for the process) > m (main memory frames) Thrashing will occur
Policy if D > m, then suspend one of the processes
Demand Paging
Operating system also uses demand segmentation, which is similar to
demand paging. Operating system to uses demand segmentation where
there is insufficient hardware available to implement ‘Demand Paging’.
29
o The segment table has a valid bit to specify if the segment is already in physical memory or not. If a
segment is not in physical memory, then segment fault results, which traps to the operating system and brings
the needed segment into physical memory, much like a page fault.
o Demand segmentation allows for pages that are often referenced with each other to be brought into memory
together, this decreases the number of page faults.
o If there is no space in the memory then LRU segment is chosen for replacement and is written to disk.
But it suffers from the problem of external fragmentation.
D) Conclusion
This unit is an attempt to provide a detailed understanding of operating system, its functions and its types.
Concepts of memory management, swapping, difference between paging and segmentation and detailed
description of virtual memory with all replacement algorithms. Concepts of thrashing and other
considerations.
Q1. Which of the following page replacement algorithms suffers from Belady’s anomaly?
A) FIFO
B) LRU
C) Optimal Page Replacement
D) Both LRU and FIFO
Q4. When the memory allocated to a process is slightly larger than the process, then:
A) internal fragmentation occurs
B) external fragmentation occurs
C) both a and b
D) neither a nor
30
A) Large secondary memory
B) Large main memory
C) Illusion of large main memory
D) None of the above
Q8. Consider data given in the above question. What is the minimum number of pages colours needed to
guarantee that no two synonyms map to different sets in the processor cache of this computer?
A) 2
B) 4
C) 8
D) 16
Q11. A multilevel page table is preferred in comparison to a single level page table for translating virtual
address to physical address because
A) It reduces the memory access time to read or write a memory location.
B) It helps to reduce the size of page table needed to implement the virtual address space of a process.
C) It is required by the translation lookaside buffer.
D) It helps to reduce the number of page faults in page replacement algorithms.
Q16. Run time mapping from virtual to physical address is done by:
A) memory management unit
B) CPU
C) PCI
D) none of the mentioned
Q17. Memory management technique in which system stores and retrieves data from secondary storage for
use in main memory is called:
A) fragmentation
B) paging
C) mapping
D) none of the mentioned
Q25. If relocation is static and is done at assembly or load time, compaction _________.
A) cannot be done
B) must be done
C) must not be done
D) can be done
Q26. The disadvantage of moving all process to one end of memory and all holes to the other direction,
producing one large hole of available memory is :
A) the cost incurred
B) the memory used
C) the CPU used
D) All of these
Q29. In ………………. technique, each process is divided into a number of segments and process loaded by
loading all of its segments into dynamic partitions that need not be contiguous.
A) Fixed partitioning
B) Simple Paging
C) Virtual memory paging
D) Simple segmentation
Q30. Which of the following is/are the strengths of virtual memory segmentation techniques used in
memory management.
i) No internal fragmentation
ii) A higher degree of multiprogramming
iii) More efficient to use of main memory
iv) Large virtual address space
v) Protection and sharing support?
Ans. An Operating System is the interface between the computer hardware and the end-user. Processing of
data, running applications, file management and handling the memory is all managed by the computer OS.
Windows, Mac, Android etc. Are examples of Operating systems which are generally used nowadays. All
modern computing devices including Laptops, Tablet, mobile phones, etc. comprise an Operating System
which helps in the smooth working of the device.
Q2. What are different types of Operating system. Explain in brief.
Ans. Different types of Operating System along with brief information about each of them:
1. Batch Operating System
34
2. Real-Time Operating System
Multiple people at various terminals can use a program at the same time
The main motive is to minimize the response time
4. Distributed Operating System
When two or more systems are connected to each other and one can open files which are not present in
their system but in other devices connected in the network
Its usage has now increased over the years
They use multiple central processors to serve real-time applications
Failure of one system does not affect the other systems connected in the network
5. Embedded Operating System
They have one main server which is connected to other client servers
All the management of files, processing of data, access to sharing files, etc. are performed over this small
network
It is also a secure operating system for working with multiple users
• It helps with memory management. It keeps a track of the files being saved in the Main memory and the
primary memory of the computer device
Whenever a computer is turned on, the Operating system automatically starts to work. Thus, the booting
and rebooting process of a computer device is also an important function of the OS
It provides a user interface
Managing of basic peripheral devices is done by the operating system
Using the password protection option of an operating system, the data in the device can be kept secure
It coordinates with the software and the user
Easy navigation and organisation of files and programs are managed by the OS
35
Any kind of program which needs to be run through the system is done by the operating system
If any kind of error or bug is found during the program is detected using the operating system
Ans. In operating systems, memory management is the function responsible for managing the computer's
primary memory. The memory management function keeps track of the status of each memory location, either
allocated or free. It tracks when memory is freed or unallocated and updates the status.
Ans. Six famous memory management techniques are: Fixed Partitioning, Dynamic Partitioning, Simple
Paging, Simple Segmentation, Virtual-Memory Paging and Virtual- Memory Segmentation.
Ans.
36
Q7. Explain demand paging?
Ans. Demand paging is a method that loads pages into memory on demand. This method is mostly used in
virtual memory. In this, a page is only brought into memory when a location on that particular page is
referenced during execution. The following steps are generally followed:
Ans. It is a memory management technique feature of OS that creates the illusion to users of a very large
(main) memory. It is simply space where a greater number of programs can be stored by themselves in the
form of pages. It enables us to increase the use of physical memory by using a disk and also allows us to have
memory protection. It can be managed in two common ways by OS i.e., paging and segmentation. It acts as
temporary storage that can be used along with RAM for computer processes.
37
Q9. What is thrashing in OS?
Ans. It is generally a situation where the CPU performs less productive work and more swapping or paging
work. It spends more time swapping or paging activities rather than its execution. By evaluating the level of
CPU utilization, a system can detect thrashing. It occurs when the process does not have enough pages due to
which the page-fault rate is increased. It inhibits much application-level processing that causes computer
performance to degrade or collapse.
Ans. Multitasking: It is a system that allows more efficient use of computer hardware. This system works on
more than one task at one time by rapidly switching between various tasks. These systems are also known as
time-sharing systems.
Multiprocessing: It is a system that allows multiple or various processors in a computer to process two or
more different portions of the same program simultaneously. It is used to complete more work in a shorter
period of time.
Teams of 2 or 3 students will select an operating system topic that is not covered in class or important topics
from the syllabus and present it to their peers in the final week of this semester by making a relevant
presentation on it.
38
UNIT-2: PROCESSES
B) Introduction:
This unit basically deals with the processes and their life cycle. It tells how different processes can
be scheduled together to complete particular tasks on time. A brief insight has been also given on the
concept of process synchronization which includes critical section problem, semaphores and classical
problems of synchronization.
Lesson 1: Process
PROCESSES:
39
Process Life Cycle
When a process executes, it passes through different states. These stages may differ in different
operating systems, and the names of these states are also not standardized.
In general, a process can have one of the following five states at a time.
40
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 as listed below in the table −
The architecture of a PCB is completely dependent on Operating System and may contain different
information in different operating systems. Here is a simplified diagram of a PCB –
41
The PCB is maintained for a process throughout its lifetime, and is deleted once the process
terminates.
Process Scheduling:
Definition
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.
Process scheduling is an essential part of a Multiprogramming operating systems. Such operating
systems allow more than one process to be loaded into the executable memory at a time and the
loaded process shares the CPU using time multiplexing.
42
The OS can use different policies to manage each queue (FIFO, Round Robin, Priority, etc.). The OS
scheduler determines how to move processes between the ready and run queues which can only have
one entry per processor core on the system; in the above diagram, it has been merged with the CPU.
Schedulers
Schedulers are special system software which handles 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
Short-Term Scheduler
Medium-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. Process loads into the memory for CPU scheduling.
The primary objective of the job scheduler is to provide a balanced mix of jobs, such as I/O bound
and processor bound. It also controls the degree of multiprogramming. If the degree of
multiprogramming is stable, then the average rate of process creation must be equal to the average
departure rate of processes leaving the system.
On some systems, the long-term scheduler may not be available or minimal. Time-sharing operating
systems have no long term scheduler. When a process changes the state from new to ready, then there
is use of long-term scheduler.
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. CPU
scheduler selects a process among the processes that are ready to execute and allocates CPU to one
of them.
43
Short-term schedulers, also known as dispatchers, make the decision of which process to execute
next. Short-term schedulers are faster than long-term schedulers.
Medium-term scheduling is a part of swapping. It removes the processes from the memory. It reduces
the degree of multiprogramming. The medium-term scheduler is in-charge of handling the swapped
out-processes.
A running process may become suspended if it makes an I/O request. A suspended process cannot
make any progress towards completion. In this condition, to remove the process from memory and
make space for other processes, the suspended process is moved to the secondary storage. This
process is called swapping, and the process is said to be swapped out or rolled out. Swapping may
be necessary to improve the process mix.
Comparison among Scheduler
Context Switch
A context switch is the mechanism to store and restore the state or context of a CPU in Process
Control block so that a process execution can be resumed from the same point at a later time. Using
this technique, a context switcher enables multiple processes to share a single CPU. Context
switching is an essential part of a multitasking operating system features.
When the scheduler switches the CPU from executing one process to execute another, the state from
the current running process is stored into the process control block. After this, the state for the process
to run next is loaded from its own PCB and used to set the PC, registers, etc. At that point, the second
process can start executing.
44
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 information
45
A process may be created by another process using fork(). The creating process is called the parent
process and the created process is the child process. A child process can have only one parent but a
parent process may have many children. Both the parent and child processes have the same memory
image, open files, and environment strings. However, they have distinct address spaces.
A diagram that demonstrates process creation using fork() is as follows −
2. Process Preemption
An interrupt mechanism is used in preemption that suspends the process executing currently and the
next process to execute is determined by the short-term scheduler. Preemption makes sure that all
processes get some CPU time for execution.
A diagram that demonstrates process preemption is as follows −
3. Process Blocking
The process is blocked if it is waiting for some event to occur. This event may be I/O as the I/O events
are executed in the main memory and don't require the processor. After the event is complete, the
process again goes to the ready state.
46
A diagram that demonstrates process blocking is as follows −
4. Process Termination
After the process has completed the execution of its last instruction, it is terminated. The resources
held by a process are released after it is terminated.
A child process can be terminated by its parent process if its task is no longer relevant. The child
process sends its status information to the parent process before it terminates. Also, when a parent
process is terminated, its child processes are terminated as well as the child processes cannot run if the
parent processes are terminated.
47
Lesson 2: CPU Scheduling
CPU SCHEDULING:
Whenever the CPU becomes idle, the operating system must select one of the processes in the ready
queue to be executed. The selection process is carried out by the short-term scheduler (or CPU
scheduler). The scheduler selects from among the processes in memory that are ready to execute and
allocates the CPU to one of them.
Another component involved in the CPU scheduling function is the Dispatcher. The dispatcher is the
module that gives control of the CPU to the process selected by the short-term scheduler. This
function involves:
Switching context
Switching to user mode
Jumping to the proper location in the user program to restart that program from where it left last time.
The dispatcher should be as fast as possible, given that it is invoked during every process switch. The
time taken by the dispatcher to stop one process and start another process is known as the Dispatch
Latency. Dispatch Latency can be explained using the below figure:
CPU scheduling decisions may take place under the following four circumstances:
1. When a process switches from the running state to the waiting state(for I/O request or invocation of
wait for the termination of one of the child processes).
2. When a process switches from the running state to the ready state (for example, when an interrupt
occurs).
48
3. When a process switches from the waiting state to the ready state(for example, completion of I/O).
4. When a process terminates.
In circumstances 1 and 4, there is no choice in terms of scheduling. A new process(if one exists in the
ready queue) must be selected for execution. There is a choice, however in circumstances 2 and 3.
When Scheduling takes place only under circumstances 1 and 4, we say the scheduling scheme is non-
preemptive; otherwise, the scheduling scheme is preemptive.
Non-Preemptive Scheduling
Under non-preemptive scheduling, once the CPU has been allocated to a process, the process keeps
the CPU until it releases the CPU either by terminating or by switching to the waiting state.
This scheduling method is used by the Microsoft Windows 3.1 and by the Apple Macintosh operating
systems.
It is the only method that can be used on certain hardware platforms because It does not require the
special hardware (for example a timer) needed for preemptive scheduling.
In non-preemptive scheduling, it does not interrupt a process running CPU in the middle of the
execution. Instead, it waits till the process completes its CPU burst time, and then after that it can
allocate the CPU to any other process.
Some Algorithms based on non-preemptive scheduling are: Shortest Job First (SJF basically non-
preemptive) Scheduling and Priority (non- preemptive version) Scheduling, etc.
Preemptive Scheduling
In this type of Scheduling, the tasks are usually assigned with priorities. At times it is necessary to run
a certain task that has a higher priority before another task although it is running. Therefore, the
running task is interrupted for some time and resumed later when the priority task has finished its
execution.
Thus this type of scheduling is used mainly when a process switches either from running state to ready
state or from waiting state to ready state. The resources (that is CPU cycles) are mainly allocated to
the process for a limited amount of time and then are taken away, and after that, the process is again
placed back in the ready queue in the case if that process still has a CPU burst time remaining. That
process stays in the ready queue until it gets the next chance to execute.
49
Some Algorithms that are based on preemptive scheduling are Round Robin Scheduling (RR), Shortest
Remaining Time First (SRTF), Priority (preemptive version) Scheduling, etc.
There are many different criteria to check when considering the "best" scheduling algorithm, they are:
1. CPU Utilization
To make out the best use of the CPU and not to waste any CPU cycle, the CPU would be working
most of the time(Ideally 100% of the time). Considering a real system, CPU usage should range from
40% (lightly loaded) to 90% (heavily loaded.)
2. Throughput
It is the total number of processes completed per unit of time or rather says the total amount of work
done in a unit of time. This may range from 10/second to 1/hour depending on the specific processes.
3. Turnaround Time
It is the amount of time taken to execute a particular process, i.e. The interval from the time of
submission of the process to the time of completion of the process(Wall clock time).
4. Waiting Time
The sum of the periods spent waiting in the ready queue amount of time a process has been waiting in
the ready queue to acquire get control on the CPU.
SCHEDULING ALGORITHMS:
51
Given: Table of processes, and their Arrival time, Execution time
Priority scheduling is a non-preemptive algorithm and one of the most common scheduling algorithms
in batch systems.
Each process is assigned a priority. Process with highest priority is to be executed first and so on.
Processes with same priority are executed on first come first served basis.
Priority can be decided based on memory requirements, time requirements or any other resource
requirement.
Given: Table of processes, and their Arrival time, Execution time, and priority. Here we are considering 1 is
the lowest priority.
52
4. Shortest Remaining Time
Shortest remaining time (SRT) is the preemptive version of the SJN algorithm.
The processor is allocated to the job closest to completion but it can be preempted by a newer ready
job with shorter time to completion.
Impossible to implement in interactive systems where required CPU time is not known.
It is often used in batch environments where short jobs need to give preference.
53
For example, CPU-bound jobs can be scheduled in one queue and all I/O-bound jobs in another queue.
The Process Scheduler then alternately selects jobs from each queue and assigns them to the CPU
based on the algorithm assigned to the queue
MULTIPROCESSOR SCHEDULING:
In multiple-processor scheduling multiple CPU’s are available and hence Load Sharing becomes
possible. However it is more complex as compared to single processor scheduling. In this there are
cases when the processors are identical i.e. HOMOGENEOUS, in terms of their functionality; we can
use any processor available to run any process in the queue.
Process Synchronization is a technique which is used to coordinate the process that use shared Data. There
are two types of Processes in an Operating Systems:-
1. Independent Process –
The process that does not affect or is affected by the other process while its execution then the process is
called Independent Process. Example The process that does not share any shared variable, database, files,
etc.
2. Cooperating Process –
The process that affect or is affected by the other process while execution, is called a Cooperating Process.
Example The process that share file, variable, database, etc are the Cooperating Process.
Process Synchronization is mainly used for Cooperating Process that shares the resources. Let us consider
an example of
54
//racing condition image
It is the condition where several processes tries to access the resources and modify the shared data
concurrently and outcome of the process depends on the particular order of execution that leads to data
inconsistency, this condition is called Race Condition. This condition can be avoided using the technique
called Synchronization or Process Synchronization, in which we allow only one process to enter and
manipulates the shared data in critical section.
55
This setup can be defined in various regions like:
Entry Section –
It is part of the process which decide the entry of a particular process in the Critical Section, out of many
other processes.
Critical Section –
It is the part in which only one process is allowed to enter and modify the shared variable. This part of the
process ensures that only no other process can access the resource of shared data.
Exit Section –
This process allows the other process that are waiting in the Entry Section, to enter into the Critical
Sections. It checks that a process that after a process has finished execution in Critical Section can be
removed through this Exit Section.
Remainder Section –
The other parts of the Code other than Entry Section, Critical Section and Exit Section are known as
Remainder Section.
Progress
Progress means that if a process is not using the critical section, then it should not stop any other
process from accessing it. In other words, any process can enter a critical section if it is free.
Bounded Waiting
Bounded waiting means that each process must have a limited waiting time. Itt should not wait
endlessly to access the critical section.
There are two approaches that are commonly used in operating system to handle critical section.
Preemptive Kernel − A preemptive kernel allows a process to be preempted while it is running in
kernel mode.
Non-Preemptive Kernels − A non-preemptive kernel doesn’t allow a process running in kernel mode
to be preempted.
Peterson’s Solution
Peterson’s solution is a classic based software solution to the critical-section problem. It is restricted to two
processes that alternate execution between their critical sections and remainder sections. Peterson’ section
requires two data items to be shared between the two processes i.e.
Int turn;
Boolean flag[2];
56
Here, variable turn indicates whose turn is to enter its critical section and flag array indicated whether the
process is ready to enter its critical section.
If turn == i, it means process Pi is allowed to enter in its critical section.
If flag[j] is TRUE, it means process j is ready to enter in its critical section
Given below is the structure of process P in Peterson’s solution
(C)Synchronization Hardware
It is implemented using two types of instructions −
(D)Semaphores
Semaphore is a synchronization tool that is used to overcome the problems generated by TestAndSet() and
Swap() instructions. A semaphore S is an integer variable that can be accessed through two standard atomic
operations that are wait() and signal()
57
Function for wait():
wait(S) {
While S <= 0
; // no operation
S--;
}
signal(S) {
S++;
}
When one process is modifying the value of semaphore then no other process can simultaneously manipulate
the same semaphore value.
Given below is the mutual-exclusion implementation with semaphore
Semaphores allow only one process into the critical section. They follow the mutual exclusion
principle strictly and are much more efficient than some other methods of synchronization.
There is no resource wastage because of busy waiting in semaphores as processor time is not wasted
unnecessarily to check if a condition is fulfilled to allow a process to access the critical section.
Semaphores are implemented in the machine independent code of the microkernel. So they are
machine independent.
Disadvantages of Semaphores
Some of the disadvantages of semaphores are as follows −
58
Semaphores are complicated so the wait and signal operations must be implemented in the correct
order to prevent deadlocks.
Semaphores are impractical for last scale use as their use leads to loss of modularity. This happens
because the wait and signal operations prevent the creation of a structured layout for the system.
Semaphores may lead to a priority inversion where low priority processes may access the critical
section first and high priority processes later.
Problem Statement
There is a buffer of n slots and each slot is capable of storing one unit of data. There are two processes running,
namely, producer and consumer, which are operating on the buffer.
A producer tries to insert data into an empty slot of the buffer. A consumer tries to remove data from a filled
slot in the buffer. As you might have guessed by now, those two processes won't produce the expected output
if they are being executed concurrently.
There needs to be a way to make the producer and consumer work in an independent manner.
Solution:
One solution of this problem is to use semaphores. The semaphores which will be used here are:
m, a binary semaphore which is used to acquire and release the lock.
empty, a counting semaphore whose initial value is the number of slots in the buffer, since, initially
all slots are empty.
full, a counting semaphore whose initial value is 0.
At any instant, the current value of empty represents the number of empty slots in the buffer and full represents
the number of occupied slots in the buffer.
59
The Producer Operation
do
Looking at the above code for a producer, we can see that a producer first waits until there is atleast
one empty slot.
Then it decrements the empty semaphore because, there will now be one less empty slot, since the
producer is going to insert data in one of those slots.
Then, it acquires lock on the buffer, so that the consumer cannot access the buffer until producer
completes its operation.
After performing the insert operation, the lock is released and the value of full is incremented because
the producer has just filled a slot in the buffer.
do
{ // wait until full > 0 and then decrement 'full'
wait(full);
// acquire the lock
wait(mutex);
60
/* perform the remove operation in a slot */
// release the lock
signal(mutex);
// increment 'empty'
signal(empty);
} while(TRUE);
The consumer waits until there is atleast one full slot in the buffer.
Then it decrements the full semaphore because the number of occupied slots will be decreased by one,
after the consumer completes its operation.
Following that, the consumer completes the removal operation so that the data from one of the full
slots is removed.
Finally, the empty semaphore is incremented by 1, because the consumer has just removed data from
an occupied slot, thus making it empty.
Problem Statement
Consider there are five philosophers sitting around a circular dining table. The dining table has five chopsticks
and a bowl of rice in the middle as shown in the below figure.
61
At any instant, a philosopher is either eating or thinking. When a philosopher wants to eat, he uses two
chopsticks - one from their left and one from their right. When a philosopher wants to think, he keeps down
both chopsticks at their original place.
Solution:
From the problem statement, it is clear that a philosopher can think for an indefinite amount of time. But when
a philosopher starts eating, he has to stop at some point of time. The philosopher is in an endless cycle of
thinking and eating.
while(TRUE)
{ wait(stick[i]);
/* mod is used because if i=5, next
chopstick is 1 (dining table is circular)
*/wait(stick[(i+1) % 5]);
/* eat */
signal(stick[i]);
signal(stick[(i+1) % 5]);
/* think */
}
When a philosopher wants to eat the rice, he will wait for the chopstick at his left and picks up that chopstick.
Then he waits for the right chopstick to be available, and then picks it too. After eating, he puts both the
chopsticks down.
But if all five philosophers are hungry simultaneously, and each of them pickup one chopstick, then a deadlock
situation occurs because they will be waiting for another chopstick forever. The possible solutions for this
are:
A philosopher must be allowed to pick up the chopsticks only if both the left and right chopsticks are
available.
Allow only four philosophers to sit at the table. That way, if all the four philosophers pick up four
chopsticks, there will be one chopstick left on the table. So, one philosopher can start eating and
eventually, two chopsticks will be available. In this way, deadlocks can be avoided.
62
3. Readers Writer Problem
Problem Statement
There is a shared resource which should be accessed by multiple processes. There are two types of
processes in this context. They are reader and writer. Any number of readers can read from the shared
resource simultaneously, but only one writer can write to the shared resource. When a writer is writing
data to the resource, no other process can access the resource. A writer cannot write to the resource if
there are non zero number of readers accessing the resource at that time.
Solution
From the above problem statement, it is evident that readers have higher priority than writer. If a writer
wants to write to the resource, it must wait until there are no readers currently accessing that resource.
Here, we use one mutex m and a semaphore w. An integer variable read_count is used to maintain
the number of readers currently accessing the resource. The variable read_count is initialized to 0. A
value of 1 is given initially to m and w.
Instead of having the process to acquire lock on the shared resource, we use the mutex m to make the
process to acquire and release lock whenever it is updating the read_count variable.
The code for the writer process looks like this:
while(TRUE)
{ wait(w);
/* perform the write operation */
signal(w);
}
And, the code for the reader process looks like this:
while(TRUE)
{
//acquire lock
wait(m);
read_count++;
if(read_count == 1)
wait(w);
//release lock
signal(m);
/* perform the reading operation */
// acquire lock
wait(m);
read_count--;
if(read_count == 0)
signal(w);
// release lock
signal(m);
}
63
Here is the Code explained
As seen above in the code for the writer, the writer just waits on the w semaphore until it gets a chance
to write to the resource.
After performing the write operation, it increments w so that the next writer can access the resource.
On the other hand, in the code for the reader, the lock is acquired whenever the read_count is updated
by a process.
When a reader wants to access the resource, first it increments the read_count value, then accesses
the resource and then decrements the read_count value.
The semaphore w is used by the first reader which enters the critical section and the last reader which
exits the critical section.
The reason for this is, when the first readers enters the critical section, the writer is blocked from the
resource. Only new readers can access the resource now.
Similarly, when the last reader exits the critical section, it signals the writer using the w semaphore
because there are zero readers now and a writer can have the chance to access the resource.
C) Conclusion
A process is a program in execution. The execution of a process must progress in a sequential fashion.
A process is defined as an entity which represents the basic unit of work to be implemented in the system.
CPU scheduling is a process that allows one process to use the CPU while the execution of another
process is on hold (in waiting state) due to unavailability of any resource like I/O etc, thereby making
full use of CPU. The aim of CPU scheduling is to make the system efficient, fast, and fair Process
Synchronization is a technique which is used to coordinate the process that use shared Data.
MCQ’S
1. The systems which allow only one process execution at a time, are called __________
a) uniprogramming systems
b) uniprocessing systems
c) unitasking systems
d) none of the mentioned
8.Which system call can be used by a parent process to determine the termination of child process?
a) wait
b) exit
c) fork
d) get
9.The address of the next instruction to be executed by the current process is provided by the ____
a) CPU registers
b) Program counter
c) Process stack
d) Pipe
10. Cascading termination refers to termination of all child processes if the parent process terminates
__
65
a) Normally
b) Abnormally
c) Normally or abnormally
d) None of the mentioned
11.Which module gives control of the CPU to the process selected by the short-term scheduler?
a) dispatcher
b) interrupt
c) scheduler
d) none of the mentioned
12. The processes that are residing in main memory and are ready and waiting to execute are kept on a
list called _____________
a) job queue
b) ready queue
c) execution queue
d) process queue
13. The interval from the time of submission of a process to the time of completion is termed as ______
a) waiting time
b) turnaround time
c) response time
d) throughput
14. Which scheduling algorithm allocates the CPU first to the process that requests the CPU first?
a) first-come, first-served scheduling
b) shortest job scheduling
c) priority scheduling
d) none of the mentioned
16. In priority scheduling algorithm, when a process arrives at the ready queue, its priority is compared
with the priority of ____________
a) all process
b) currently running process
c) parent process
d) init process
20. Which one of the following can not be scheduled by the kernel?
a) kernel level thread
b) user level thread
c) process
d) none of the mentioned
21. Which process can be affected by other processes executing in the system?
a) cooperating process
b) child process
c) parent process
d) init process
22. When several processes access the same data concurrently and the outcome of the execution
depends on the particular order in which the access takes place is called ________
a) dynamic condition
b) race condition
c) essential condition
d) critical condition
23. If a process is executing in its critical section, then no other processes can be executing in their
critical section. What is this condition called?
a) mutual exclusion
b) critical exclusion
c) synchronous exclusion
d) asynchronous exclusion
Question: What is a process scheduler? State the characteristics of a good process scheduler?
OR
What is scheduling? What criteria affect the scheduler's performance?
Answer: Scheduling can be defined as a set of policies and mechanisms which controls the order in which
the work to be done is completed. The scheduling program which is a system software concerned with
scheduling is called the scheduler and the algorithm it uses is called the scheduling algorithm.
Various criteria or characteristics that help in designing a good scheduling algorithm are:
CPU Utilization − A scheduling algorithm should be designed so that CPU remains busy as possible.
It should make efficient use of CPU.
Throughput − Throughput is the amount of work completed in a unit of time. In other words
throughput is the processes executed to number of jobs completed in a unit of time. The scheduling
algorithm must look to maximize the number of jobs processed per time unit.
Response time − Response time is the time taken to start responding to the request. A scheduler must
aim to minimize response time for interactive users.
Turnaround time − Turnaround time refers to the time between the moment of submission of a job/
process and the time of its completion. Thus how long it takes to execute a process is also an important
factor.
Waiting time − It is the time a job waits for resource allocation when several jobs are competing in
multiprogramming system. The aim is to minimize the waiting time.
Fairness − A good scheduler should make sure that each process gets its fair share of the CPU.
Question: Explain time slicing? How its duration affects the overall working of the system?
Answer: Time slicing is a scheduling mechanism/way used in time sharing systems. It is also termed as
Round Robin scheduling. The aim of Round Robin scheduling or time slicing scheduling is to give all
processes an equal opportunity to use CPU. In this type of scheduling, CPU time is divided into slices that
are to be allocated to ready processes. Short processes may be executed within a single time quantum. Long
processes may require several quanta.
The Duration of time slice or Quantum
The performance of time slicing policy is heavily dependent on the size/duration of the time quantum. When
the time quantum is very large, the Round Robin policy becomes a FCFS policy. Too short quantum causes
too many process/context switches and reduces CPU efficiency. So the choice of time quanta is a very
68
important design decision. Switching from one process to another requires a certain amount of time to save
and load registers, update various tables and lists etc.
Consider, as an example, process switch or context switch takes 5 m sec and time slice duration be 20 m sec.
Thus CPU has to spend 5 m sec on process switching again and again wasting 20% of CPU time. Let the
time slice size be set to say 500 m sec and 10 processes are in the ready queue. If P1 starts executing for first
time slice then P2 will have to wait for 1/2 sec; and waiting time for other processes will increase. The
unlucky last (P10) will have to wait for 5 sec, assuming that all others use their full time slices. To conclude
setting the time slice.
Too short will cause too many process switches and will lower CPU efficiency.
Setting too long will cause poor response to short interactive processes.
A quantum around 100 m sec is usually reasonable.
1 0 7
2 1 4
3 3 9
4 4 5
Job1 is started at time 0, being only job in queue. Job 2 arrives at time 1. The remaining time for job 1 is
larger (6 time units) than the time required by job2 (4 time units), so job 1 is preempted and job2 is scheduled.
The average turnaround time for the above is:
1 16-0 = 16
69
2 5-1 = 4
3 25-3 = 22
4 10-4 = 6
48
Question: What are the different principles which must be considered while selection of a scheduling
algorithm?
Answer: The objective/principle which should be kept in view while selecting a scheduling policy are the
following −
1. Fairness − All processes should be treated the same. No process should suffer indefinite
postponement.
2. Maximize throughput − Attain maximum throughput. The largest possible number of processes per
unit time should be serviced.
3. Predictability − A given job should run in about the same predictable amount of time and at about
the same cost irrespective of the load on the system.
4. Maximum resource usage − The system resources should be kept busy. Indefinite postponement
should be avoided by enforcing priorities.
5. Controlled Time − There should be control over the different times −
o Response time
o Turnaround time
o Waiting time
The objective should be to minimize above mentioned times.
70
Question: Shown below is the workload for 5 jobs arriving at time zero in the order given below −
1 10
2 29
3 3
4 7
4 12
Now find out which algorithm among FCFS, SJF And Round Robin with quantum 10, would give the
minimum average time.
Answer: For FCFS, the jobs will be executed as:
1 0
2 10
3 39
4 42
5 49
71
140
1 10
2 32
3 0
4 3
5 20
65
1 0
72
2 32
3 20
4 23
5 40
115
73
Block the calling process (i.e. Wait on S)
V(S) or signal(S):
If any processes are waiting on S
Start one of these processes
Else
Set S to S+1
The semaphore operation are implemented as operating system services and so wait and signal are atomic in
nature i.e. once started, execution of these operations cannot be interrupted.
Thus semaphore is a simple yet powerful mechanism to ensure mutual exclusion among concurrent
processes.
Assignment 2:
1. What is CPU scheduling in OS?
2. Is CPU scheduling performed by OS?
3. Which are the criteria used for CPU scheduling?
4. Why do we need scheduling in operating system?
5. What are the 5 scheduling types?
6. Which scheduling algorithm is best?
Assignment 3:
74
UNIT-3: DEADLOCKS AND DEVICE MANAGEMENT
B) Introduction
In a multiprogramming environment several processes may compete for a finite number of resources.
A process request resources; if the resource is available at that time a process enters the wait state.
Waiting process may never change its state because the resources requested are held by other waiting
process. This situation is known as deadlock. Apart from the deadlocks the unit also gives a detailed
understanding of the disk structures the types of disks and storage devices. The various disk scheduling
algorithms need to be studied as the main content of this chapter since the prime responsibility of the
operating system is to maintain efficiency in every functionality of the operating system.
C) Body of Content
The topics covered in this unit are mentioned below:
Lesson 1: Deadlocks, this discusses about the concept of deadlocks and the various mechanism for
detection, avoidance and prevention of deadlocks.
Lesson 2: This focuses on the concepts of disk structure, types of storage devices and various disk
scheduling algorithms.
In a multiprogramming environment several processes may compete for a finite number of resources. A
process request resources; if the resource is available at that time a process enters the wait state. Waiting
process may never change its state because the resources requested are held by other waiting process. This
situation is known as deadlock.
Example
System has 2 disk drives.
P1 and P2 each hold one disk drive and each needs another one.
2 train approaches each other at crossing, both will come to full stop and neither shall start
until other has gone.
Traffic only in one direction.
Each section of a bridge can be viewed as a resource.
If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback).
Several cars may have to be backed up if a deadlock occurs. • Starvation is possible
System Model:
A system consists of a finite number of resources to be distributed among a number of competing processes.
The resources are partitioned into several types each of which consists of a number of identical instances. A
75
process may utilized a resources in the following sequence
Request: In this state one can request a resource.
Use: In this state the process operates on the resource.
Release: In this state the process releases the resources.
Deadlock Characteristics:
In a deadlock process never finish executing and system resources are tied up. A deadlock situation can arise
if the following four conditions hold simultaneously in a system.
Mutual Exclusion: At a time only one process can use the resources. If another process
requests that resource, requesting process must wait until the resource has been released.
Hold and wait: A process must be holding at least one resource and waiting to additional
resource that is currently held by other processes.
No Preemption: Resources allocated to a process can’t be forcibly taken out from it unless it
releases that resource after completing the task.
Circular Wait: A set {P0 , P1 , …….Pn} of waiting state/ process must exists such that P0 is
waiting for a resource that is held by P1 , P1 is waiting for the resource that is held by P2 …..
P(n – 1) is waiting for the resource that is held by Pn and Pn is waiting for the resources that
is held by P4 .
A directed edge from resource type Rj to process Pi is denoted by Rj ->Pi, it signifies that an instance of
resource type Rj has been allocated to process Pi.
A directed edge Pi ->Rj is called a requested edge.
A directed edge Rj->Pi is called an assignment edge.
We represent each process Pi as a circle, each resource type Rj as a rectangle. Since resource type Rj may
have more than one instance. We represent each such instance as a dot within the rectangle. A request edge
points to only the rectangle Rj. An assignment edge must also designate one of the dots in the rectangle.
When process Pi requests an instance of resource type Rj, a request edge is inserted in the resource allocation
graph. When this request can be fulfilled, the request edge is instantaneously transformed to an assignment
edge. When the process no longer needs access to the resource, it releases the resource, as a result, the
assignment edge is deleted.
76
The sets P, R, E:
P= {P1, P2, P3}
R= {R1, R2, R3, R4}
E= {P1 ->R1, P2 ->R3, R1 ->P2, R2 ->P2, R2 ->P1, R3 ->P3}
PROCESS STATES:
Process P1 is holding an instance of resource type R2 and is waiting for an instance of resource type R1.
Process P2 is holding an instance of R1 and an instance of R2 and is waiting for instance of R3. Process P3 is
holding an instance of R3.
77
If the graph contains no cycles, then no process in the system is deadlocked. If the graph does contain a cycle,
then a deadlock may exist. Suppose that process P3 requests an instance of resource type R2. Since no resource
instance is currently available, a request edge P3 ->R2 is added to the graph.
2 cycles:
P1 ->R1 ->P2 ->R3 ->P3 ->R2 ->P1
P2 ->R3 ->P3 ->R2 ->P2
Processes P1, P2, P3 are deadlocked. Process P2 is waiting for the resource R3, which is held by process
P3.process P3 is waiting for either process P1 (or) P2 to release resource R2. In addition, process P1 is waiting
for process P2 to release resource R1.
We also have a cycle: P1 ->R1 ->P3 ->R2 ->P1
However there is no deadlock. Process P4 may release its instance of resource type R2. That resource can
then be allocated to P3, breaking the cycle.
DEADLOCK PREVENTION
For a deadlock to occur, each of the 4 necessary conditions must held. By ensuring that at least one of these
conditions cannot hold, we can prevent the occurrence of a deadlock.
Mutual Exclusion – The mutual exclusion condition holds for non sharable. The example is a printer cannot
be simultaneously shared by several processes. Sharable resources do not require mutual exclusive access and
thus cannot be involved in a dead lock. The example is read only files which are in sharing condition. If
several processes attempt to open the read only file at the same time they can be guaranteed simultaneous
access.
78
Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other
resources. Hold and wait: To ensure that the hold and wait condition never occurs in the system, we must
guaranty that whenever a process requests a resource it does not hold any other resources. There are two
protocols to handle these problems such as one protocol that can be used requires each process to request and
be allocated all its resources before it begins execution. The other protocol allows a process to request
resources only when the process has no resource. These protocols have two main disadvantages. First,
resource utilization may be low, since many of the resources may be allocated but unused for a long period.
Second, starvation is possible. A process that needs several popular resources may have to wait indefinitely,
because at least one of the resources that it needs is always allocated to some other process.
No Preemption –
If a process that is holding some resources requests another resource that cannot be immediately
allocated to it, then all resources currently being held are released
Preempted resources are added to the list of resources for which the process is waiting
Process will be restarted only when it can regain its old resources, as well as the new ones that it is
requesting.
Circular Wait – Impose a total ordering of all resource types, and require that each process requests resources
in an increasing order of enumeration. We can ensure that this condition never holds by ordering of all resource
type and to require that each process requests resource in an increasing order of enumeration. Let R 45 | P a g
e = {R1 , R2 , …….Rn}be the set of resource types. We assign to each resource type a unique integer number,
which allows us to compare two resources and to determine whether one precedes another in our ordering
Deadlock Avoidance
Requires that the system has some additional a priori information available
Simplest and most useful model requires that each process declare the maximum number of
resources of each type that it may need
The deadlock-avoidance algorithm dynamically examines the resource allocation state to ensure that
there can never be a circular-wait condition
Resource-allocation state is defined by the number of available and allocated resources, and the
maximum demands of the processes
Safe State
When a process requests an available resource, system must decide if immediate allocation leaves the system
in a safe state System is in safe state if there exists a sequence <P1, P2, P3,….Pn) of ALL the processes in the
systems such that for each Pi, the resources that Pi can still request can be satisfied by currently available
resources + resources held by all the Pj, with j < I
That is:
If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished
When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and
terminate
When Pi terminates, Pi +1 can obtain its needed resources, and so on If a system is in safe state
no deadlocks
79
If a system is in unsafe state possibility of deadlock Avoidance ensure that a system will never
enter an unsafe state
In this graph a new type of edge has been introduced is known as claim edge. Claim edge Pi→Rj indicates
that process Pj may request resource Rj ; represented by a dashed line. Claim edge converts to request edge
when a process requests a resource. Request edge converted to an assignment edge when the resource is
allocated to the process. When a resource is released by a process, assignment edge reconverts to a claim
edge. Resources must be claimed a priori in the system.
Banker’s Algorithm
This algorithm can be used in banking system to ensure that the bank never allocates all its available cash
such that it can no longer satisfy the needs of all its customer. This algorithm is applicable to a system with
multiple instances of each resource type. When a new process enter in to the system it must declare the
maximum number of instances of each resource type that it may need. This number may not exceed the total
number of resources in the system. Several data structure must be maintained to implement the banker’s
algorithm.
Let,
n = number of processes
m = number of resources types
Max: n x m matrix. If Max [i,j] = k, then process Pimay request at most k instances of resource
type Rj .
Need: n x m matrix. If Need [i,j] = k, then Pi may need k more instances of Rj to complete its
task. Need [i,j] = Max[i,j] – Allocation [i,j].
Safety Algorithm
1. Let Workand Finish be vectors of length m and n, respectively.
Initialize: Work = Available Finish [i] = false for i = 0, 1, …,n- 1.
2. Find and i such that both:
a. Finish [i] = false
b. Need ≤ Work
If no such i exists, go to step 4.
3. Work = Work + Allocation
a. Finish[i] = true; go to step 2.
4. If Finish [i] == true for all i, then the system is in a safe state.
81
3. Pretend to allocate requested resources to Pi by modifying the state as follows:
a. Available = Available – Request;
b. Allocationi= Allocationi + Requesti ;
c. Needi=Needi – Requesti ;
If safe ⇒ the resources are allocated to Pi.
If unsafe ⇒ Pi must wait, and the old resource-allocation state is restored
Example
5 processes P0 through P4 ;
3 resource types:
o A (10 instances), B (5instances), and C (7 instances).
Snapshot at time T0 :
The system is in a safe state since the sequence satisfies safety criteria. P1 requests (1, 0, 2)
Check that Request ≤ Available (that is, (1,0,2) ≤ (3,3,2) ⇒ true.
82
Executing safety algorithm shows that sequence satisfies safety requirement.
Can request for (3,3,0) by P4 be granted? –NO
Can request for (0,2,0) by P0 be granted? –NO (Results Unsafe)
Deadlock Detection
If a system doesn’t employ either a deadlock prevention or deadlock avoidance, then deadlock situation may
occur. In this environment the system must provide
An algorithm to recover from the deadlock.
An algorithm to remove the deadlock is applied either to a system which pertains single in instance
each resource type or a system which pertains several instances of a resource type.
83
a. Work = Available
b. For i = 1,2, …, n, if Allocationi≠ 0, then Finish[i] = false;otherwise, Finish[i] = true.
2. Find an index i such that both:
a. Finish[i] == false
b. Requesti≤Work
If no such i exists, go to step 4.
3. Work = Work + Allocation
Finish [i] = true
Go to step 2
4. If Finish [i] = false, for some i, 1≤ i≤ n, then the system is in a deadlock state. Moreover, if Finish [i]
= false, then process Pi is deadlocked.
Process Termination: To eliminate deadlocks by aborting a process, we use one of two methods. In both
methods, the system reclaims all resources allocated to the terminated processes.
Abort all deadlocked processes: This method clearly will break the deadlock cycle, but at a great
expense; these processes may have computed for a long time, and the results of these partial
computations must be discarded and probably recomputed later.
Abort one process at a time until the deadlock cycle is eliminated: This method incurs considerable
overhead, since after each process is aborted, a deadlock detection algorithm must be invoked to
determine whether any processes are still deadlocked.
Resource Preemption:
To eliminate deadlocks using resource preemption, we successively preempt some resources from processes
and give these resources to other processes until the deadlock cycle is broken. If preemption is required to
deal with deadlocks, then three issues need to be addressed.
Selecting a victim: Which resources and which processes are to be preempted? As in process
termination, we must determine the order of preemption to minimize cost. Cost factors may include
such parameters as the numbers of resources a deadlock process is holding, and the amount of time a
deadlocked process has thus far consumed during its execution.
Rollback: If we preempt a resource from a process, what should be done with that process? Clearly,
it cannot continue with its normal execution; it is missing some needed resource. We must rollback
the process to some safe state, and restart it from that state.
Starvation: In a system where victim selection is based primarily on cost factors, it may happen that
the same process is always picked as a victim. As a result, this process never completes its designated
task, a starvation situation that needs to be dealt with in any practical system. Clearly, we must ensure
that a process can be picked as a victim only a small finite number of times. The most common solution
is to include the number of rollbacks in the cost factor.
84
UNIT-4: INFORMATION MANAGEMENT
B) Introduction
A file is collection of specific information stored in the memory of computer system. File management is
defined as the process of manipulating files in computer system, it management includes the process of
creating, modifying and deleting the files. File structure basically comprise of four terms: Field, Record, File,
Database. The unit describes the concepts of Files and file system interfaces, the allocation methods and the
various protection and security features and techniques used in file system.
C)Body of Content
A file is a named collection of related information that is recorded on secondary storage such as
magnetic disks, magnetic tapes and optical disks. In general, a file is a sequence of bits, bytes, lines
or records whose meaning is defined by the files creator and user.
File Structure A File Structure should be according to a required format that the operating system
can understand.
A file has a certain defined structure according to its type.
A text file is a sequence of characters organized into lines.
A source file is a sequence of procedures and functions.
An object file is a sequence of bytes organized into blocks that are understandable by the machine.
When operating system defines different file structures, it also contains the code to support these
file structure. Unix, MS-DOS support minimum number of file structure
85
File management is one of the basic and important features of operating system. Operating system is used to
manage files of computer system. All the files with different extensions are managed by operating system.
A file is collection of specific information stored in the memory of computer system. File management is
defined as the process of manipulating files in computer system, it management includes the process of
creating, modifying and deleting the files. File structure basically comprise of four terms: Field, Record, File,
Database.
Field:
basic element of data
contains a single value
fixed or variable length
Record:
collection of related fields that can be treated as a unit by some application program
fixed or variable length
File:
collection of similar records
treated as a single entity
may be referenced by name
access control restrictions usually apply at the file level
Database:
collection of related data
relationships among elements of data are explicit
designed for use by a number of different applications
consists of one or more types of files
The following are some of the tasks performed by file management of operating system of any computer
system:
1. It helps to create new files in computer system and placing them at the specific locations.
2. It helps in easily and quickly locating these files in computer system.
3. It makes the process of sharing of the files among different users very easy and user friendly.
4. It helps to stores the files in separate folders known as directories. These directories help users to search file
quickly or to manage the files according to their types or uses.
5. It helps the user to modify the data of files or to modify the name of the file in the directories.
6. Provide a standardized set of I/O interface routines to user processes
7. Provide I/O support for multiple users in the case of multiple user systems
86
In the above figure shows the general hierarchy of the storage in an operating system. In this figure the root
directory is present at the highest level in the hierarchical structure. It includes all the subdirectories in which
the files are stored. Subdirectory is a directory present inside another directory in the file storage system. The
directory base storage system ensures better organization of files in the memory of the computer system.
File management of function in operating system (OS) is based on the following concepts:
1. File Attributes
It specifies the characteristics of the files such as type, date of last modification, size, location on disk etc. file
attributes help the user to understand the value and location of files. File attributes is one most important
feature. It is uses to describe all the information regarding particular file.
87
2. File Operations
It specifies the task that can be performed on a file such as opening and closing of file.
4. File Systems
It specifies the logical method of file storage in a computer system. Some of the commonly used files
systems include FAT and NTFS.
Unix like operating systems create a virtual file system, which makes all the files on all the devices appear to
exist in a single hierarchy. This means, in those systems, there is one root directory, and every file existing on
the system is located under it somewhere. Unix-like systems can use a RAM disk or network shared resource
as its root directory.
2. Linux
Linux supports numerous file systems, but common choices for the system disk on a block device include XFS,
JFS, and btrsfs. For raw flash without a flash translation layer(FTL) or Memory Technology Device(MTD),
there are UBIFS, JFFS 2 and YAFFS, among others. SquashFS is a common compressed read-only file system.
3. macOS
macOS uses the Apple File System(APFS), which recently replaced a file system inherited from classic mac
old called HFS Plus(HFS+). Apple also uses the term “Mac OS Extended” for HFS+.HFS Plus is a metadata-
rich and case-preserving but (usually) case-insensitive file system. Due to the Unix roots of macOS, Unix
permissions were added to HFS Plus. Later versions of HFS Plus added journaling to prevent corruption of the
file system structure and introduced a number of optimizations to the allocation algorithms in an attempt to
defragment files automatically without requiring an external defragmenter.
88
4. Microsoft Windows
Windows makes use of the FAT, NTFS, exFAT , Live File System and ReFS file systems (the last of these is
only supported and usable in Windows Servers, Windows 8,8.1,10.
1. Space management
File System Fragmentation occurs when unused space or single files are not contiguous. As a file system is
used, files are created, modified and deleted. When a file is created the file system allocates space for the data.
Some file systems permit or require specifying an initial space allocation and subsequent incremental
allocations as the file grows. As files are deleted the space they were allocated eventually is considered
available for use by other files. This creates alternating used and unused areas of various sizes. This is free
space fragmentation. When a file is created and there is not an area of contiguous space available for its initial
allocation the space must be assigned in fragments. When a file is modified such that it becomes larger it may
exceed the space initially allocated to it, another allocation must be assigned elsewhere and the file becomes
fragmented.
2. Filenames
A filename (or file name) is used to identify a storage location in the file system. Most file systems have
restrictions on the length of filenames. In some file systems, filenames are not case sensitive(i.e., the names
MYFILE and myfile refer to the same file in a directory); in others, filenames are case sensitive (i.e., the names
MYFILE, MyFile , and myfile refer to three separate files that are in the same directory).
3. Directories
File systems typically have directories (also called folders) which allow the user to group files into separate
collections. This may be implemented by associating the file name with an index in a table of contents or an
inode in a Unix-like file system. Directory structures may be flat (i.e. linear), or allow hierarchies where
directories may contain subdirectories. The first file system to support arbitrary hierarchies of directories was
used in the Multics operating system.
FILE DIRECTORIES:
Collection of files is a file directory. The directory contains information about the files, including
attributes, location and ownership. Much of this information especially that is concerned with storage is
managed by the operating system. The directory is itself a file, accessible by various file management
routines.
89
Type
Address
Current length
Maximum length
Date last accessed
Date last updated
Owner id
Protection information
SINGLE-LEVEL DIRECTORY
In this a single directory is maintained for all the users.
Naming problem: Users cannot have same name for two files.
Grouping problem: Users cannot group files according to their need.
90
TWO-LEVEL DIRECTORY
In this separate directories for each user is maintained.
Path name: Due to two levels there is a path name for every file to locate that file.
Now, we can have same file name for different user.
Searching is efficient in this method.
TREE-STRUCTURED DIRECTORY:
Directory is maintained in the form of a tree. Searching is efficient and also there is grouping capability.
We have absolute or relative path name for a file. Tree-Structured Directories
This generalization to a directory tree structure of arbitrary height allows users to create their own
subdirectories and organize their files accordingly.
Directory
o Becomes simply another file.
o Contains a set of files or subdirectories.
o All directories have the same internal format.
o One bit in directory entry defines entry as file or directory.
o Special commands are used to create and delete directories.
91
Advantages
Efficient searching
Grouping Capability
Each user has a current directory (working directory)
cd /spell/mail/prog
type list
Acyclic-Graph Directories
An acyclic graph is a graph with no cycle and allows us to share subdirectories and files. The same file or
subdirectories may be in two different directories. It is a natural generalization of the tree-structured directory.
... It is the point to note that the shared file is not the same as the copy file
A tree structure prohibits the sharing of files or directories.
Acyclic graphs allow directories to have shared subdirectories and files.
When the same files need to be accessed in more than one place in the directory structure ( e.g. because they
are being shared by more than one user / process ), it can be useful to provide an acyclic-graph structure.
(Note the directed arcs from parent to child.)
UNIX provides two types of links for implementing the acyclic-graph structure.
92
o A hard link (usually just called a link) involves multiple directory entries that both refer to the same file.
Hard links are only valid for ordinary files in the same file system.
o A symbolic link that involves a special file, containing information about where to find the linked file.
Symbolic links may be used to link directories and/or files in other file systems, as well as ordinary files in
the current file system.
Windows only supports symbolic links, termed shortcuts.
Hard links require a reference count, or link count for each file, keeping track of how many directory
entries are currently referring to this file. Whenever one of the references is removed the link count is reduced,
and when it reaches zero, the disk space can be reclaimed.
For symbolic links there is some question as to what to do with the symbolic links when the original file is
moved or deleted:
o One option is to find all the symbolic links and adjust them also.
o Another is to leave the symbolic links dangling, and discover that they are no longer valid the next time
they are used.
o What if the original file is removed, and replaced with another file having the same name before the
symbolic link is next used?
1. Continuous Allocation: A single continuous set of blocks is allocated to a file at the time of file creation.
Thus, this is a pre-allocation strategy, using variable size portions. The file allocation table needs just a
single entry for each file, showing the starting block and the length of the file. This method is best from the
point of view of the individual sequential file. Multiple blocks can be read in at a time to improve I/O
performance for sequential processing. It is also easy to retrieve a single block. For example, i f a file starts
93
at block b, and the ith block of the file is wanted, its location on secondary storage is simply b+i -1.
Disadvantage
External fragmentation will occur, making it difficult to find contiguous blocks of space of sufficient
length. Compaction algorithm will be necessary to free up additional space on disk.
Also, with pre-allocation, it is necessary to declare the size of the file at the time of creation.
94
2. Linked Allocation (Non-contiguous allocation) : Allocation is on an individual block basis. Each block
contains a pointer to the next block in the chain. Again the file table needs just a single entry for each file,
showing the starting block and the length of the file. Although pre-allocation is possible, it is more common
simply to allocate blocks as needed. Any free block can be added to the chain. The blocks need not be
continuous. Increase in file size is always possible if free disk block is available. There is no external
fragmentation because only one block at a time is needed but there can be internal fragmentation but it
exists only in the last disk block of file.
Disadvantage:
3. Indexed Allocation:
It addresses many of the problems of contiguous and chained allocation. In this case, the file allocation
table contains a separate one-level index for each file: The index has one entry for each block allocated to
the file. Allocation may be on the basis of fixed-size blocks or variable-sized blocks. Allocation by blocks
eliminates external fragmentation, whereas allocation by variable-size blocks improves locality. This
allocation technique supports both sequential and direct access to the file and thus is the most popular
form of file allocation.
95
Disk Free Space Management
Just as the space that is allocated to files must be managed, so the space that is not currently allocated to
any file must be managed. To perform any of the file allocation techniques, it is necessary to know what
blocks on the disk are available. Thus we need a disk allocation table in addition to a file allocation table.
The following are the approaches used for free space management.
1. Bit Tables: This method uses a vector containing one bit for each block on the disk. Each entry for a 0
corresponds to a free block and each 1 corresponds to a block in use.
For example: 00011010111100110001
In this vector every bit correspond to a particular block and 0 implies that, that particular block is free and
1 implies that the block is already occupied. A bit table has the advantage that it is relatively easy to find
one or a contiguous group of free blocks. Thus, a bit table works well with any of the file allocation methods.
Another advantage is that it is as small as possible.
2. Free Block List: In this method, each block is assigned a number sequentially and the list of the numbers
of all free blocks is maintained in a reserved block of the disk.
96
Limitations
It may be advantageous or necessary to have files in a different file system than they currently exist. Reasons
include the need for an increase in the space requirements beyond the limits of the current file system. The
depth of path may need to be increased beyond the restrictions of the file system. There may be performance
or reliability considerations. Providing access to another operating system which does not support the existing
file system is another reason.
97
I/O Control: consists of device drivers and interrupt handlers to transfer information between the main
memory and the disk system. The device driver writes specific bit patterns to special locations in the I/O
controller’s memory to tell the controller which device location to act on and what actions to take. The Basic
File System needs only to issue commands to the appropriate device driver to read and write physical blocks
on the disk. Each physical block is identified by its numeric disk address (Eg. Drive 1, cylinder 73, track2,
sector 10).
The File Organization Module knows about files and their logical blocks and physical blocks. By knowing
the type of file allocation used and the location of the file, file organization module can translate logical block
address to physical addresses for the basic file system to transfer. Each file’s logical blocks are numbered
from 0 to n. so, physical blocks containing the data usually do not match the logical numbers. A translation is
needed to locate each block.
The Logical File System manages all file system structure except the actual data (contents of file). It maintains
file structure via file control blocks. A file control block (inode in Unix file systems) contains information
about the file, ownership, permissions, location of the file contents
98
Lesson 2: Protection and File Security
Protection
Files must be kept safe for reliability ( against accidental damage ), and protection ( against deliberate
malicious access. ) The former is usually managed with backup copies. This section discusses the latter.
One simple protection scheme is to remove all access to a file. However this makes the file unusable, so
some sort of controlled access must be arranged.
Types of Access
The files which have direct access of the any user have the need of protection. The files which are not
accessible to other users doesn’t require any kind of protection. The mechanism of the protection provide
the facility of the controlled access by just limiting the types of access to the file. Access can be given or
not given to any user depends on several factors, one of which is the type of access required. Several
different types of operations can be controlled:
Access Control
There are different methods used by different users to access any file. The general way of protection is to
associate identity-dependent access with all the files and directories an list called access-control list
(ACL) which specify the names of the users and the types of access associate with each of the user. The
main problem with the access list is their length. If we want to allow everyone to read a file, we must list
all the users with the read access. This technique has two undesirable consequences:
Constructing such a list may be tedious and unrewarding task, especially if we do not know in advance the
list of the users in the system.
Previously, the entry of the any directory is of the fixed size but now it changes to the variable size which
results in the complicates space management. These problems can be resolved by use of a condensed version
of the access list. To condense the length of the access-control list, many systems recognize three
classification of users in connection with each file:
Owner – Owner is the user who has created the file.
Group – A group is a set of members who has similar needs and they are sharing the same file.
Universe – In the system, all other users are under the category called universe.
99
One approach is to have complicated Access Control Lists, ACL, which specify exactly what access is
allowed or denied for specific users or groups.
o The AFS uses this system for distributed access.
o Control is very finely adjustable, but may be complicated, particularly when the specific users involved
are unknown. (AFS allows some wild cards, so for example all users on a certain remote system may be
trusted, or a given username may be trusted when accessing from any remote system.)
UNIX uses a set of 9 access control bits, in three groups of three. These correspond to R, W, and X
permissions for each of the Owner, Group, and Others. (See "man chmod" for full details.) The RWX bits
control the following privileges for ordinary files and directories:
In addition there are some special bits that can also be applied:
The set user ID (SUID) bit and/or the set group ID (SGID) bits applied to executable files temporarily
change the identity of whoever runs the program to match that of the owner / group of the executable program.
This allows users running specific programs to have access to files (while running that program) to which
they would normally be unable to access. Setting of these two bits is usually restricted to root, and must be
done with caution, as it introduces a potential security leak.
The sticky bit on a directory modifies write permission, allowing users to only delete files for which they
are the owner. This allows everyone to create files in /tmp, for example, but to only delete files which they
have created, and not anyone else's.
The SUID, SGID, and sticky bits are indicated with an S, S, and T in the positions for execute permission
for the user, group, and others, respectively. If the letter is lower case, (s, s, t), then the corresponding execute
permission is not also given. If it is upper case, (S, S, T), then the corresponding execute permission IS given.
The numeric form of chmod is needed to set these advanced bits.
100
Progress Check: MCQ’s and long answer question
101
d) ) user will need to remember a lot of passwords
Answer D
8. In a different level directory structure :
a) the subdirectories do not need protection once the directory is protected
b) the same previous techniques will be used as in the other structure
c) a mechanism for directory protection will have to apply
d) none of the mentioned
Answer C
9. The directory protection is handled in Unix _________ to the file protection.
a) none of the mentioned
b) it is not handled at all
c) similar
d) different
Answer C
10. Each containing a file system or ______, Disks are segmented into one or more partitions.
a) left ‘ripe’
b) made into swap space
c) made into backup space
d) left ‘raw’
Answer D
11. Such as access by fraudulent people , Destruction of files for malicious reasons is classified as being
a)unauthorized access
b)accessed
c)destroyed
d)modified
Answer D
12. If the order of operation on two or more files are similar in files, then the operation will be
a)sequential
b)combinational
c)complex
d)simple
Answer D
13. In which records are accessed from and inserted into file Access is classified as;
a)random access
b)duplicate access
c)direct access
d)sequential access
Answer D
102
14. A ……………….. is the basic element of data where individual field contains a single value, such as an
employees last name, a data or the value of the sensor reading.
A) field
B) record
C) file
D) database
Answer A
15. A ……………………. is collection of related fields that can be treated as a unit by some application program.
A)field
B)record
C)file
D) database
Answer B
16. …………………….. communicate directly with peripheral devices or their controllers or channels.
A)Device drivers
B) Physical I/O
C) Basic I/O supervisor
D) Logical I/O
Answer A
17. The ……………………. is responsible for all file I/O initiation and termination.
A) Device drivers
B) Physical I/O
C) Basic I/O supervisor
D) Logical I/O
Answer C
18. ……………………….. provides a general purpose record I/O capability and maintains basic data about files.
A) Device drivers
B) Physical I/O
C) Basic I/O supervisor
D) Logical I/O
Answer D
19. In the ……………………… file organization, data are collected in the order in which they arrive where each
record consists of one burst of data.
A) pile
B) sequential
103
C) indexed sequential
D) indexed
Answer A
20. In …………………….. file organization, a fixed format is used for records where all records are of the same
length, consisting of the same number of fixed length fields in a particular order.
A) pile
B) sequential
C) indexed sequential
D) indexed
Answer B
21. The ……………………… maintains the key characteristic of the sequential file: Records are organized in
sequence based on a key field.
A) pile
B) sequential file
C) indexed sequential file
D) indexed file
Answer C
22. The ……………………… retains one limitation of the sequential file: effective processing is limited to that
which is based on a single field of the file.
A) pile
B) sequential file
C) indexed sequential file
D) indexed file
Answer C
23. …………………… are used mostly in applications where data are rarely processed exhaustively.
A) pile
B) sequential file
C) indexed sequential file
D) indexed file
Answer D
24. Airline reservation systems and inventory control system are the examples of …………………….. system.
A) pile
B) sequential file
C) indexed sequential file
D) indexed file
Answer B
25. The …………………. greatly reduced the time required to access a single record, without sacrificing the
sequential nature of the file.
A) pile
B) sequential file
C) indexed sequential file
D) indexed file
104
Answer C
26. In free space management, …………. method has negligible space overhead because there is no need for a disk
allocation table, merely for a pointer to the beginning of the chain and the length of the first portion.
A) Bit tables
B) Chained Free Portions
C) Indexing
D) Free Block List
Answer B
27. In …………………….. method on free space management, each block is assigned in a reserved portion of the
disk.
A) Bit tables
B) Chained Free Portions
C) Indexing
D) Free Block List
Answer D
28. A ………………… on free space management has the advantages that it relatively easy to find one or a
contiguous group of free blocks.
A) Bit table
B) Chained Free Portion
C) Indexing
D) Free Block List
Answer A
29. In ………………………….. method, the file allocation table contains a separate one level index for each file,
the index has one entry for each portion allocated to the file.
A) Chained allocation
B) Indexed allocation
C) Contiguous allocation
D) Variable allocation
Answer B
30. ………………….. is a preallocation strategy, using variable size portions where the file allocation table needs
just a single entry for each file, showing the starting block and the length of the file.
A) Chained allocation
B) Indexed allocation
C) Contiguous allocation
D) Variable allocation
Answer C
105
Long Answer Questions
1. What is a File?
A file is a named collection of related information that is recorded on secondary storage. A file contains either
programs or data. A file has certain “structure” based on its type.
File attributes: Name, identifier, type, size, location, protection, time, date
File operations: creation, reading, writing, repositioning, deleting, truncating, appending, renaming
File types: executable, object, library, source code etc.
Several pieces of information are associated with an open file which may be: File pointer
File open count, Disk location of the file Access rights
6. What is Directory?
The device directory or simply known as directory records information- such as name, location, size, and
type for all files on that particular partition. The directory can be viewed as a symbol table that translates file
names into their directory entries.
106
7. What are the operations that can be performed on a Directory?
8. What are the most common schemes for defining the Logical Structure of aDirectory?
The most general scheme to implement identity-dependent access is to associate with each file and directory
an access control unit.
107
The time taken by the head to move to the appropriate cylinder or track is called seek time. Once the head is
at right track, it must wait until the desired block rotates under the read-write head. This delay is latency time.
Three major methods of allocating disk space which are widely in use are
Contiguous allocation
Linked allocation
Indexed allocation
Teams of 2 or 3 students will be allotted a topic from the subject of operating system covered in class or
important topics from the syllabus and will be required to give a presentation to their peers during the end of
semester by making a relevant presentation particularly including the higher level concepts and using the
practical approach for the same.
108
Keywords:
Operating System, swapping, paging, segmentation, virtual memory, page replacement, demand paging,
thrashing, Semaphores, Process, scheduling algorithms, Arrival Time (AT), Completion Time (CT), Burst
Time (BT), Turn Around Time (TAT), Turn Around Time (TAT), Response Time, Gant Chart, Deadlocks,
resource Allocation Graph, mutual exclusion, hold and wait, circular wait, no preemption, bankers algorithm,
file allocation, access control mechanism, file operations, allocation methods, directory structure, seek time,
latency time, free space management, security, file protection.
• Silbersachatz and Galvin, “Operating System Concepts”, John Wiley & Sons, 7th Ed. 2005
• Haldar/Aravind, “Operating System”, Pearson Edu.
• “Thomas Anderson and Michael Dahlin, “Operating Systems: Principles & Practices, Volume III Memory
Management”, Second Edition
• Andrew S.Tanenbaum and Herbert Bos, “Modern Operating System”, Pearson.
References
• Madnick E., Donovan J., “Operating Systems”, Tata McGraw Hill, 2001
• Tannenbaum, “Operating Systems”, PHI, 4th Edition, 2000
• An Introduction to Operating Systems: Concepts & Practice, Bhatt, PHI
• William Stallings, “Operating Systems: Internals and Design Principles”, Seventh Edition, Prentice Hall
109