COMP 20103 Operating Systems
COMP 20103 Operating Systems
SYSTEMS
Compiled by:
TABLE OF CONTENTS
MODULE 1: INTRODUCTION TO OPERATING SYSTEM................................................................. 1
Overview ................................................................................................................................................. 1
Objectives .............................................................................................................................................. 1
Lesson 1: Definition, Function, and Goals of Operating System ........................................................ 1
What is Operating System? ............................................................................................................... 1
Functions of Operating System ....................................................................................................... 2
1. Memory Management ................................................................................................................. 2
2. Processor Management ............................................................................................................. 2
3. Device Management .................................................................................................................... 2
4. File Management .......................................................................................................................... 3
5. Security .......................................................................................................................................... 3
6. Control over system performance .......................................................................................... 3
7. Job Accounting ............................................................................................................................ 3
8. Error detecting aids .................................................................................................................... 3
9. Coordination between other software and users ................................................................ 3
Goals of the Operating System ........................................................................................................ 3
Lesson 2: History of Operating System .................................................................................................. 4
The First Generation (1940’s to early 1950’s) ............................................................................... 4
The Second Generation (1955 to 1965) .......................................................................................... 4
The Third Generation (1965 - 1980) ................................................................................................. 5
The Fourth Generation (1980-Present Day)................................................................................... 6
Lesson 3: Types of Operating System .................................................................................................... 7
Batch Operating System .................................................................................................................... 7
Time-Sharing Operating System ...................................................................................................... 7
Distributed Operating System .......................................................................................................... 8
Network Operating System................................................................................................................ 9
Real-Time Operating System .......................................................................................................... 10
Handheld Operating System ........................................................................................................... 11
Lesson 4: Components of Operating System ...................................................................................... 13
Components of Operating System ................................................................................................ 13
Reading Assignment ......................................................................................................................... 14
References / Sources / Bibliography ............................................................................................ 14
Objectives
At the end of this module, the student can be able to:
Summarize the objectives and functions of modern operating systems.
Determine the functions of a contemporary operating system with respect to convenience,
efficiency, and ability to evolve.
Compare and contrast different types of operating system.
Additionaly, users can interact directly with the Operating System through a user interface such
a computer command line or graphical user interface (GUI).In its most general sense is software
that allows the user to run another application on a computing device. Without an Operating
System a computer and software would be useless.
Since the operating system serves as a computer's fundamental user interface, it significantly
affects how you interact with the device. Therefore, many users prefer to use a specific operating
system.
1. Memory Management
It refers to management of Primary Memory or Main Memory. There are some activities
that follow for the memory management: It keeps tracks of primary memory, the memory
addresses that have already been allocated and the memory addresses of the memory that has
not yet been used. In multi programming, the OS decides the order in which process are granted
access to memory, and for how long. It allocates the memory to a process when the process
requests it and deallocates the memory when the process has terminated or is performing an I/O
operation.
2. Processor Management
The OS decides which process gets the processor when and for how much time this
function is called process scheduling. It does 3 job. The first one is to keep tracks of processor
status of a process. The program responsible for this task is known as traffic controller. The
second one is allocating the processor (GPU) to a process and the third one is De-allocating the
processor when a process is no longer required.
3. Device Management
An Operating System manages device communication via their respective drivers. It does
the following activities for device management: a. Keeps tracks for all devices. The program
responsible for this task is known as the I/O Controller. b. Decides which process gets the device
when and for how much time. c. Allocates the device in the most efficient way. d. De-allocates
devices.
4. File Management
A file system is normally organized into directories for easy navigation and usage. These
directories may contain files and other directories. An OS does the following activities for file
management: a. Keeps track of information, location, uses, status, etc. The collective facilities are
often known as file system. b. Decides who gets the resources. c. Allocates the resources d. De-
allocates the resources
5. Security
Data is an important part of computer system. The operating system protects the data stored
on the computer from illegal use, modification or deletion. By means of password and similar other
techniques, it prevents unauthorized access to programs and data.
7. Job Accounting
Keeping track of time and resources used by various jobs and users.
Overhead, besides operating system monitors use of resources to make certain of efficiency.
The second goal of Operating System is user convenience to make user comfortable to done their
task OS ensures user friendly interfaces such as GUI (Graphical User Interface) it makes that
user is easy to done their task further more noninterference in the activities of its user. User can
face interference in computational activities. The operating system also prevents illegal file access
because the system knows which data can access by whom only the authorize user can access
the data.
Note: Use convenience has higher priority than efficient use of a computer in windows operating
system while efficient use of a computer system has higher priority than use convenience in Unix
Operating system.
The First Generation started from 1945 to 1955 were technology has been used as a
vacuum tubes and operating system was not present and the language was a machine language
which is called binary language.
The second generation was from 1955 to 1965 were technology was transistors, operating
system is present, and the language was used assembly and high level language. Around 1955,
transistors were introduced and first operating system was Fortran Monitor System was introduce
in a computers, and also FORTRAN is a high level language was used.
Batch System was used in this generation to reduce the time new methodology is adopted
known as a batch system. Also to execute the program two commuters were used IBM 1401 for
reading cards, copying tapes, and printing output, and IBM 7094 for real computing. The working
of batch system in second generation were all magnetic tapes are mounted on a tape drive;
operator load special program which read the first job from the tape and run it. Output was written
unto the second tape, after each job finished, the OS automatically read next job from the tape
and output tape inserted into IBM 1401 for printing.
By the late 1960’s Operating System designers were able to develop the system of
multiprogramming in which a computer program will be able to perform multiple jobs at the same
time. The introduction of multiprogramming is a major part in the development of Operating
Systems because it allowed a CPU to be busy nearly 100 % of the time that it was in operation.
Another major development during the third generation was the phenomenal growth of mini
computers starting with the DEC PDP-1 in 1961. The PDP-1 had only 4K of 18-bit words, but at
$120,000 per machine (less than 5 percent of the price of a 7094), it sold like hotcakes. These
microcomputers help create a whole new industry and the development of more PDP's. These
PDP's helped lead to the creation of personal computers which are created in the fourth
generation. In the same year, the first version of the UNIX operating system was created. This
operating system was easily adapted to new systems and has attained rapid acceptance. It
is written in C and is free to use during the first few years.
Third generation was from 1965-1975 were technology was integrated circuits, operating
system was present and the language was used is high level language. In this generation
computers are based on Integrated Circuits and was invented by Robert Noyce and Jack Kilby in
1958-1959.
Integrated Circuits are
single component containing
number of transistors. Few
examples of this are PDP-8, PDP-
11, ICL 2900,IBM 360,IBM 370
and many more. Also like the
second generation, third
generation are also fast, reliable
and high-level languages
appeared. The used of IC in a
computer provides a small part of
a computer not only to reduce but
also improves the performance of Figure 1.2: Integrated Circuits (ICs)
a computer as compared to
others or previous computers because these computers reduced the computational time from
microseconds to nanoseconds. In this generation, it uses an operating system for better resources
and used the concept of time-sharing and multiple programing. But IC chips are difficult to
maintain first it required air conditioning and the technology required the manufacturing of IC
chips. And this IC chips are cheaper than the second generation.
Along with the creation of Microsoft is the making of Apple Macintosh. Steve Jobs, co-
inventor of Apple computer, adapted GUI and Apple Macintosh became a huge success not
only because it is cheaper but with the adaption of GUI it is user-friendly. When Microsoft
decided to build a newer version of MS- DOS, it became solely based on the success of
Macintosh and Windows was created.
During the mid-1980s, there where growths of network operating systems and
distributed operating systems being used in every personal computer. Today, numerous types
of operating system are being used in different types of machines.
In this type of OS, several independent yet interconnected computers can communicate
with each other using a shared communication network. These so called “independent systems”
have their own memory unit and central processing unit (CPU). These systems can also be
referred to as loosely coupled (distributed) systems. In loosely coupled systems, the
components are less dependent on each other or depend on each other to the least extent
possible. Also, in this OS, it is possible for a user’s system to access the files or software of
another system given that the systems are both connected on the same network. An example of
this OS is LOCUS.
These types of systems are not readily available as they are very expensive. Not only that
the underlying software is highly complex and not understood well yet.
In this OS, all users are aware of the configuration of other users within the same network
(i.e., individual connections) which allows the users and the system itself to function or work more
efficiently. Which is why systems in this type of OS are also known as tightly coupled systems.
In tightly coupled systems, hardware and software components are highly independent on each
other, which explains the reason why all the users should be aware of the configuration of other
users. Examples of this OS include Microsoft Windows Server 2008, UNIX, Linux, Mac OS X.
[Link]
The Crazy Programmer. 10 Aug. 2019,
systems. Examples of real-time systems are: Air Traffic Control
2019/03/types-of-operating-
process and respond to inputs is very small. This time interval is called
response time.
[Link]
crucial for the system to function efficiently. This system is used when
the time requirements for the specific response time is very strict like
missile systems, air traffic control systems, robots, etc. Examples of
Real-Time Operating Systems include medical imaging systems, Figure 1.7: Real-Time OS Visual
industrial control systems, robots, air traffic control systems, etc. Representation
Hard Real-Time Systems: These OSs are meant for the applications where time
constraints are very strict and even the shortest possible delay is not acceptable. These
systems are built for saving life like automatic parachutes or air bags which are required to
be readily available in case of any accident. Virtual memory is almost never found in these
systems.
Soft Real-Time Systems: This type of Real-Time OS is used when the application’s time
constraints is less strict. In soft real-time system, meeting the time limit is not compulsory
for every time and task but of course, the system cannot miss the deadline for every task or
process, it can miss the deadline but not every time. If the deadline is not met frequently
then there will be consequences, up to the point where the system can no longer be used.
Examples of soft real-time systems are personal computers, audio system, video system,
etc.
Table 1.2: Major Differences between Hard and Soft Real-Time Systems
Characteristic Hard Real-Time Soft Real-Time
Response Time Hard-required Soft-required
Peak-load performance Predictable Degraded
Control of pace Environment Computer
Safety Often critical Non-critical
Size of data files Small/Medium Large
The above table shows the major differences between hard and soft real-time systems.
The response time requirements of hard real-time systems are in the order of milliseconds or less
and can result in a catastrophe if not met. In contrast, the response time requirements of soft real-
time systems are higher and not very stringent. In a hard real-time system, the peak-load
performance must be predictable and should not violate the predefined deadlines. In a soft real-
time system, a degraded operation in a rarely occurring peak load can be tolerated. A hard real-
time system must remain synchronous with the state of the environment in all cases. On the other
hand soft real-time systems will slow down their response time if the load is very high. Hard real-
time systems are often safety critical. Hard real-time systems have small data files and real-time
databases. Temporal accuracy is often the concern here. Soft real-time systems for example, on-
line reservation systems have larger databases and require long-term integrity of real-time
systems. If an error occurs in a soft real-time system, the computation is rolled back to a previously
established checkpoint to initiate a recovery action. In hard real-time systems, roll-back/recovery
is of limited use.
Advantages of RTOS:
Maximum Consumption: Maximum utilization of devices and system, thus more output
from all the resources
Task Shifting: Time assigned for shifting tasks in these systems are very less. For example
in older systems it takes about 10 micro seconds in shifting one task to another and in latest
systems it takes 3 micro seconds.
Focus on Application: Focus on running applications and less importance to applications
which are in queue.
Real time operating system in embedded system: Since size of programs are small,
RTOS can also be used in embedded systems like in transport and others.
Error Free: These types of systems are error free.
Memory Allocation: Memory allocation is best managed in these type of systems.
Disadvantages of RTOS:
Limited Tasks: Very few tasks run at the same time and their concentration is very less on
few applications to avoid errors.
Use heavy system resources: Sometimes the system resources are not so good and they
are expensive as well.
Complex Algorithms: The algorithms are very complex and difficult for the designer to
write on.
Device driver and interrupt signals: It needs specific device drivers and interrupt signals
to response earliest to interrupts.
Thread Priority: It is not good to set thread priority as these systems are very less prone to
switching tasks.
Handheld OS are created to work with different types of hardware other than the standard
desktop operating systems. Examples of handheld operating systems include Palm OS, Pocket
PC, Symbian OS, Linux, Windows, etc. Handheld systems also include Personal Digital
Assistants (PDAs), such as Palm- Pilots or Cellular Telephones the ability to connect to a network
such as the Internet. They are usually of limited size, most handheld devices have limited amount
of memory, slow processors, and small display screens.
GUI (Graphic User Interface) - This interface uses graphics to interact with an operating
system such as windows, scrollbars, buttons, wizards, painting pictures, alternative icons
and many more. In this interface the information will show in the use of videos, images,
plain text, and many more.
CLI (Command Line Interface) - In this interface you have a permission to put in writing
command or console window to interact with operating system. An example of this is in
the command prompt you will put the writing command you wanted to perform so that the
computer will do the task that you have given to it.
2. Memory Manager – This mainly focuses on the allocation of memory to the different tasks.
Memory manager handles the Main Memory or RAM (also known as Random Access Memory)
and tracks of memory spaces that is needed by the running process. Multitasking consumes
memory space. Allocation of memory happens if the portion of the memory after being checked
is valid for the request, while de-allocation happens when it’s time to reclaim the memory. The
memory manager protects the space in the main memory by not allowing any alterations to
happen.
3. Process Manager – This focuses on the scheduling of tasks and the utilization of the
processor. Process scheduling is the function in the operating system that decides about the
process that gets the processor. Information sharing and exchange of processes, protection of
resources from one process to another and providing facilities for sharing and synchronization of
processes are the examples of activities being handled by the process manager. The traffic
controller is the program that keeps track of the processor as well as its status. Handling the jobs
that enter the system and managing each process within the jobs are the two levels of Process
Manager.
4. Security Manager - This manager secure the whole computer into any unauthorized process,
application and many more.
5. Secondary Storage Manager - Unlike the main memory (RAM), this manager is used to store
data that can be manipulated further in the system.
6. Device Manager – This pertains to the control of the operating system on the peripheral
devices such as the mouse, monitor, and other pertinent devices. Whenever you save a file into
a disk, the operating system does instruct the device drivers to write/store the specific file into the
auxiliary storage device. The same happens whenever you want to print a document. The
operating system is the one that instructs the printer about the accommodation of the request to
print the document. I/O controller is the program that keeps track of all the devices. Allocation and
de-allocation of resources are done by the Device Manager too.
7. File System Manager – this refers to the ability of the user in addition, deletion, modification,
and manipulation of the files. Some of the activities being handled by file manager are naming
and renaming specific files, copying files from one directory to another, and backup and recovery
of file. It simply pertains to the use of files. This manager does allocation and de-allocation of the
resources as well.
Reading Assignment
[Link]
ng%20system%20(OS)%20is,are%20run%20on%20the%20machine.&text=Almost%20
all%20computers%20use%20an%20OS%20of%20some%20type.
[Link]
[Link]
[Link]
[Link]
Silberschatz, A., Galvin, P., and Gagne, G.(2018). “Operating ‘System Concepts”, 10th
ed. John Wiley and “Sons Inc.
Stallings, Wiliam. (2018). “Operating Systems: Internals and Design Principles” 9 th ed.
Pearson Education Inc.
[Link]
20system/operating%[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Exercises
I. Familiarize the phrases and keywords below and match them with their corresponding
generations.
First electronic computer Plug boards
Microsoft emerged GUI
Rapid growth of minicomputers Multiprogramming system
Personal computers Punch cards
Machines handheld by Batch processing systems
professional operator Time-sharing OS
Simple mathematical calculations UNIX
First operating system MS DOS
GMOs
II. Multiple Choices. Match each definition to their corresponding type of operating system.
Write the letter of the correct answer.
Choices
B. Time-Sharing Operating C. Distributed Operating
A. Batch Operating System
System System
D. Network Operating E. Real-Time Operating F. Handheld Operating
System System System
III. Give at least three (3) examples of Hard Real-Time OS and Soft Real-Time OS.
No. Hard Real-Time OS Soft Real-Time OS
1
2
3
Objectives
At the end of this module, the student can be able to:
Discuss the basic functions of system startup.
Distinguish potential threats to operating systems and the security features designed to
guard against them.
Describe how computing resources are used by application software and managed by
system software.
Discuss the advantages and disadvantages of using interrupt processing.
Contras kernel and user mode in an operating system.
These components can be coordinated and form a single device like laptops. Computer
Systems can work independently from anyone else it can also access devices that are associated
with other computer systems.
1. The Hardware – These are the physical parts that play an integral role in computer
systems. It serves as the physical medium used by the clients to send, receive, and
store data. Basic examples are the motherboard, input and output devices (such as
keyboard, mouse), CPU, and storage devices.
3. The Liveware – Also known as computer users. The user instructs the PC to execute
on guidelines. Basically, it’s just you using the computer.
There are five main hardware components that make up a computer system:
1. Input Devices – used for entering data in the computer. Examples are:
a. Keyboard
b. Microphone
c. Gamepad Controllers
d. Scanner
2. Output Devices – any device that puts out the information or data to the user or to another
device. Examples are:
a. Monitor
b. Speakers
c. Headphones
d. Printer
3. Processing Devices – these are the core parts of the computer assigned to process data.
Examples are:
a. Central Processing Unit (CPU)
b. Graphics Processing Unit (GPU)
4. Storage Devices – devices that store the data in computer and has to subcategories:
a. Primary Storage Devices – smaller in size and have the fastest data speed. One
example is the Random Access Memory (RAM).
b. Secondary Storage Devices – bigger in size but has slow data speed. Some
examples are Hard Disk Drive, Optical Disk Drive, and USB Flash Disks/Drives.
1. Warm Booting – This is the process of restarting a computer that is already powered on.
2. Cold Booting – This is the process of turning on a computer after it had been powered
off completely.
The Bootloader
Relevant data in the system software has to be loaded into the main memory as soon as
the device is started, and stays there as long as the computer is running. This is made possible
by a so-called bootloader, which comes permanently integrated as a standard in most modern
OS.
Prior to boot sequence is the power-on self-test (POST), which is the initial diagnostic test
performed by a computer when it is switched on. When POST is finished, the boot sequence
begins. If there are problems during POST, the user is alerted by beep codes, POST codes or
on-screen POST error messages.
Unless programmed otherwise, the BIOS looks for the OS on Drive A first, then looks for
the Drive C. It is possible to modify the boot sequence from BIOS settings. Different BIOS models
have different key combination and onscreen instructions to enter the BIOS and change the boot
sequence. Normally, after the POST, BIOS will try to boot using the first device assigned in the
BIOS boot order. If that device is not suitable for booting, then the BIOS will try to boot from the
second device listed, and this process continues till the BIOS finds the boot code from the devices
listed.
If the boot device is not found, an error message is displayed and the system crashes or
freezes. Errors can be caused by an unavailable boot device, boot sector viruses or an inactive
boot partition.
Traps and Interrupts are events that breaks a normal sequence of orders or instructions
that is being process or executed by the CPU. In short, it is an interruption to the CPU‟s sequence
of events.
Traps or known as a fault or an exception, are synchronous interrupts that are sensed by
the CPU as an abnormal condition that means an error has happened. This will happen when
actions from programs causes the hardware devices to transfer command from the user mode.
Traps will usually switch the operating system to kernel mode, where the operating system will
not go back to its originating process until it performs various actions. Keep in mind that a trap in
a kernel mode is more fatal than a trap in a user mode. The errors can be in the form of:
The transfer of command to the trap handler is like a call to a periodic procedure, except
that it results from some outstanding situation induced by the program and identified by the
hardware, not from an explicit procedure call in the application program.
Interrupts are asynchronous which are generated or signals made by the hardware
(devices like graphics card, I/O ports, hard disk, etc.). It is in the form of request or a message
that an I/O is required. An example for this is when a key is pressed on the keyboard or when a
mouse is moved and clicked, this type of interrupts are hardware interrupts. On the other hand, a
program requiring disk input or output will generate a software interrupt.
Note: We can consider traps as “software interrupts”, and interrupts as “hardware interrupts”.
In traps and interrupts occurrence, the CPU responds by temporarily stopping the process
of a current program. It preserved and saves all the values that are related to the stopped program
such as registers, memory location of the last line of a code that was executed, etc. after saving,
the CPU transfers command to an interrupt service routine or an interrupt handler that will settle
with the appropriate action that is needed to be taken in return to the interrupt. The CPU will
resume the temporarily stopped or interrupted process after the interrupt service routine finishes
its task. The register values, etc. are restored with the use of the previously saved values that will
assure the program’s execution will continue from where it was left off.
A good analogy from this is when you will to pause the movie that you are watching
(process) to obey your mother and buy (process) outside. After you brought the thing that is
needed by your mother, you can resume the movie that you are watching. You can still be
interrupted by other means of events like an emergency phone call or an accident happen and
you had to pause it again to help.
When an interrupt is already being executed, other interrupts are disabled for the first
interrupt to be done. As the interrupt is completed its task, the interrupt mechanism is now enabled
again. This implementation scheme for the interrupt are made to avoid overlapping interrupts
when there is an ongoing interrupt.
Device Drivers
Device drivers are software components that can be augmented into an OS to handle a
specific device. Some of the common devices are keyboards, printers, scanners, digital cameras
and external storage devices. The operating system manages from device drivers to handle all
I/O devices. A device driver is the one responsible for managing the data between the peripheral
devices and it alters its local buffer storage. A device executes processes with the operating
system for a computer by transferring signals over cable or even in wireless. These devices
communicate with computing device through a connection point which are called ports. Other
devices use a set of wires or cables, those connecting cables which are called bus. A bus is a
series of wires that is set as a pathway to manage transport of data and also a firmly defined
protocol which specifies a set of messages that can be sent on the wires. The following are the
tasks that a device driver performs:
Manage requests from the device independent software by accepting the appropriate
tasks.
Execute required error handling and interact to give and take I/O with the device controller.
See to it that all processes are completed and the request is executed successfully.
I/O Operation
To begin an I/O operation, the device driver starts by loading the registers within the device
controller.
The device controller examines the files and processes the registers to determine the
appropriate tasks or action to execute.
The controller begins to manage the transfer of data from the device to its local buffer.
Once the transfer of data has been successfully completed, the device controller signals
the device driver via interrupt that has finished its task.
Then the device driver returns control to the operating system.
Polling
The process of regularly checking status of the device to see if it is time for the next I/O
operation, is called polling. Also called as the polling operation, polling actively examines the
status of an external device by a client program as a synchronous activity. Polling is most
frequently utilized in terms of I/O and additionally referred as the polled I/O or software package
driven I/O. polled operation or polling is the simplest method for an I/O device to interact with the
processor. The I/O device simply puts the data in a status register, and the processor must come
and get the data. Most of the time, devices will not require attention and when one does, it will
have to wait until it is next interrogated by the polling program.
The distinction of polling to interrupt is that it’s not a hardware mechanism, whereas the
interrupt is a hardware mechanism, polling is a protocol in which the processor steadily checks
whether the device needs attention. Wherever device tells process unit that it desires hardware
processing, in polling method, process unit keeps asking the I/O device whether or not it desires
CPU processing. The CPU continuously check every and each device hooked up thereto for
sleuthing whether or not any device desires hardware attention.
Computer storage contains a lot of different computer components and modules that are
used to store, alter, and edit data. Storage is a process through which digital or non-physical data
is managed and saved within a data storage device by the usage of computing technology. It is
a mechanism that gives access to a computer to retain data, either permanently or temporarily.
Storage is one of the primary and at the very least, an essential component of a computer
system because most of the processes that are being executed in a computer is using memory.
There are two natures of memory: the non-volatile type and volatile type.
Non-volatile memory is a type or computer memory that has the capability to hold saved
data even if the computer power is turned off. The data is permanent and is used commonly for
secondary storage or consistent storage. While volatile memory is a type of computer memory
that only manages and saves data while the device is currently used or turned on. These data
are only temporary and will be automatically removed when the device is turned off.
Memory is a fundamental component of the computer that is categorized into primary and
secondary memory.
Primary Storage
Primary storage, also as the main memory, is the area in a computer which stores data
and information for fast access.
Semiconductor chips are the principle technology used for primary memory. It’s a memory
which is used to store frequently used programs which can be directly accessed by the processing
unit for further processing. Some of the primary storage devices are the following:
Random Access Memory (RAM) – also called as the read-write memory, this type of
primary storage is volatile type of memory because the data will be removed once the
power is turned off. RAM is the major device of primary memory as it is fast but is also
quite expensive.
Read Only Memory (ROM) – this is a primary non-volatile type of memory. This memory
cannot be altered and can only be read when required or prompted. Since it is an
unchangeable memory, it used programs and processes inside of the device that are
frequently required like the system boot program.
Cache Memory – it is used to store data and processes that are often required by the
CPU so it does not have to search and manage them in the main memory. This is a small
memory and fast memory, but more expensive than RAM.
Secondary Storage
Secondary storage is another memory device for a computer that can hold, store and
manage data and information that can be permanently saved. These devices do not use power
and can store data permanently but the data from secondary storage needs to be brought into
the primary storage before the CPU can use it as the CPU usually cannot directly access the data
inside secondary storage devices. Some of the secondary devices are:
Hard Disk Drives – commonly used as secondary storage devices. They are flat, round
pieces of metal covered with magnetic disk or platter that can rotate at fast speed. It is a
non-volatile storage device in which you can store data permanently. This is also a type
of magnetic disk device.
Floppy Disks – Also known as floppies and diskettes. These secondary storage devices
were very common from mid-1970’s to 1990’s and were the most commonly used storage
devices at that time. It can store megabytes of data at most. Also a type of magnetic disk
device.
Memory Cards – these are card-shaped and small storage devices. They can be easily
plugged in a certain device due to its size, and is commonly used in smaller gadgets like
phones and cameras. It is available in different storage sizes such as 8 megabytes to 32
gigabytes and higher, depending on the brand.
Flash Drives – also called as pen drives, these are a type of portable storage device. It
is a compact and small memory storage device that can store permanent data that varies
from different sizes.
CD-ROM – CD-ROMs or Compact Disks are a disk-like optical storage device that usually
has silver color. It can store data and usually have a storage capacity of MB to GB worth
of storage.
All of these storage devices are essential to a computer and have different speed,
availability, and performance that affect processes that is being executed in a computing device.
To understand further, we can look at the figure below:
From a very simple architecture, the computer has evolved into a highly dynamic, interactive, and
complex machine. Computers which were previously standalone have also been asked to
communicate with one another through networking. This added another level of intricacy in the
design and operation of the computer which has a profound effect on its security.
Dual-mode operation forms the basis of I/O protection, memory protection, and CPU
protection. In dual-mode operation, there are two separate modes: monitor mode (also called as
“system mode” or “kernel mode”) and user mode. In monitor mode, the CPU can use all
instructions and access all areas of memory. While in user mode, the CPU is restricted to
unprivileged instructions and a specified area of memory. User code should always be executed
in user mode and the OS design ensures that it is. When responding to system calls,
traps/exceptions, and interrupts, OS code is run. The CPU automatically switches to monitor
mode.
Basically, hardware protection is divided into three (3) categories: CPU protection,
Memory protection, and I/O protection, which are explained below:
1. CPU Protection – CPU protection prevents the user program getting stuck in an
infinite loop, and neve returning control to OS. CPU usage is protected by using the
timer device, the associated timer interrupts, and OS code called the scheduler. While
running in user mode, the CPU cannot change the timer value or turn off the timer
interrupt, because these required privileged operations. Before passing the CPU to a
user process, the scheduler ensures that the timer is initialized and interrupts are
enabled. When a timer interrupt occurs, the timer interrupt handler (OS code) can run
the scheduler (more OS code), which decides whether or not to remove the current
process from the CPU.
2. Memory Protection – Memory is protected by partitioning the memory into pieces.
While running in user mode, the CPU can only access some of these pieces. The
boundaries for these pieces are controlled by the base register and the limit register
(specifying bottom bound and number or locations, respectively). These registers can
only be set via privileged instructions.
3. I/O Protection – The I/O is protected by making all input/output instructions privileged.
While running in user mode, the CPU cannot execute them, thus, user code, which
runs in user mode, cannot execute them. User code requests I/O by making
appropriate system calls. After checking the request, the OS code, which is running in
monitor mode, can actually perform the I/O using the privileged instructions.
Reading Assignment
[Link]
Architecture#:~:text=A%20computer%20system%20is%20basically,Logic%20Unit%2C
%20Control%20Unit%20etc
[Link]
[Link]
[Link]
is%20a%20startup%20sequence,computer%20has%20a%20boot%20sequence.
[Link]
Silberschatz, A., Galvin, P., and Gagne, G.(2018). “Operating ‘System Concepts”, 10th
ed. John Wiley and “Sons Inc.
Stallings, Wiliam. (2018). “Operating Systems: Internals and Design Principles” 9 th ed.
Pearson Education Inc.
[Link]
20system/operating%[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
bootloader/#:~:text=A%20bootloader%2C%20also%20known%20as,DVD%20or%20a%
20USB%20stick.
[Link]
sequence#:~:text=Boot%20sequence%20is%20the%20order,to%20start%20the%20boo
t%20sequence.
[Link]
Exercises
I. Enumeration
1. Five (5) examples of input devices.
2. Two (2) modes in dual-mode operation.
3. Three (3) primary storage devices.
4. Two (2) I/O methods.
5. Three (3) communication devices
III. Now that you already know some of the primary storage devices, let’s focus on the
two basic primary ones, the RAM and ROM. In this exercise, use the Venn diagram to
compare and contrast these two storages.
RAM ROM
The more complex the operating system is, the more it is expected to do on behalf of its users.
Although its main concern is the execution of user programs, it also needs to take care of various
system tasks that are better left outside the kernel itself. A system therefore consists of a collection
of processes: operating-system processes executing system code and user processes executing
user code. Potentially, all these processes can execute concurrently, with the CPU (or CPUs)
multiplexed among them. By switching the CPU between processes, the operating system can
make the counter more productive. In this module, you will read about what processes are and
how they work.
Objectives
At the end of this module, the student can be able to:
Introduce the notion of a process – a program in execution, which forms the basis of all
computation.
Describe the various features of processes, including scheduling, creation, and
termination.
Explore interprocess communication using shared memory and message passing.
Describe communication in client-server systems.
Text Section – A process, sometimes known as the Text Section, also includes the
current activity represented by the value of the program counter.
Stack – Contains the temporary data, such as function parameters, returns addresses,
and local variables.
Data Section – Contains the global variable.
Heap Section – Dynamically allocated memory to process during its run time.
Context Switching
The process of saving the context of one process and loading the context of another
process is known as context switching. In simple terms, it is like loading and unloading the
process from running state to ready state.
When a high-priority process comes to ready state (i.e. with higher priority than the running
process)
An interrupt occurs.
User and kernel mode switch (though, this is not necessary)
Preemptive CPU scheduling is used.
A mode switch typically occurs for a process context switch to occur. Only the kernel can
cause a context switch.
Process Creation
A process may be created in the system for different operations. Some of the events that
lead to process creation are:
1. When a new process is created, the operating system assigns a unique Process
Identifier (PID) to it and inserts a new entry in primary process table.
2. Then the required memory space for all the elements of process such as program,
data, and stack is allocated including space for its Process Control Block (PCB).
3. Next, the various values in PCB are initialized such as:
a. Process identification part is filled with PID assigned to it in step 1 and also its
parent’s PID.
b. The processor register values are mostly filled with zeroes, except for the stack
pointer and program counter. Stack pointer is filled with the address of stack
allocated to it in step 2 and program counter is filled with the address of its
program entry point.
c. The process state information would be set to “New”.
d. Priority would be lowest by default, but user can specify any priority during
creation.
In the beginning, process is not allocated to any I/O devices or files. The user has
to request them or if this is a child process it may inherit some resources from its
parent.
4. Then, the operating system will link this process to scheduling queue and the process
state would be changed from “New” to “Ready”. Now, process is competing for the
CPU.
5. Additionally, operating system will create some other date structures such as log files
or accounting files to keep track of processes activity.
A process may be created by another process using fork(). The creating process is called
the parent process and the created process is called 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.
Process Termination
Process termination occurs when the exit system is called. A process usually exits after
its completion but sometimes there are cases where the process aborts execution and terminates.
When a process exits, resources, memory, and I/O devices are all deallocated.
When a parent process is terminated, its child process is also terminated. This
happens when a child process cannot exist without its parent process.
If a process needs additional memory more than what the system allocated,
termination happens because of memory scarcity.
A process tries to access a resource that is not allowed to use.
If the process fails to allocate a resource within the allotted time.
When a parent process requests the termination of its child process.
The task is no longer required or needed.
Each thread belongs to exactly one process and no thread can exist outside a process.
Each thread represents a separate flow of control. Threads have been successfully used in
implementing network servers and web server. They also provide a suitable foundation for parallel
execution of applications on shared memory multiprocessors. The following shows the working of
a single-threaded and a multithreaded process.
Multithreading
A thread is also known as lightweight process. The idea is to achieve parallelism by
dividing a process into multiple threads. For example, in a browser, multiple tabs can be different
threads. Microsoft Word uses multiple threads: one thread to format the text, another thread to
process the inputs, etc.
Below are some of the differences between the thread and process:
Process Thread
Process is heavy weight or resource Thread is light weight, taking lesser
intensive. resources than a process.
Process switching needs interaction with Thread switching does not need to interact
operating system. with operating system.
In multiple processing environments, each
All threads can share same set of open files,
process executes the same code but has its
child processes.
own memory and file resources.
If one process is blocked, then no other
While one thread is blocked and waiting, a
processes can execute until the first process
second thread in the same task can run.
is unblocked.
Multiple processes without using threads use Multiple threaded processes use fewer
more resources. resources.
Process Thread
In multiple processes, each process operates One thread can read, write or change another
independently of the others. thread’s data.
1. Responsiveness – If the process is divided into multiple threads, if one thread completes
its execution, then its output can be immediately returned.
2. Faster context switch – Context switch time between threads is lower compared to
process context switch. Process context switching requires more overhead from the CPU.
3. Effective utilization of multiprocessor system – If we have multiple threads in a single
process, then we can schedule threads on multiple processor. This will make process
execution faster.
4. Resource sharing – Resources like code, data, and files can be shares among all threads
within a process (Note: Stack and registers can’t be shared among the threads. Each
thread has its own stack and registers.)
5. Communication – Communication between multiple threads is easier, as the thread
shares common address space. While in process we have to follow some specific
communication technique for communication between two processes.
6. Enhanced throughput of the system – If a process is divided into multiple threads, and
each thread function is considered as one job, then the number of jobs completed per unit
of time is increased, thus increasing the throughput of the system.
Let’s put it in this way. It’s like a student attending subjects on a single room. When a time
allotted for a certain subject goes up, another professor will come in, teaching a different subject,
depending on the schedule assigned by the school. It can be also be compared to a queue in a
grocery store. The same goes for the scheduling of processes. If a process is finished, another
one will take its place, or simply be just removed from the queue, depending on the chosen
strategy.
The system maintains the three important scheduling queues for processes:
This can be compared to baking batches of cookies. Let’s say that you only have two trays
and a single oven. When you have prepared two full trays of cookies, and if you’re going to make
another batch, you have to put it somewhere else first, for example, on a plate (Job Queue),
because the trays (Ready Queue) are still unavailable. Meanwhile, a tray of unbaked cookies
must be set aside first while another tray is still being baked inside the oven (CPU) since one
cannot bake more than a tray, which then will stay on the ready queue.
The operating system can use various strategies or policies to manage each queue (such
as First Come First Serve, Shortest Job First, etc. which will be discussed on the next part of this
module). The scheduler determines how to move processes between read and run queues which
can only have one entry per processor core on the CPU as shown in the diagram above.
Schedulers
There are three types of schedulers that chooses the jobs to be submitted to the system
to decide which process is to be run. These are the long-term, short-term, and medium-term
schedulers which will be discussed below.
Long-term scheduler (also known as job scheduler) is the one responsible for
determining which programs should be admitted to the system. It selects processes from the
queue and puts them in the memory for it to be executed.
Short-term scheduler’s (also known as CPU scheduler) main task is to improve system
performance while following a certain set of criteria. It is where the change happens from ready
state to running state of the process. These are also known as dispatchers, because the manage
processes that are ready to execute and allocates CPU to one of them.
Medium-term scheduler is where the swapping part of the process occurs. Swapping
takes place whenever a process becomes suspended. When processes are suspended, it cannot
be completed anymore. Thus, removing it from the memory and placing it on the secondary
storage. This reduces the degree of multiprogramming and is necessary to improve the process
mix. For example, if a person on a line for payment forgets his/her money, he is forced to leave
the queue and come at the back again.
The main goal of this is to keep the CPU occupied all the time and to provide the least
amount of response time for every program. To do this, the scheduler should apply the appropriate
rules to swap processes in and out of the CPU.
There are two scheduling categories, namely the non-preemptive scheduling and the
preemptive scheduling. Non-preemptive scheduling is a where process will not be interrupted
and will be executed until it is finished, while preemptive scheduling is where a process can be
interrupted to give way for another process that has a higher priority of shorter job than the current
ongoing one.
Scheduling of processes is also done to finish the work/process on time. Below are
different time with respect to a process:
Arrival Time (AT) – Time at which the process arrives in the ready queue.
Completion Time – Time at which process completes its execution.
Burst Time (BT) – Time required by a process for CPU execution.
Turn Around Time (TaT) – Time difference between completion time and arrival time.
Formula: Turn Around Time = Completion Time – Arrival Time
Waiting Time (WT) – Time difference between TaT and BT.
Formula: Waiting Time = Turn Around Time – Burst Time
Non-Preemptive Preemptive
First Come First Serve (FCFS) Round Robin
Shortest Job First (SJF) Shortest Remaining Time First (SRTF)
Non-Preemptive Priority Preemptive Priority
Additional two algorithms are Multi-Level Queue (MLQ) and Multi-Level Feedback
Queue (MLFQ) which contain two or more algorithms.
Scheduling Algorithms
1. First Come First Serve (FCFS) – Simplest scheduling algorithm that schedules according
to arrival times of processes. First come first serve scheduling algorithm states that the
process that requests the CPU first is allocated the CPU first. It is implemented by using
the First In First Out (FIFO) queue. When a process enters the ready queue, its PCB is
linked onto the tall of the queue. When the CPU is free, it is allocated to the process at the
head of the queue. The running process is then removed from the queue. To put it in this
way, imagine that you are in a fast food chain, when you order a food at the cashier, you
must fall in line. Whoever comes first in line will be served first by the cashier.
Step 1: Draw a timeline for you to know the arrangement of jobs in chronological order.
J1 J2 J3 J4
0 1 3 5
Step 2: Create a Gantt chart by following the arrangement of the jobs and taking their
respective burst times.
The first job to come is J1 that arrived in time 0 and with a burst time of 5. Therefore the
Gantt chart will be
J1
5
Now, let’s check the CPU Utilization, turnaround time, and waiting time.
To compute for the CPU Utilization, use this formula:
𝑇𝑜𝑡𝑎𝑙 𝐵𝑢𝑟𝑠𝑡 𝑇𝑖𝑚𝑒
𝑥 100
𝐸𝑛𝑑 𝑇𝑖𝑚𝑒
Take note that the End Time that we are talking here is the end time of the Gantt
char. Therefore,
18
𝑥 100 = 100% 𝐶𝑃𝑈 𝑈𝑡𝑖𝑙𝑖𝑧𝑎𝑡𝑖𝑜𝑛
18
Next, we will get the turnaround and waiting time of each job as well as the average
turnaround and waiting times. Use the formula given on the previous lesson.
Job Turnaround Time Waiting Time
J1 5–0=5 5–5=0
J2 9–1=8 8–4=4
J3 12 – 3 = 9 9–3=6
J4 18 – 5 = 13 13 – 6 = 7
Average 8.75 4.25
One of the problems that the FCFS suffers is the convoy effect. Convoy effect is a
phenomenon associated with the FCFS algorithm, in which the whole operating system
slows down due to few slow processes.
2. Shortest Job First (SJF) – Process which have the shortest burst time are scheduled
first. If two processes have the same burst time then FCFS is used to break the tie.
Given the same example in FCFS, The Gantt chart using SJF will be:
J3 J2 J1 J4
0 3 7 12 18
Same formula will be used for the CPU utilization, turnaround time and waiting time.
3. Non-Preemptive Priority (NPP) – The job with the highest priority is processed first. In
case of jobs having the same priority, the job’s arrival time will be considered, therefore
processing first the job who arrived first.
Using the example in the FCFS, we will adding a priority to each job. The highest priority
will be 0, and so on.
Job Arrival Time Burst Time Priority
J1 0 5 3
J2 1 4 0
J3 3 3 2
J4 5 6 1
The Gantt chart of these jobs using the NPP will be:
J2 J4 J3 J1
0 4 10 13 18
4. Preemptive Priority – This is the preemptive version of the NPP. Both prioritizes the job
with higher priority but it preempts every time a process enters the ready state, it then
compares the priority of the new job to the current job and to all of the process inside the
ready queue and will execute the process with higher priority.
Let’s still use the given in NPP and to create a Gantt chart using the Preemptive Priority.
However, we will change the priority to be able to simulate the latter algorithm.
Job Arrival Time Burst Time Priority
J1 0 5 1
J2 1 4 0
J3 3 3 2
J4 5 6 1
5. Shortest Remaining Time First (SRTF) – This is the preemptive version of SJF but
similar process to Preemptive Priority in which the job will preempt every time a new job
enters the ready state. In this algorithm, the job with shortest burst time or remaining time
will be processed first.
Using the given in the previous algorithm, the Gantt chart for this algorithm will be:
J1 J2 J2 J3 J1 J4
0 1 3 5 8 12 18
6. Round Robin (RR) – This is the preemptive version of the FCFS. Each process is
assigned a fixed time (Time Quantum / Time Slice) in cyclic way. It is designed especially
for the time sharing system. The ready queue is treated as a circular queue. The CPU
scheduler goes around the ready queue, allocating the CPU to each process for a time
interval of up to 1-time quantum. To implement Round Robin scheduling, we keep the
ready queue as FIFO queue of processes. New processes are added to the tail of the
ready queue. The CPU scheduler pick the first process from the ready queue, sets a timer
ton interrupt after 1-time quantum, and dispatches the process. One of the two things will
then happen. The process may have a CPU burst of less than 1-quantum. In this case,
the process itself will release the CPU voluntarily. The scheduler will then proceed to the
next process in the ready queue. Otherwise, if the CPU burst of the currently running
process is longer than 1-time quantum, the timer will go off and will cause an interrupt to
the operating system. A context switch will be executed, and the process will be put at the
tail of the ready queue. The CPU scheduler will then select the next process in the ready
queue.
To have a better understanding of this algorithm, consider yourself queueing at the ATM
station where there maximum transactions allowed is 2. If you have more than 2
transactions, after your second transaction, you must go to the back of the line to give way
to the person next to you.
Using again the given in the previous algorithm, let’s create a Gantt chart using the Round
Robin with a Time Slice of 2.
J1 J2 J1 J3 J2 J4 J1 J3 J4 J4
0 2 4 6 8 10 12 13 14 16 18
7. Multilevel Queue (MLQ) – According to the priority of process, processes are places in
different queues. Generally high priority processes are placed in the top level queue.
Online after completion of processes from top level queue, lower level queued processes
are scheduled.
As you can see, the Level column is added to the table. That column is connected to this
table below in which each level is assigned to a single algorithm and a priority.
Queue No. Algorithm Priority
0 Shortest Job First High Level Queue
1 Non-Preemptive Priority Low Level Queue
Therefore, since Queue No. 0 has the highest level queue, all jobs under the said queue
will be executed first, then followed by the queue number with the next to the highest level
queue and so on.
Following the algorithm on the Queue No. 0, J3 was executed first followed by J5. Since,
there no jobs left for Queue No. 1, the next queue number will be executed then. Hence,
having J4 to be executed first followed by J2, following the algorithm on the Queue No. 1.
8. Multi-Level Feedback Queue (MLFQ) – It allows the process to move between queues.
The idea is to separate processes according to the characteristics of their CPU bursts. If
a process uses too much CPU time, it is moved to a lower-priority queue. This is similar
to MLQ however, this process can move between the queues. MLFQ keep analyzing the
behavior (time of execution) of processes and according to which it changes its priority.
The diagram and the explanation below will make you understand how MLFQ works.
Let us suppose that Queue 1 and 2 follow Round Robin with a time slice of 4 and
8, respectively, and Queue 3 follows FCFS. The implementation of MLFQ will be:
3. If a process completes the 4 unit and still has remaining burst time, then its
priority gets reduced and will be shifted to Queue 2.
4. Above steps 2 and 3 are true for Queue 2, however, must use a time slice
of 8 instead of 4. If a process has still remaining burst time after executing
for 8 unit, it will be shifted to Queue 3.
5. In the last queue, processes are scheduled in FCFS.
6. A process in lower priority can be only executed when higher priority
queues are empty.
7. A process running in the lower priority queue is interrupted by a process
arriving in the higher priority queue.
J1 J2 J3 J4 J5 J6 J1 J2 J3 J4 J5 J6 J4
0 2 4 6 8 10 12 15 17 18 21 24 26 27
Reading Assignment
[Link]
m
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Silberschatz, A., Galvin, P., and Gagne, G.(2018). “Operating ‘System Concepts”, 10th
ed. John Wiley and “Sons Inc.
Stallings, Wiliam. (2018). “Operating Systems: Internals and Design Principles” 9 th ed.
Pearson Education Inc.
[Link]
20system/operating%[Link]
[Link]
[Link]
[Link]
ion_process_creation_termination.htm
Exercises
I. Essay
1. To fully prove that you have actually understood how process scheduling works
and runs, provide two or more instances/examples that can be compared to
process scheduling queues aside from those stated in this lesson.
II. Make a Gantt chart of each algorithm using the given table below. Find the CPU
Utilization, Turn Around Time and Waiting Time (per job and average).
III. Using the given table above, make a Gantt chart for Multilevel Queue and Multi-level
Feedback Queue algorithms. Please refer to the table below for the job levels.
IV. Using the same given, make a Gantt chart using the Multilevel Feedback Queue with
the given table below.
Queue No. Algorithm Priority
0 Round Robin (q = 3) High Level Queue
1 Preemptive Priority Medium Level Queue
2 FCFS Low Level Queue
Objectives
After successful completion of this module, the student can be able to:
Learn the hardware activities involved in the retrieval/storage of data on a direct
access storage device; and
Compute the different Disk Scheduling algorithms in order to make contrasts and
comparisons of performance.
Storage Management
Storage management is defined as referring to data storage equipment management
that is used to store data generated by user/computer. Hence, it is an administrator’s tool or
collection of processes used to keep the data and storage equipment secure.
There are many Disk Scheduling Algorithms but before discussing them let’s have a quick
look at some of the important terms:
Seek Time: Seek time is the time taken to locate the disk arm to a specified track where
the data is to be read or write. So, the disk scheduling algorithm that gives minimum
average seek time is better.
Rotational Latency: Rotational Latency is the time taken by the desired sector of disk
to rotate into a position so that it can access the read/write heads. So the disk scheduling
algorithm that gives minimum rotational latency is better.
Transfer Time: Transfer time is the time to transfer the data. It depends on the rotating
speed of the disk and number of bytes to be transferred.
Disk Access Time: Disk Access Time is:
Disk Access Time= Seek time + Rotational Delay + Controller
Overhead + Queuing delay
Disk Response Time: Response Time is the average of time spent by a request waiting to
perform its I/O operation. Average Response time is the response time of the all
requests. Variance Response Time is measure of how individual request are serviced with
respect to average response time. So, the disk scheduling algorithm that gives minimum
variance response time is better.
Example: We illustrate them with a request queue (0 – 199), with the order or request 98, 183,
37, 122, 14, 124, 65, 67. The head pointer is a 53
For instance, if it takes 3ms per cylinder move to seek the request, we shall get the seek
time. To get the seek time, it will be:
Seek Time = THM x Seek Rate
= 640 x 3ms
= 1920ms
This algorithm selects the disk I/O request which requires the least disk arm movement
from its current position regardless of the direction. It allows the head to move to the closest track
in the service queue. SSTF scheduling is a form of SJF scheduling; may cause starvation of some
requests.
Using the same given in the previous algorithm, the chart would be
In this algorithm, we need another given to be able to create a chart. It can be a previous
position of the read/write head or a direction such as upward or downward. Using the same
example from the previous algorithms, we will add 40 as the previous read/write head position
prior to cylinder 53. The chart in this algorithm would be:
Using the given example from the previous algorithm with same directions from SCAN,
the chart in this algorithm would be:
analogy for this concept is the carriage return lever of a typewriter. Once it is pulled to the
rightmost direction, it resets the typing point to the leftmost margin of the paper. A typist is not
supposed to type during the movement of the carriage return lever because the line spacing is
being adjusted. The frequent use of this lever consumes time, similar to the time consumed when
the access arm is reset to its starting position.
Using the given example and direction from the previous algorithm, and the alpha (α) is
negligible, the chart in this algorithm would be:
If α has assigned value, it should be added to the THM. However, in computing the seek
time, the α must be discarded.
Using the given example and direction from the previous algorithm, and the alpha (α) is
negligible, the chart in this algorithm would be:
Reading Assignment
E-books
[Link]
[Link]
[Link]
YouTube Tutorials;
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
References / Sources
Stallings, Wiliam. (2018). “Operating Systems: Internals and Design Principles” 9th ed.
Pearson Education Inc.
Starting from the current head position, what is the total distance traversed by the disk
arm in satisfying all the requests using the ff. disk scheduling algorithm: FCFS, SSTF,
SCAN,C-SCAN, LOOK and C-LOOK.
2. The head of moving disk, with 200 tracks numbers 0 to 199, is currently serving a request
at track 133 and had just finished a request at track 123. If the rate of movement from one
track to another track is 6. What is the total head movement and seek time of each
scheduling algorithm?
The disk requests are as follows: 90 160 97 190 98 153 110 180 140
Objectives
After successful completion of this module, the student can be able to:
Identify the responsibilities of the memory manager;
Identify the different memory management strategies;
Differentiate the principles of the memory management strategies presented; and
Solve problems using the different strategies in memory management.
Introduction
Aside from managing processes, the operating system must efficiently manage the
primary storage of the computer. The component of the operating system responsible for this
function is the memory manager. As a review, module 2 has enumerated the main responsibilities
of a memory manager as the component that:
manages the memory;
allocates and de-allocates memory space needed;
keeps track of the memory spaces needed by active processes and by the operating
system itself;
keeps track of which part of memory are currently being used and by whom;
brings in and swaps out blocks of data from the secondary storage; and
decides which processes are to be loaded into memory when memory spaces become
available.
In a uniprogramming environment, the primary storage is divided into two regions: the
resident monitor where the operating system reside and the user memory where the current
program is being stored. The memory manager is not too burdened in this kind of scenario unlike
if it becomes a multiprogramming environment where the user memory is further partitioned to
accommodate several processes simultaneously processing in the system.
Question is, why share memory between processes? Why provide multiple processes to
reside in physical memory at the same time? So as to multiprogram the processor, time share
system and overlap computation and I/O, in short, maximize system performance.
The task of allocating spaces, remembering where these processes were stored, checking
that each process do not interfere with one another, and taking notes on which space is unused
calls for efficient memory management, increased utilization of spaces and increased speed in
data access. It is in this context that we need to study the different memory management
strategies available. The memory management strategies to be discussed are:
Terminologies
A user memory with 12K, 4K, 6K, 3K,10K, 15K partition means that the user memory of size
50K is divided into 6 regions as shown below.
If several processes are to enter the primary storage, the memory manager will be burdened
on how these processes will be allocated a specific region. Several strategies of allocating spaces
are available but we will only tackle the more popular ones shown in Table 5.1 like First Fit, Next
Fit, Best Fit and Worst Fit.
Using the various allocation algorithms mentioned in Table 5.1 creates spaces which cannot
be used because a process maybe too big or too small to fit into that partition. This wasted space
is called fragmentation. There are two types of fragmentation namely internal fragmentation and
external fragmentation. Internal fragmentation is wasted spaces not used within a specific
partition. External fragmentation on the other hand is a partition that was not used because the
process may be too big to fit the partition or the partition maybe too small to fit any process. Bear
in mind that external fragmentation occurs only when there is an incoming process which does
not fit any region.
One solution to be able to use this wasted space is memory compaction, where free spaces
are merged together to create a bigger space that may now fit a process. Compaction is often
called “burping the memory”.
Example:
Given a job pool:
A B C D E F G H
9k 7k 3k 8k 11k 5k 2k 13k
2. What is the Internal Fragmentation, External Fragmentation and % Memory Utilization using
the allocation strategies above?
Solution:
Region Size 12 4 6 3 10 15
A C F G B D
wasted space 3 1 1 1
Region Size 12 4 6 3 10 15
A F G B C
wasted space 3 1 1 3 12
Region Size 12 4 6 3 10 15
B G F C A D
wasted space 5 2 1 1 7
Region Size 12 4 6 3 10 15
B G F C A
wasted space 5 2 1 7 6
Given a job pool and a user memory partitioned as 12K, 6K, 6K, 6K
Arrival Memory
Job Burst Time
Time Size 12K
A 0 9 6
B 1 5 8 6K
C 2 8 4 6K
D 3 7 5 6K
Assume:
CPU Scheduling Algorithm – First Come First Served
Memory Allocation Strategy – First Fit
Memory Management Strategy – Multiple Fixed Partition
Compute IF, EF and %MU
At time = 0
Region Size 12 6 6 6
A
wasted space 3
At time = 1
Region Size 12 6 6 6
A B
wasted space 3 1
At time = 2
Region Size 12 6 6 6
A B
wasted space 3 1
At time = 3
Region Size 12 6 6 6
A B
wasted space 3 1
Our previous knowledge of CPU scheduling comes handy to know when jobs A and B will
finish their execution. Based on the Gantt Chart using FCFS CPU Scheduling Algorithm, process
A will finish at time = 6 and will release its allocation.
Gantt Chart
A
0 6
At time = 6
Region Size 12 6 6 6
C B
wasted space 4 1
Gantt Chart
A B
0 6 14
At time = 14
Region Size 12 6 6 6
C
wasted space 4
Gantt Chart
A B C
0 6 14 18
At time = 18
Region Size 12 6 6 6
D
wasted space 5
Multiple variable partition, also known as Dynamic Partition views the memory as one big
hole and allocates the memory based on the size of the process. The partition size is variable,
thus eliminating internal fragmentation. This technique is more efficient than multiple fixed
partition but the memory needs to be “burped” (compaction) from time to time to counter external
fragmentation.
Assume:
CPU Scheduling Algorithm – Round Robin with q = 5
Memory Allocation Strategy – First Fit
Memory Management Strategy – Multiple Variable Partition
User Memory starts from 25 to 45.
Compute IF, EF and %MU
At time = 0
0 25 34 45
A
Jobs not allocated = none
Internal Fragmentation (IF) = 0
External Fragmentation (EF) = 0
Total Fragmentation (TF) = 0
20 − 0
% Memory Utilization (MU) = × 100 = 100%
20
At time = 1
0 25 34 39 45
A B
Jobs not allocated = none
Internal Fragmentation (IF) = 0
External Fragmentation (EF) = 0
Total Fragmentation (TF) = 0
20 − 0
% Memory Utilization (MU) = × 100 = 100%
20
At time = 2
0 25 34 39 45
A B
Jobs not allocated = C
Internal Fragmentation (IF) = 0
External Fragmentation (EF) = 45 – 39 = 6
Total Fragmentation (TF) = 6
20 − 6
% Memory Utilization (MU) = × 100 = 70%
20
At time = 11
0 25 33 34 39 45
C B
A releases its memory space
Job not allocated = D
Internal Fragmentation (IF) = 0
External Fragmentation (EF) = 6 + 1 = 7
Total Fragmentation (TF) = 7
20 − 7
% Memory Utilization (MU) = × 100 = 65%
20
At time = 14
0 25 33 40 45
C D
B releases its memory space
Jobs not allocated = none
Internal Fragmentation (IF) = 0
External Fragmentation (EF) = 0
Simple Paging
One of the problems encountered in Multiple Variable Partition strategy is external
fragmentation. To avoid external fragmentation, allocate the physical memory to processes in
fixed size pages called frames. The physical memory is divided into a number of equal size
frames to accommodate processes which are also divided into a number of equal size page. The
process is put in by loading all of its pages into the available frames not necessarily in contiguous
frames.
Simple Segmentation
If paging is referred to memory allocation strategy using fixed length pages, then, the
processes of allocating memory using variable length blocks called segments is known as
Segmentation. Here, each process is divided into several segments and loaded into a variable
partition that is non-contiguous. This strategy gets rid of internal fragmentation and is an
improvement of multiple variable partition or dynamic partitioning.
Swapping
Swapping is a technique that permits a computer system to execute programs that are larger
than the primary storage. The technique is for the operating system to copy a part of the process
found in the secondary storage into the primary storage. When the other part of the process is
needed, it exchanges a portion of the data in primary storage (swap out) with a portion of the data
in the secondary storage (swap in). The choice on which process to swap out and which process
to swap in is made by the medium term scheduler. Figure 5.2 illustrates swapping in and out
data.
This technique is implemented by the programmer and compiler which maybe complex and
very time consuming task.
Buddy System
Overlaying permits a process to execute even though it is larger than the primary storage.
The technique is for
The buddy system memory management technique splits memory by half until a best fit
for a specific request is met. For example, if we have 512KB and we need 40KB, we divide 512
in half and then the first half in half until we can fit 40KB.
512
256 256
64 64 128 256
40 64 128 256
Once a partition is de-allocated, it will merged with its buddy to re-form the original memory
size. That is, 64KB will merge with the other 64KB and merge with the 128KB until the memory
size reverts to 512KB. Buddy system is comparatively easier to implement than paging, has little
external fragmentation and little overhead trying to do compaction of memory but, it encounters a
lot of internal fragmentation.
Reading Assignment
E-Books
[Link]
Gokey, C. (1997), "Fragmentation Example,"
[Link]
[Link]
[Link]/modules
[Link]/class/sp07/cs241/Lectures/28
YouTube tutorials:
Virtual Memory 1, 3, 4 By David Black Schaffer
Memory Management Tech guiders Tutorials 1-3,
Contiguous Memory allocation Fixed Partitioning Tech Guiders tutorial 6
Contiguous Memory Allocation – Dynamic Partitioning Tech Guiders Tutorial 8
First fit Best Fit worst Fit for Dynamic Partitioning Tutorial 12
Introduction to Paging, Tutorial 13.
References / Sources
Nutt, G. (2009), Operating Systems: A Modern Perspective, 3rd Edition, Pearson
Addison-Wesley Inc, Boston , Massachusetts.
Stallings, Wiliam. (2018). “Operating Systems: Internals and Design Principles” 9th ed.
Pearson Education Inc.
[Link] [Link]
[Link]
[Link]
[Link]/class/sp07/cs241/Lectures/28
[Link]
EXERCISES
1. Using the Job pool below:
A B C D E F G H
13k 5k 3k 11k 8k 7k 2k 9k
Assume:
CPU Scheduling Algorithm – Shortest Job First
Memory Allocation Strategy – First Fit
Memory Management Strategy – Multiple Fixed Partition
Compute IF, EF and %MU
Assume:
CPU Scheduling Algorithm – Round Robin with q = 3
Memory Allocation Strategy – First Fit
Memory Management Strategy – Multiple Variable Partition
User Memory starts from 25 to 45.
Compute IF, EF and %MU
4. On a system with 1024KB memory using the buddy system, draw a diagram showing the
allocation of memory after each of the following events.
a. Process A, request 40K
5. Given the following data using the memory management strategies enumerated:
Simulate and calculate the Internal, External and %Memory Utilization, CPU Scheduling
algorithm used is First Come First Serve and the Memory allocation strategy is First Fit.
A 0 4 9
B 0 7 7
C 0 5 3
D 0 2 8
E 0 6 11
F 0 3 5
G 0 8 2
H 0 4 13
6. Given the following data using the memory management strategies enumerated:
Simulate and calculate the Internal, External and %Memory Utilization, CPU Scheduling
algorithm used is First Come First Serve and the Memory allocation strategy is First Fit.
A 1 6 3
B 0 3 9
C 0 4 12
D 1 7 4
E 0 2 2
F 2 5 5
G 2 8 3
H 1 3 4
I 4 8 12
Objectives
After successful completion of this module, the student can be able to:
Identify the virtual memory management strategies;
Apply the different virtual memory management strategies;
Describe demand paging;
Identify the various page allocation algorithms;
Ascertain the principle involved in each of the different page replacement algorithms; and
Evaluate reference strings using the different page replacement algorithms.
It is a technique that gives an application program the notion that it has a big contiguous
real memory, when it may be physically fragmented and may even spill over to the secondary
storage. Brookshear provides a better explanation. To quote:
"Suppose, for example, that a main memory of 64 megabytes is required but only 32
megabytes is actually available. To create the illusion of the larger memory space, the
memory manager would divide the required space into units called pages and store the
contents of these pages in mass storage. A typical page size is no more than four
kilobytes. As different pages are actually required in main memory, the memory manager
would exchange them for pages that are no longer required, and thus the other software
units could execute as though there were actually 64 megabytes of main memory in the
machine."
Virtual memory concept makes use of the different computer memory available as
additional spaces to store data and instructions hence expanding the memory such that only data
and instructions which are currently needed are stored in the RAM. The operating system through
its memory manager coordinates the use of the different types of memory by tracking available
spaces, what process to be allocated or deallocated and how to move data between these various
types of memory. In essence, the operating system creates a temporary file where data is stored
when the RAM is inadequate. This temporary file uses a backing store, a fast secondary storage
device just like the hard disk drive to perform as an extension of the RAM. In this way, the
memory seems to be very big when in fact; it is just using another area where it can swap in and
out data. This technique increases the degree of multiprogramming but… beware… thrashing
may occur. Thrashing is the phenomenon of excessively shuffling portions of a process in and
out of the RAM thus slowing the processor. This can happen either because one process requires
a large amount of RAM (assuming Process A), so the operating system swaps out another
process (assuming Process B) to the secondary storage to accommodate process A. However,
Process B needs to be in main memory also.
The degree of multiprogramming can only be increased to some extent, when it reaches
its peak, thrashing occurs. To resolve thrashing problem, a user may either 1) increase the
amount of RAM in the computer or 2) decrease the number of programs concurrently running on
the computer.
Figure 6.1 show the paging architecture. In the paging implementation, the main memory
is divided into small fixed size parts known as frames. Since this frames as limited in size, we
need to split the process into smaller parts known as pages to fit the frames. The size of the page
is the same as the size of the frame. When pages of a process are created, we need to identify
each page by using a virtual / logical address. The virtual address consist of two parts namely:
page number (p) and page offset / displacement (o). To be able to access data at a given
address, the memory manager automatically gets 1) the page number (p), 2) the page offset (o),
3) translate the page number to frame number (f) and 4) gets the data at the same offset in the
frame number given. Here, the virtual address (V) is translated to physical address in main
memory(R). The figure shows that the virtual address consist of p,o and physical address consist
of f,o where the offset or displacement of the virtual (u) and physical address (R) is the same. All
we need to know is the relationship between the page number (p) and the frame number (f) which
is mapped in the page table. To be able to access a specific data in the real memory, we need
to access the page table and then fetch the data in the frame specified in the page table. In short,
we need two physical memory accesses for each virtual memory access.
To translate virtual memory (U) to physical memory (R), the formula to use:
Let U= virtual memory / logical memory R = Physical / Real Memory
P = page size f = frame number
p = page number o = page offset
For a concrete example, suppose a 32 bytes process is to be stored in a memory with a page
size of 4bytes. The process will be split into small pages of 4 bytes to fit into the physical memory.
The whole process will have 8 pages. Figure 6.2 shows that page 0 will be stored in frame 3,
page 1 in frame 5 and page 3 in frame 1. Notice that the user views that the pages are stored in
a contiguous manner but physically it is not. The only way to know where the other pages are
stored is through the page table.
from figure 6.2; logical address 6 which contain the value G is found in physical address 22.
Figure 6.2 Paging example for a 32 byte memory with 4 byte pages
What about if we would like to know the address of page no = 2 with page offset = 2. From
the formula given, we can immediately compute for the logical address as well as the physical
address. From the page table, p=2 can be found in frame no = 6.
To check, the content of p=2, o=2 is K and from figure 6.2, K can be found in physical address
26.
Presuming a user program is 2353 bytes and it should be stored in a page size of 64
bytes. How many frames are needed to store 2353 bytes? What is the offset of the last page?
U = 2353 and P = 64 ;
the last page can be found in p = U div P = 2353 div 64 = 36 and the offset (last instruction/data
of the process) is found in o = 2353 mod 64 = 49. The number of frames needed to store the
program is 37, why? because the first page starts at page 0 and base on our computation, the
last page is page 36 which equates to 37 pages = 37 frames. The last data is found in page 36
line 49, was the whole frame used? No, the size of the whole frame is 64 and the part used is
only up to 49 which shows that there is an unused space of 15 {internal fragmentation}.
Table 6.2: Characteristics of Segmentation with or without the use of Virtual Memory
Simple Segmentation Virtual Memory Segmentation
main memory is not partitioned
program is broken into segments specified by the programmer to the compiler
there is no Internal fragmentation
External fragmentation exists
Operating system maintains a segment table for each process presenting the base address
and the size of each segment.
Operating system maintains a list of free holes in main memory
Processor uses the segment number and segment offset to calculate physical address.
All segments of the process must be in Not all segments of the process need to be
main memory to execute. in main memory to execute. Segments
maybe brought it when needed or
demanded.
Bringing a segment into main memory (swap
in) may require one or more segments to be
brought out of the main memory (swap out).
Source: Stallings, W., “Modern Operating systems” 4th ed. Prentice Hall, 2001
This technique divides the program into variable sized segments like main program,
procedure, function, local variables and global variables, stack, and arrays. Each segment has a
name and a length found in a segment table as shown in Figure 6.3. Segment 0 of P1 is found
in physical memory with an address 43062. Its size is described in the limit as 25286, thus, the
whole segment 0 is from address 43062 to 68343 (43062 + 25286). Segment 1 of P1 is found in
physical memory address 68348 up to 72773.
The logical address space consists of the segment number (s) and a segment
displacement (d). This can be visualized in Figure 6.4. The physical address of a segment is
then equal to the base. The extent of the segment is computed as: base + limit. The protection
mechanism of accessing a segment in memory is to check if the limit found in the segment table
is < the displacement. If it is, then access is granted, otherwise, addressing error occurs (d should
never be > than limit).
The memory management unit (MMU) is responsible for translating a segment (s) and
displacement (d) within the segment into a physical memory address and for performing checks
to make sure that the reference to that segment (s) and displacement (d) is permitted.
Reading Assignment
E-books
[Link]/modules
[Link]
[Link]
2. A user process with 4063 bytes of memory needs to be allocated in primary memory with a
frame size of 64 bytes.
a. How many frames will be needed to store the user process?
b. Will there be an internal fragmentation? If so, what is the internal fragmentation?
c. If the snap shot of the page table shows:
Page Table
p f
5 9
43 2
28 44
3. A system using segmentation provides the segment table below. Compute the physical
address for each of the logical addresses. If the address generates a segment fault, indicate
so.
a. 0, 323
b. 1, 856
c. 2, 234
d. 3, 1009
e. 2,533
Segment Base Length
0 1311 400
1 2711 900
2 411 500
3 4211 1100
There are two major problems to implement demand paging: page/frame allocation and
page replacement. Page/Frame allocation answers the question “how many frames need to be
allocated for each process loaded in the primary memory?” and page replacement answers the
question “if a page is needed to be unloaded from the primary memory, how do we choose the
page to drop off?” Let us tackle each of these problems.
Optimal (OPT) or Selects that page that will not be referenced again for the longest
Clairvoyant period of time.
Implementation of this algorithm would require knowledge of what
pages are needed in the future.
Least Recently Used Keeps track of the last time each page was used and not when it was
(LRU) swapped in. Each page table entry contains a counter that registers
the number of times a page is referenced.
Searches table for the entry with the lowest counter value and selects
that page to be swapped out.
Uses stack data structure wherein if the pagte is not in the stack, a
page fault occurs.
Not Recently Used An approximation of LRU which makes use of a dirty bit ( a page has
(NRU) been modified or written to) and a reference bit. As a page is loaded,
the operating system sets the reference bit to 0. When the page is
accessed, the reference bit is changed to 1. The OS periodically
initializes the reference bit to 0, hence, a reference bit 0 means that it
has not been recently referenced. The page may categorically be in
any of the 4 classes.
Class 0: not referenced, clean
Class 1: not referenced, dirty
Class 2: referenced, clean
Class 3: referenced, dirty
The NRU algorithm picks a random page from the lowest category for
removal. Note that this algorithm implies that a reference page is
more important than a modified page.
Second Chance A combination of the FIFO and NRU algorithms. The oldest page is
selected as a candidate for replacement and removes it if its reference
bit is 0. If the reference bit is 1, the page is inserted at the back of the
queue, and the reference bit is set to 0. The process is repeated until
a page is selected for replacement.
It can be considered a circular queue.
Fares better than FIFO.
Clock Keeps a circular list of pages in memory, with the hand or pointer
pointing to the oldest page in the list known as the victim. When a
page needs to be replaced and no empty frames available, the victim
is inspected. If the reference bit is 0, new page replaces the victim. If
the reference bit of the victim is 1, the victim’s reference bit is set to 0.
The clock hand or pointer is incremented and process is repeated until
a page is replaced.
Random Replace a random page from all the pages currently in primary
memory.
No overhead cost in tracking page references.
Does not perform well.
Let us evaluate using a particular string of memory references and compute the page fault
incurred by each algorithm. Two important notes to consider are:
1. For a given page size, the page number will only be the one considered and not
the entire address.
2. If a page is brought into primary memory, any succeeding reference to that page
while it is still in memory will not cause a page fault.
0120 0405 0135 0650 0111 0104 0109 0145 0643 0104
0109 0145 0632 0103 0104 0107 0453 0101 0118 0160
If the size of the page is 100 bytes per page, the page denoted by the particular address sequence
is:
1 4 1 6 1 1 1 1 6 1
1 1 6 1 1 1 4 1 1 1
This is further reduced to the following reference string (ordered list of page numbers accessed
by a program):
1 4 1 6 1 6 1 6 1 4 1
To determine the number of page faults for the actual reference string, the number of page
frames needs to be given. Apparently, as the number of available frames increases, the page
fault decreases.
Reference to pages tends to be localized on a small set of pages. This locality may
manifest in two forms. If a memory location has been referenced, it is most likely to be referenced
again soon. This form is called temporal locality. The other form, spatial locality, refutes that if a
memory location is accesses, there is a good chance that a location near it will be accessed soon.
As quoted by J. Archer Harris,
How many page faults occur for the algorithms FIFO, OPT, and LRU, given the following reference
strings using three page frames?
0 3 1 2 3 6 4 0 1 4 2 4
0 3 1 2 3 6 4 0 1 4 2 4
0 3 1 2 2X 2X 2 2X 2 2 2 2
0 3X 3 3 6 4 4X 4 4 4 4
0X 0 0X 0X 0 0 1 1 1 1
No No No No No
pf pf pf pf pf pf pf
pf pf pf pf pf
9
% page fault = × 100 = 75.0 %
12
Reading Assignment
Read supplemental books
Stallings, William. “Operating systems: Internals and Design Principles”, Prentice
Hall.
Research
1. There are other variants of LRU. Name some and describe the strategy done.
2. Differentiate local replacement and global replacement.
3. What is Working Set Model (WSM)?
4. What is Least Recently Used (LRU) algorithm? What about Not Frequently Used (NFU)
Algorithm? Is there a difference between these two algorithms?
5. Discuss other page replacement algorithms like LIFO and MFU.
References / Sources
Nutt, G. (2009), Operating Systems: A Modern Perspective, 3rd Edition, Pearson Addison-
Wesley Inc, Boston , Massachusetts.
Stallings, Wiliam. (2018). “Operating Systems: Internals and Design Principles” 9 th ed.
Pearson Education Inc.
“Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.”. Martin Rinard,
osnotes@[Link], [Link]/~rinard
[Link]
[Link]
A 38
B 57
C 43
D 25
E 19
1. The available frames inside the primary storage is 20, how many frames will be
allocated to each of the processes using:
a. Equal allocation
b. Proportional allocation
2. If the process is to be split into equal pages where the page size is 8,
a. How many frames will be used by each of the processes?
b. Will there be an internal fragmentation? If so, what is the internal
fragmentation?