You are on page 1of 38

COLLEGE OF COMPUTER STUDIES 1

OPERATING SYSTEM MELJUN P.CORTES

INSTRUCTIONAL MANUAL for
CS 3112
OPERATING SYSTEM

MELJUN P. CORTES
________________________________

CS 3112
OPERATING SYSTEM
________________________________

IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR
THE DEGREE OF BACHELOR OF SCIENCE IN COMPUTER SCIENCE (BSCS)

________________________________

MELJUN P. CORTES, MBA,MPA,BSCS,ACS

DECEMBER 2005 Handouts

CCS Faculty
COLLEGE OF COMPUTER STUDIES 2

OPERATING SYSTEM MELJUN P.CORTES

Course Title: PRINCIPLES OF OPERATING SYSTEMS

Course Description:
The course examines process synchronization; input/output, buffering, file
systems; processor and memory management; virtual memeory; job scheduling;
resource allocation; systems modeling; performance measurement and
evaluation.

Course Objectives:
At the end of the term, the students should be able to:
1. Define an operating system and describe its general functions;
2. Determine the types of operating systems;
3. Understand the different types of memory partitioning techniques;
4. Describe the functions and the types of processor scheduling;
5. Discuss the functions of device and information management.

Course Outline
1. Basic Operating System
1.1 Definition of an OS
1.1.1 Function of an OS
1.1.2 Measure of Effectiveness
1.1.3 Types of OS
1.1.3.1 Size of the Underlying Hardware
1.1.3.2 Configuration
1.1.3.3 Level of Resource Sharing
1.1.3.4 Type of Interaction Permitted

1.2 Historical Perspective
1.2.1 Evolution of OS
1.2.1.1 Single Job Stream
1.2.1.2 Multiprogramming
1.2.1.3Time Sharing
1.2.1.4 Virtual Memory
1.2.1.5 Personal Computer OS
1.2.1.6 Networks
1.2.1.7 Client Server
1.2.2 Early System
1.2.3 Set Up Time / Automatic JS
1.2.4 Performance of CPU Utilization

CCS Faculty
COLLEGE OF COMPUTER STUDIES 3

OPERATING SYSTEM MELJUN P.CORTES

QUIZ NO. 1

1.3 Structure of OS
1.3.1 Monolithic Structure
1.3.2 The Kernel Approach
1.3.3 Object-Oriented Structure
1.3.4 Client Server Model
1.4 Hardware Types
1.4.1 Limitation of HW Resources
1.4.2 The Front End: Input / Output
1.4.3 Interfaces, Control Units and Channels

QUIZ NO. 2
PRELIMINARY EXAMINATION

2. Software
2.1 Software Types
2.1.1 SW and Data: Logical vs. Physical
2.1.2 The Source Data
2.1.3 Data Management
2.1.4 File Organization
2.1.4.1 Sequential File
2.1.4.2 Direct Access File
2.1.3.4 Indexed-Sequential File
2.1.5 Categories of SW
2.1.5.1 Application SW Package
2.1.5.2 4th GL's
2.1.5.3 Query Language
2.1.5.4 Report Generation
2.1.5.5 Application Generation
2.1.5.6 Decision Support System

QUIZ NO. 3

3. Storage Management
3.1 Storage Hierarchy
3.2 Storage Management Strategies
3.3 Simple Memory Management
3.4 Strategies
3.4 Virtual Memory
3.4.1 Paging
3.4.2 Segmentation
3.4.3 Page Replacement
3.4.3.1 FIFO Replacement
3.4.3.2 LRU Page Replacement

CCS Faculty
COLLEGE OF COMPUTER STUDIES 4

OPERATING SYSTEM MELJUN P.CORTES

QUIZ NO. 4
MIDTERM EXAMINATION

4. Processor Management
4.1 Process State and State Transition
4.2 The OS Kernel
4.3 Basic Operation on Process and Resources
4.3.1 Process Control
4.3.2 Resource Primitive
4.4 Interprocess Communication
4.4.1 Mutual Exclusion w/ Busy Waiting
4.4.2 Sleep and Wake-up
4.4.3 Remaphores
4.4.4 Event Counter
4.4.5 Message Passing
4.5 Scheduling Methods
4.5.1 Time Based Scheduling Algorithm
4.5.1.1 FIFO Scheduling
4.5.1.2 Last In / Last Out
4.5.1.3 Shortest Job Next
4.5.1.4 SRTF Scheduling
4.5.1.5 Multi-Level Feedback
5. Device Management
5.1 Device Characteristic, Hardware Consideration
5.2 Principles of I/O Software
5.2.1 Goals w/ the I/O SW
5.2.2 nterrupt Handlers
5.2.3 Device Handlers
5.2.4 Device Independent I/O SW
5.2.5 User Space I/O SW
5.3 I/O Traffic Controller, I/O Schedules, I/O Handlers
5.4 Deadlocks
5.4.1 Resources
5.4.2 Deadlock Modeling
5.4.3 The Ostrich Algorithm
5.4.4 Detection of Recovery
5.4.5 Deadlock Prevention
5.4.6 Deadlock Avoidance

CCS Faculty
COLLEGE OF COMPUTER STUDIES 5

OPERATING SYSTEM MELJUN P.CORTES

QUIZ NO. 5

6. The File System and its Function
6.1 A Hierarchical Model of the File 6.2 and I/O System
6.3 File System Design
6.3.1 Disk Space Management
6.3.2 File Storage
6.3.3 Directory Structure
6.3.4 Shared Files
6.3.5 File Systems Reliability
6.4 Physical Organization Methods
6.4.1 Logical File Organization
6.4.2 Physical File Organization
6.4.3 Management of Auxiliary Storage Space
6.5 File Servers

7. OS Facilities
7.1 Processor
7.2 Memory Management
7.3 File Systems
7.4 Input / Output
7.5 Other Facilities
7.5.1 User Activity
7.5.2 Logging
7.6 User Interface
7.7 Utility SW

QUIZ NO. 6
FINAL EXAMINATION

PRELIM PERIOD
What is Operating System?

Operating System it is a program that acts as an intermediary between the user of computer
and the computer hardware.
Operating System is a set of software routines that sits between the application program and
hardware.
*routines: perform key support functions such as
1. communicating with peripheral devices
2. accepting and carrying out user commands
a. load a program
b. copy a file
c. create a directory

CCS Faculty
COLLEGE OF COMPUTER STUDIES 6

OPERATING SYSTEM MELJUN P.CORTES
Operating System acts like an interface between the user and computer hardware.

FOUR COMPONENTS OF COMPUTER SYSTEM
1. Hardware – provides the basic computing resources
(CPU, Memory, I/O Devices)
2. Application Program – define the ways in which these resources are used to
solve the computing problems of the users.
(compilers, database system, games & business prog.)
3. Users – the one who solve problems in many different application programs.
(people and machines)

4. Operating System – control coordinates the use of hardware among the
Various application programs for various users.
- provides environment with other programs to do useful
work.

- allocates resources requested by specific programs users to operate
computer system fairly and efficiently.
-
PURPOSE OF OPERATING SYSTEM
To provide environment in which a user can execute program.
GOAL OF OPERATING SYSTEM
1. To make computer system convenient to use
2. To use the computer hardware efficient to use.
FUNCTIONS OF OPERATING SYSTEM
1. As a Service Provider
2. As a Resource Manager

O.S,as a Service Provider
1. Resource Manager
* Program execution
The operating system is responsible for the following activities in connection with process
management:
 the creation and deletion of both user and system processes
 the suspension and resumption of processes
 The provision of mechanisms for processes synchronization
 The provision of mechanisms for process communication
 The provision of mechanisms for deadlock handling
2. I/O Manager
* involve a file and I/O devices
3. File Manager
a. Manipulation of Data
b. Execution of Data
c. Recovery & Archiving

CCS Faculty
COLLEGE OF COMPUTER STUDIES 7

OPERATING SYSTEM MELJUN P.CORTES

4. Protection & Security
*protection involves ensuring that all access to system resources is
controlled, security eventually a password which every user having
to authenticate himself to the system.
5. Accounting
* to keep track the resources and what kind of computer resources.
6. Error Detection & Handling
*operating system needs constantly be aware of possible errors.

O.S. as a Resource Manager
1. Keeps track the status of its resources
2. Enforce a schedule among programs requesting resources
3. Allocate & De-allocate resources

HISTORY OF OPERATING SYSTEM
0th Generation – No O.S at all, machines is controlled hard-wired
(Punch-card).
- No existence of O.S only encoding

*Encoding – programming techniques that binary bit is presented through
voltages.

1st Generation – During 1950’s, simple operating system were developed that
allowed programs to be submitted in sequence and stored.
- Batch Processing / Batch Oriented Processing.

2nd Generation – During 1960’s Multi-using was developed
*Multi-using:
1. To store several programs in memory simultaneously
2. Share computer resources

3rd Generation – Mid 1960, Multiprocessing, Multiprogramming, Time-Sharing,
Real-time processing & Virtual memory were introduced.

*Virtual Memory – the ability of OS to expand the memory of computer sys.

4th Generation – the period of Networking System & Distributed O.S that provide
networking & communication function.
- Open system were introduced
- Interoperability & other network standard
- Massive memory was develop (expansion)

CCS Faculty
COLLEGE OF COMPUTER STUDIES 8

OPERATING SYSTEM MELJUN P.CORTES

5th Generation – Multimode system (1980’s)
- Provide higher resolution
- Speech synthesizers & Recognition
- Computer Vision
- Allow intelligent machines & Open System

*Multimode System – connotes multi-processing & multiprogramming
*Open System
1. Portability – a system that can be applied in any kind of
Computer environment
2. Availability – source-code licenses in short notice
3. Scalability – the code can be transferable and resizable
4. Interoperability – a system that allow sharing of files and
applications.

TYPES OF OPERATING SYSTEMS
1. Single Programmed OS / Single Job Stream
- allows execution of program one at a time.
- One program active
2. Batched OS
- allowed automatic job sequencing by a resident operating
system and improved the overall utilization of the computer.
- the common input devices were card readers & tape drivers.
- The common output devices were line printers & card punches.
- Console: a terminal that consists of switches
3. Multi-programmed OS
- jobs are kept in memory at one time
- having several programs running concurrently in the computer.
4. Time-sharing/Multi-tasking/Multi-using
- logical extension of multi-programming.
- Time shared OS: allows many users to share the computer simultaneously. Uses
CPU scheduling.
- Having several users running in the computer system.

5. Real-time OS
- Type of OS that is designed for a particular task through the use of sensors.
- Sensors brings data to the computer.
- Real system is defined, fixed and time constraint.

CCS Faculty
COLLEGE OF COMPUTER STUDIES 9

OPERATING SYSTEM MELJUN P.CORTES

2 FLAVORS OF REAL TIME SYSTEM:
1. Hard real-time system – guarantees that critical task is completed on
time.

2. Soft real-time system – a critical real-time task get s priority over other
task, and retains that priority until it completes.

APPLICATION OF REAL-TIME SYSTEM
1. Satellite Communication
2. Robotics
3. Home Appliances Controllers
4. Nuclear weapon system
5. Scientific Experiment System
6. Industrial Control System
7. Automatic-Fuel-Engine-Injection System
8. Imaging/X-rays

6. Distributed OS / Network OS
- Network Operating System is an OS that provide features such as file sharing (WIN
NT) across the network, that includes a communication scheme that allows different
processes on different computers to exchange messages.
- Distributed OS is a less autonomous environment.
CRITERIA TO MEASURE THE EFFECTIVENESS OF THE COMP.SYS
1. Throughput - the amount of work going on a computer system
-measure of work is the number of processes that are
completed per unit time.
2. Turnaround Time – is the sum of the periods spent waiting to get into memory
waiting in the ready queue, executing on the
CPU,and doing I/O.
- elapsed time from the job submission up to job completion.
3. Waiting Time - is the sum of the periods spent waiting in the ready queue.
4. Response Time - the amount of time it takes to start responding, but not the
the time that it takes to output that response.
5. Availability - the measures of system accessibility
6. Cost
7. Ease of Use
8. Reliability
9. Security

CCS Faculty
COLLEGE OF COMPUTER STUDIES 10

OPERATING SYSTEM MELJUN P.CORTES

QUIZ #1
1. It control and coordinates the use of hardware among the various application program for various
users.
2. It provides manipulation of data, execution, archiving and recovery.
3. It is the ability of Operating System to expand the memory of computer system.
4. A system that can be applied in any king of computer environment.
5. Allows execution of programmed one at a time.
6. It provides higher resolution and speech recognition.
7. Guarantees that the critical task is complete on time.
8. Fixed and Time constraint.
9. A type of Operating System having several programs running concurrently in the computer.
10. A terminal that composed of switches

CPU UTILIZATION
It determines how efficient and reliable a computer system. To determine the efficiency of the
CPU, it must be equal to 50%, the card reader must be equal to 25% and line printer must be equal to
25% . If the result of the computation will not meet the required percentage then, it is less efficient and
reliable.

FORMULAS:

CR Time = 1 card where:
CR speed CR Speed = # of cards
Time
LP Time = 1 line LP Speed = # of lines
LP speed Time

CPU Time = number of instruction * CPU speed
TOTAL Time = CPU Time + CR Time + LP Time

To get the efficiency used the following formula:

% Efficiency of Card Reader = (CR Time / Total Time) * 100
% Efficiency of Line Printer = (LP Time / Total Time) * 100
% Efficiency of CPU = (CPU Time / Total Time) * 100
_______________________
100 %

CCS Faculty
COLLEGE OF COMPUTER STUDIES 11

OPERATING SYSTEM MELJUN P.CORTES

Example:

Given the following characteristics:
1. % Eff. Of CR = 48.78%
TT = 0.41 sec
CPU Time = 10 ms
No. of instructions = 10,000

Required:
a. CPU speed in µs c. %Eff.of LP e. %Eff. Of TT
b. CR Time d. % Eff. Of CPU

2. % Eff. Of CPU = 19.85%
TT = .001525 hr
LP Speed = 30 lines / min

Required:
a. LP Time d. %Eff. Of LP
b. CPU Time e. %Eff.of CR
c. CR Time

SOLUTIONS TO PROBLEM GIVEN ABOVE:

1. A. CPU speed = no. of instruction
CPU Time

CPU speed = 10,000 instruction
10 ms
= 10,000 instruction
10ms * 1 x 10-3
1 ms
= 10,000 instruction
10,000 seconds
= 1 instruction/sec (convert in µs)
= 1 µs

B. CR Time = Total Time * %Eff.of CR
100
= .41 * 48.78
100
CR Time = .199 sec or .2sec

CCS Faculty
COLLEGE OF COMPUTER STUDIES 12

OPERATING SYSTEM MELJUN P.CORTES

C. %Eff. Of LP = .2sec / .41sec * 100

= 48.78%

D. %Eff. Of CPU = 100% - 48.78% + 48.78%
= 100% - 97.56%

= 2.54%

E. %Eff. Of TT = 100%

2.
A. LP speed = 30 lines * 1 min
Min 60 sec
= 1 / .5
= 2 sec

LP Time = 2 seconds

B. CPU Time = (19.85 * 5.48)
100

= 1.09 sec

%Eff. Of CPU =(1.09 sec / 5.48 sec) * 100

= 19.85%

C. CR Time = (5.48 * 43.62)
100
= 2.39 sec

= 2.4 sec

D. %Eff.of LP = (2 sec / 5.48) * 100

= 36.49%

E. %Eff. Of CPU = (1.09 sec / 5.48 ) 8 100 = 19.89%
%Eff. Of TT = 19.89% + 36.49% + %CRT
%Eff. Of CR = 100 – 19.89 – 36.39

= 43.62%

CCS Faculty
COLLEGE OF COMPUTER STUDIES 13

OPERATING SYSTEM MELJUN P.CORTES
Exercise:

Assuming that the computer system has the following characteristics:

TT = 4 sec

CR speed = 100 c/ min

If CPU takes 1200ms to assemble 1500 instructions, determine the following.

a. % Efficiency of CPU

b. % Efficiency of CR

QUIZ #2

Assuming the computer system has the following set-up.

CR CPU LP
34% Eff

TT = 2000 ms
CPU = 972µs/ instruction
If there are 900 instructions, determine the following:
a. % Eff. Of CPU c. CR Time
b. % Eff. Of LP d. LP Time

PRELIM EXAMINATION

CCS Faculty
COLLEGE OF COMPUTER STUDIES 14

OPERATING SYSTEM MELJUN P.CORTES

MIDTERM PERIOD
HARDWARE- any physical device that are used to build/run a computer for you to able to solve a
computing problems.
TYPES OF HARDWARE
1. Input
2. Output

SOFTWARE - is a general form for the various kinds of programs used to operate computers and
related devices.

TYPES OF SOFTWARE
Applications software- performs all the specialized tasks that computers are used for: payroll, video
editing, gif animator, computer aided design, airline reservations, email, chat.

General-purpose packages are the most commonly used software packages. These include word
processing, spreadsheet, desk-top-publishing, database and graphics. They are called general purpose
because they can be customized in a variety of ways to perform extremely specialized tasks. A
database can be used to create an application like a personnel or stock control system.

Systems software controls the operations of a computer and the other types of software that it runs.
Examples of systems software include the operating system, device drivers, programming languages,
compilers, assemblers and translators.

Utility software carries out all the day-to-day tasks in maintaining a computer system and its data files.
Some common utilities are screensaver, virus checker, and system tools like disk defragmenter.
Certain utility programs are usually bundled along with the operating system and are thought of as a
type of systems software. Windows comes with a variety of screen savers, and various utilities
including DriveSpace that displays the percentage of drive space used and unused.

File – a uniform logical of data/information which are mapped by a file system in your storage
devices.

File System – is one of the most visible service and feature of operating system.

File Organization Techniques
1. Sequential = records in this kind of technique may only be retrieved sequentially.
2. Direct/Relative = random access of record/file by means of key field
3. Indexed = includes a table that relates key values to storage location of the corresponding file.
4. Multiple Key = it allows access to the data/file by fields other than the primary key.

CCS Faculty
COLLEGE OF COMPUTER STUDIES 15

OPERATING SYSTEM MELJUN P.CORTES

Types of File:
Master Report
Transaction Text
Program Security
Work Audit

File Operations = a file can be accessed by a program that executes in batch mode or by a program
that executes interactively.

QUIZ #3
I. Definition of terms (10 pts)
1. Software
2. Hardware
3. File
4. File System
5. Multiple Key
II. Enumeration (10 pts)
1-4. File Organization technique
5-8. Types of Software
9-10. File Operations

MEMORY MANAGEMENT is one of the concerns of operating system since it is the main memory that
the CPU directly accesses for instructions and data.

MAIN – MEMORY is central to the operation of a modern computer system. Main Memory is a large
array of words or bytes, ranging in size from hundreds of thousands to hundreds of millions. Each word
or byte has its own address. Main Memory is a repository of quickly accessible data shared by the CPU
and I/O devices. The operating system is responsible for the following activities in connection with
memory management.
 Keep track of which parts of memory are currently being used and by whom
 Decide which processes are to be loaded into memory when memory space becomes
available
 Allocate and deallocate memory space as needed

The memory is usually divided into two partitions, one for the resident operating system, and one for
the user processes. There are two types of memory allocation techniques. First,
The Single Contiguous Allocation, Secondly, the Partitioned allocation method.
Single contiguous allocation requires no special hardware and usually associated with small
stand –alone computers with simple operating systems. The main memory is divided into three
contiguous portions: resident OS capacity, available memory used by the job and available memory
allotted space but unused.

CCS Faculty
COLLEGE OF COMPUTER STUDIES 16

OPERATING SYSTEM MELJUN P.CORTES

DIAGRAM:

OS

Used by the Job

Unused
allotted space

PARTITIONED ALLOCATION main memory partitioned into separate memory portions and such
portion of the memory holds a separate job address space.
Two Types:
1. Static Partitioned Allocation
Type of partitioned wherein memory portions are created prior to processing of the job or
process. It means that the main memory like allocate a portion of its memory upon knowing the
properties of a process.
2. Dynamic Partitioned Allocation
Memory potions are created during as to match processing of job sizes to partitioned
sizes. This procedure is a particular instance of the general dynamic storage allocation problem,
which is how to satisfy a request of size n from a list of free holes. There are many solutions to this
problem. The set of holes is searched to determine which hole is best to allocate. First fit, best-fit and
worst fit are the most common strategies used to select a free hole from the set of available holes.
 First-fit: Allocate the first hole that is big enough. Searching can start either at the
beginning of the set of holes or where the previous first-fit search ended. We can stop
searching as soon as we find a free hole that is large enough.
 Best-fit: Allocate the smallest hole that is big enough. We must search the entire list,
unless the list is kept ordered by size. This strategy produces the smallest leftover hole.
 Worst fit: Allocate the largest hole. Again, we must search the entire list, unless it is
sorted by size. This strategy produces the largest leftover hole, which may be more useful
than the smaller leftover hole from a best-fit approach.
These algorithms suffer from external fragmentation. As process are loaded and removed from
memory, the free memory space is broken into little pieces. External fragmentation exists when
enough total memory space exists to satisfy a request, but it is not contiguous; storage is fragmented
unto a large number of small holes. Another problem arises with multiple partition allocation scheme is
the internal fragmentation. Internal fragmentation, internal to a partition but it is not being used.
One solution to the problem of external fragmentation is compaction. The goal is to shuffle the
memory contents to place all free memory together in one large block. The simplest compaction
algorithm is simply to move all processes toward one end of memory; all holes move in the other
direction, producing one large hole of available memory.

CCS Faculty
COLLEGE OF COMPUTER STUDIES 17

OPERATING SYSTEM MELJUN P.CORTES

Example:
Complete the process table below:
Total Memory Capacity = 1500
Residence OS = 290

Process Capacity Memory Used Wasted Based Address
A 50 38 12 290
B 45 30 15 340
C 65 45 20 385
D 200 170 30 450
E 220 160 60 650

Answer:
0
OS
290
A
328 Wasted (12 KB)

340
B
370
Wasted (15 KB)
385
C
430
Wasted (20 KB)
450
D
620
Wasted (30 KB)
650
E
810
Wasted (60 KB)

870
Free Space
(630 KB)
1500
The wasted or the unused space of the job is known as internal fragments. A job used
and the internal fragment composed the partition of the memory. The job scheduler cannot compress
internal fragments because it is within the internal portion of the process.

CCS Faculty
COLLEGE OF COMPUTER STUDIES 18

OPERATING SYSTEM MELJUN P.CORTES

Example: Dynamic Partition
Given:
OS = 400 KB
Total Capacity = 2048 KB

Initial State of the Main Memory

0
OS
400
P1 (500 KB)
900
Free Space (100 KB)

1000
P2 (600 KB)
1600
Free Space (448 KB)

2048
Task to Perform:
A. Allocate P3
B. Deallocate P2
C. Allocate P4 (410 KB)

Answer/ Solution:
Task A. 0
OS
400
P1 (500 KB)

900
Free Space (100 KB)

1000
P2 (600 KB)

1600
P3 (400 KB)

2000 Free Space (48 KB)

2048

CCS Faculty
COLLEGE OF COMPUTER STUDIES 19

OPERATING SYSTEM MELJUN P.CORTES
Task B.
0
OS

400
P1 (500 KB)
900
Free Space (700 KB)

1600
P3 (400 KB)
2000
Free Space (48 KB)

2048

Task C.
0
OS
400
P1 (500 KB)
900
P4 (410 KB)

1310
Free Space (290 KB)

1600
P3 (400 KB)

2000 Free Space (48 KB)

2048

The sets of instruction or tasks to be done are the instructions to be performed by the
operating system in managing the memory what job is to be allocated or deallocated. Deallocated jobs
are that are already finished or terminated by the user or those jobs that are deleted in the memory.
In dynamic Partition allocation, the main memory suffers external fragments. External
Fragments occur when the memory is not contiguous such that even if the memory space available is
lesser than the job to be allocated, it may not be possible to load such process.
One solution of external fragmentation is known as compaction. The goal is to shuffle the
memory contents to place all free memory together in one large block. Compaction method,
Compressing all jobs upward while all the spaces will be combined at the lower part of the memory.

CCS Faculty
COLLEGE OF COMPUTER STUDIES 20

OPERATING SYSTEM MELJUN P.CORTES

COMPACTION
0
OS

400
P1 (500 KB)

900
P4 (410 KB)
1310
P3 (400 KB)
1710
Free Space (338 KB)

2048

SWAPPING
A process needs to be in memory to be executed. A process, however, can be swapped
temporarily out pf memory to a backing store, and then brought back into memory for continued
execution. Ideally, the memory manager can swap processes fast enough that there are always
processes in memory, ready to execute, when the CPU scheduler wants to reschedule the CPU. The
quantum must also be sufficiently large that reasonable amounts of computing are done between swaps
A variant of this swapping policy used for priority based scheduling algorithms. If a higher
priority process arrives and wants service, the memory manager can swap out the lower-priority process
so that it can load and execute the higher priority process. When the higher priority process finishes, the
lower priority process can be swapped back in and continued. This variant of swapping is sometimes
called roll out, roll in.
Swapping requires a backing store. The backing store is commonly a fast disk. It must be
large enough to accommodate copies of all memory images for all users, and must provide direct
access to these memory images. The system maintains a ready queue consisting of all processes
whose memory images are on the backing store or in memory and are ready to run.

CCS Faculty
COLLEGE OF COMPUTER STUDIES 21

OPERATING SYSTEM MELJUN P.CORTES
Illustration:

MAIN MEMORY BACKING STORE

OS MEMORY P1
CORE
IMAGES
USER
PROCESSES
P2

Performance:

Time for each interaction = swap-in time + swap-out time + CPU time

= 2 * swap time + CPU time

Efficiency:

%Efficiency of swapping = (CPU time / time for each interaction) * 100

PAGING
It is a scheme that possibly solves the external fragmentation that permits the logical address
space of a process to be noncontiguous.
BASIC METHOD
Physical memory is broken into fixed-sized blocks called frames. Logical memory is also broken
into blocks of the same size called pages. When a process is to be executed, its pages are loaded into
any available memory frames from the backing store.
The backing store is divided into fixed-sized blocks that are of the same size as the memory
frames.
Every address generated by the CPU is divided into two parts: a page number (p) and a page
offset (d). The page number is used as an index into a page table. The page table contains the base
address of each page in physical memory. The base address is combined with the page offset to define
the physical address that is sent to the memory unit. The hardware registers define the page size (like
the frame size).
Illustration:

CPU p d f d
Physical
Memory
Physical Address
f

CCS Faculty
COLLEGE OF COMPUTER STUDIES 22

OPERATING SYSTEM MELJUN P.CORTES
STRUCTURE OF THE PAGE TABLE

Each Operating system has its own methods for storing page tables. The hardware
implementation of the page table can be done in a number of different ways. The simplest case, the
page table is implemented as a set of dedicated registers. These registers should be built with very high
speed logic to make the paging address translation efficient.
The page table is kept in main memory and a page table base register (PTBR) points to the
page table. The PTBR provides the frame number (1) which is combined with the page offset to
produce the actual address.
In the user point of view of memory, physical address can be mapped using the formula.
ADDRESS = (frame number * size of the page) + offset number

FRAME NUMBER = Address – offset number
Size of page
Example:
TOTAL MEMORY CAPACITY = 20 KB

Logical 0
P5 1
Memory Offset P6 2
P7 3
P1 0
P8 4
P2 1
2 P0 5
P3 6
3
P4 7
0
P5 1 8
0 4 P9
P6 2 P1 9
1 0
P7 3 P10 10
2 2
P8 0 P11 11
P12 12
P9
1 13
P10 14
P11 2 P2
3 15
P12 16
P1 17
P2 18
P3 19
P4 20

CCS Faculty
COLLEGE OF COMPUTER STUDIES 23

OPERATING SYSTEM MELJUN P.CORTES

Exercises:

1. Total capacity of memory = 15 kb
Page number = 0, 1, 2
Frame number = 3, 0, 0
Content of page 0 = p1, p2, p3, p4
Content of page 1 = p5, p6, p7, p8
Content of page 2 = p9, p10, p11, p12
Required:
a. address
b. page table

2. Total capacity of memory = 20 kb
Page number = 0, 1, 2
Frame number = 3,2,1
Content of page 0 = p1,p2,p3,p4,p5
Content of page 1 = p6,p7,p8,p9,p10
Content of page 2 = p11,p12,p13,p14,p15
Required:
a. address
b. page table
c.
Seatwork:
0
P0
1 B1
P1
Page # Frame#
P3 4 E1 B1
P4 5 E1
A1
P2 2 A1 R1
P5 3

P7 1 R1
P8 2

PAGE REPLACEMENT
In generating the frame number, the PTBR uses an algorithm. Frame numbers came from
generated reference string.
Page replacement is needed to determine the number page fault, page fault rate and default
pages. Page faults are frame numbers that are currently used while the default pages are pages
that occur when there is an existing page used as a frame number.

CCS Faculty
COLLEGE OF COMPUTER STUDIES 24

OPERATING SYSTEM MELJUN P.CORTES

Algorithm:
1. FCFS/FIFO – First come first serve/ first in first out basis
2. Optimal – a reference string that will needed for longer time will be replaced
3. LRU or Least Recently Used – a reference string will be replaced that is recently
used by the frame.
Given the reference string:
2 3 1 5 2 3 2

FCFS

2 3 1 5 2 3 2
Page fault rate=6/7*100= 85.71%
2 2 2 5 5 5 Page Fault = 6
3 3 3 2 2 Default = 1
1 1 1 3
OPTIMAL
Page fault rate=(4/7)*100=57.14%
2 3 1 5 2 3 2 Page Fault = 4
Default = 3
2 2 2 2
3 3 3
1 5
LRU
Page fault rate=(4/7)*100=57.14%
2 3 1 5 2 3 2 Page Fault = 4
Default = 3
2 2 2 2
3 3 3
1 5

QUIZ #4
Using FCFS, OPTIMAL and LRU algorithm determine the job sequence of the given reference
string: 2 3 4 5 6 7 8 9 1 5 7 3 7

MIDTERM EXAMINATION

CCS Faculty
COLLEGE OF COMPUTER STUDIES 25

OPERATING SYSTEM MELJUN P.CORTES

FINAL PERIOD

PROCCES MANAGEMENT allows time sharing of CPU in allocating different processes to the
processor.

PROCESS The designer of Multics system was the first who introduced the word or term “process” in
the mid 60’s. Since that time, process used somewhat interchangeably with task or job, has been given
a lot of definitions. Some of these are:
 A program in execution.
 An asynchronous activity
 The “animated spirit” of a procedure in execution.
 The “locus of control” of a procedure in execution.
 That which is manifested by the existence of a “process control block” in the operating
system.
 That entity to which processors are assigned.
 The “dispatch able” unit.
A process is more than a program code (sometimes known as text section). It also includes the current
activity, as represented by the value of the program counter and the contents of the processor’s
registers. A process generally includes the process stack, containing temporary data such as
subroutines, parameters, return address, and temporary variables and data section containing global
variables.
A resource of Process includes CPU Time, memory, files, and I/O devices to complete the task.
These resources are either given to the process when it is created, or allocated to it while it is running.

PCB is a data structure, which contains important information about certain process. It is also called a
task control block. The information or content of PCB are process state, program counter, CPU
Registers, CPU Scheduling information, Memory-management Information, Accounting Information and
I/O information.

ILLUSTRATION of PCB
Pointer Process
State

Process number

Program Counter

Registers

Memory limits

List of Open Files

:
:

CCS Faculty
COLLEGE OF COMPUTER STUDIES 26

OPERATING SYSTEM MELJUN P.CORTES
 Process State. The state may be new, ready, running, and waiting, halted and so on.
 Program Counter. The counter indicates the address of the next instruction to be
executed for this process.
 CPU Registers. The registers vary in number and type, depending on the computer
architecture. They include accumulators, index registers, stack pointers, and general-
purpose registers, plus any condition-code information. Along with the program counter,
this state information must be saved when an interrupt occurs, to allow the process to be
continued correctly afterward.
 CPU Scheduling Information. This information includes a process priority, pointers to
scheduling queues, and any other scheduling parameters.
 Memory-Management information. This information may include such information as the
value of the base and limit registers, the page tables or the segment tables depending on
the memory system used by the operating system.
 Accounting information. This information includes the amount of CPU and real time
used, time limits, account numbers, job or process numbers and so on.
 I/O status information. The information includes the list of I/O devices (such as tape
drives) allocated to this process, a list of open files, and so on.

PROCESS TRANSITION DIAGRAM

Run

Submit Hold Ready
Complete

Wait

A process goes through a series of discrete process states. Various events can cause a process
to change states.
Submit state, a state where a process is being submitted to the system, and the system will
respond to the request.
Eventually, when a job is submitted to the system or CPU, a corresponding process is created
and normally inserted at the back of the ready list. The assignment of the CPU to the first process on
the ready list is called dispatching, and is performed by a system hardware called “dispatcher”.
Hold state, a state where a process is being transformed into a machine readable form.
Ready state a state where a process submitted is ready for execution, but there are more
processes running than the processor available.
To prevent any process from monopolizing the system, the operating system sets a hardware
interrupting clock or interval timer (idle) to allow particular user to run for a specific time interval called
“quantum time”. The interrupting clock generates an interrupt, causing the operating system to regain
control. The operating system then makes the previously running process ready, and makes the first
process on the ready list running.

CCS Faculty
COLLEGE OF COMPUTER STUDIES 27

OPERATING SYSTEM MELJUN P.CORTES

A running state a currently procedure of processing takes place were from the ready list
provided that the english like language used by a specific users the operating system handles the
operation to transformed the english like language into a machine readable form. After a thorough
procedure of transformation of language and when it is successfully done it is immediately scheduled to
the processor for processing.
A process is said to be running if it is currently has the CPU. A process is said to be ready if it is
used a CPU if one were available. A process is said to be blocked if it is waiting for some event to
happen before it can proceed.
A wait state was some of the processes are waiting for some event. Once, the CPU reset the
resource it means that it is ready to accept another process. Timer or interrupt clock queue the waiting
jobs to dispatcher or ready state to prepare for next execution.
Complete State the process is already finished and the resources used are reclaimed for the
next process in the queue.
Before a process will be submitted (next) to the system, TRAFFIC CONTROLLER will check the
Available resources. It will keep track the status of all hardware and software resources.
There are two types of scheduler in operating system that will manage the flow of the system.

QUIZ #5

I. Enumeration (15 pts)
1-6. Discrete Process States
7-15. Information inside the Process Control Block
II. Essay (15 pts)
1. Draw and discuss the Process Transition Diagram (10 pts)
2. Define Process. (3 pts)
3. Define Process Control Block (2 pts)

SCHEDULER. A process migrates between the various scheduling queues throughout its lifetime. The
operating system must select, for scheduling purposes, processes from these queues in some fashion.
The selection process is carried out by the appropriate scheduler.
1. JOB SCHEDULER also known as Long Term Scheduler. It will select jobs being submitted to the
system and will put all the jobs selected in the physical memory of the system.
There are several criteria for job selection:
a. capacity of the job
b. priority of process
c. expected runtime
d. amount of input and output
e. special resources required

CCS Faculty
COLLEGE OF COMPUTER STUDIES 28

OPERATING SYSTEM MELJUN P.CORTES

2. CPU SCHEDULER or also known as Short Term Scheduler. This scheduler will select process in
the memory and put it on time of the queue.
There are types of queue.
a. Ready Queue will hold processes that are ready to be dispatched or ready for execution.
The process that resides in main memory and are ready and waiting to execute are kept
on a list are called ready queue.
b. Device Queue will hold processes that are listed for a particular input output deices.

In CPU scheduler, there are different algorithms used for handling processes, which are
categorized into two:
2. Non Deterministic Scheduling Algorithms
3. Deterministic Scheduling Algorithms

Deterministic Scheduling Algorithms is an algorithm wherein all characteristics of a process
are known in advance or before execution. These characteristics are:
a. execution time (ti)
b. priority time (wi)
c. deadline time (di)
d. finishing time

There are three algorithms under this class.
1. Minimum Mean Response Time (MMRT) all processes are arranged according to increasing
execution time. Execution time is denoted as ti. In case of the same execution time, first come
first serve is supplied.
2. Minimum Weighted Response Time (MWRT) all processes are arranged according to
increasing execution time divided by the priority. Priority is denoted as wi.
3. Maximum/Minimum Lateness (MML) all processes are arranged according to increasing
deadlines. Deadline time is denoted as di. In case of the same deadlines, the process having the
lower or smallest execution time will be loaded first.

Example: Considering the following execution time, deadline and priority time. Schedule the given
process and arranged them according to MMRT, MWRT and MML algorithm.

PROCESS Execution Time Priority Time Deadline Time
P1 10 ms 2 12
P2 5ms 1 6
P3 15 ms 3 16

CCS Faculty
COLLEGE OF COMPUTER STUDIES 29

OPERATING SYSTEM MELJUN P.CORTES

SOLUTION:

MMRT ti

CPU P2 P1 P3

5 ms 10 ms 15 ms
MWRT ti / wi

P1 10 / 2 = 5
P2 5 / 5 = 1
P3 15 / 3 = 5

CPU P2 P1 P3

1ms 5 ms 5 ms
MML di

CPU P2 P1 P3

6 ms 12 ms 16 ms

Exercise:

Schedule the following jobs using MMRT, MWRT and MML where:
A = 5, B= 3 C = 2.
PROCESS Execution Priority Time Deadline Time
Time
J A*A C*C A*B–C
U A–B*2 B–C C*2
L B*A/3 A*C A*A
Y A*C B*3 A-B

Seatwork:

A. Enumerate the 6 discrete process states in process management and explain each.

B. Discuss the Process Control Block.

C. Schedule the following process using the 3 Deterministic Scheduling

Algorithm: A=6, B=A/2, C=A*B/2

CCS Faculty
COLLEGE OF COMPUTER STUDIES 30

OPERATING SYSTEM MELJUN P.CORTES

Non– Deterministic Scheduling Algorithm where in the characteristics of a process are not known in
advance. This algorithm can be categorized into two:
1. Single Queuing all process arrives at the same time with their corresponding burst time.
2. Multiple Queuing each process has its own arrival time in the processor.
Burst time is the time where the processor detects the existence of a particular process before
execution.
There are four scheduling algorithms in non-deterministic scheduling algorithms.
1. First Come First Serve Scheduling Algorithm (FCFS) the first process that arrives first will be
the process to be loaded in the processor. FCFS is nonpreemptive. Once the CPU has been
allocated to a process, that process keeps the CPU until it releases the CPU, either by
terminating or by requesting I/O. The problem of this algorithm encountered is all processes
suffer convoy effect. This effect results in lower CPU and device utilization than might be
possible if the shorter processes were allowed to go first.
2. Shortest Job First Scheduling Algorithm (SJF) the process with a smallest the processes
burst time will be loaded first. This algorithm associates with each process the length of the
latter’s next CPU burst. Using this algorithm, the processes are suffering starvation effect.
3. Priority Scheduling Algorithm. A process with a higher priority will be loaded into the
processor. Priority scheduling can be either preemptive or non preemptive. When a process
arrives at the ready queue, its priority is compared with the priority of the currently running
process. A preemptive priority scheduling algorithm will preempt the CPU if the priority of the
newly arrived process is higher than the priority of the currently running process. A
nonpreemptive priority scheduling algorithm will simply put the new process at the head of the
ready queue. A major problem with priority scheduling algorithm is indefinite blocking or
starvation. A solution to the problem of indefinite blockage of low priority processes is aging.
Aging is a technique of gradually increasing the priority of processes that wait in the system
for a long time. To solve the convoy effect and starvation effect, Round Robin is
conceptualized.
4. Round Robin Scheduling Algorithm i8s designed especially for time sharing systems. A
quantum time is given. A quantum time is generally from 10 to 100 milliseconds. The ready
queue is treated a s a circular queue. The CU scheduler goes around the ready queue,
allocating the CPU to each process for a time interval of up to 1 time quamtum. It is a time
defined for the processes that will be executed in order to prevent monopoly of the processor:

To simulate how these processes work, Gantt chart is used to determine the average waiting
time and the average turn around time.
Waiting time is the time where a particular process is waiting in the ready queue while the
Turn-around time is the elapse time form job submission up to job completion.

CCS Faculty
COLLEGE OF COMPUTER STUDIES 31

OPERATING SYSTEM MELJUN P.CORTES

FORMULA:
1. To compute the average waiting time:

Long Method:
Actual Waiting Time = Waiting Time – Arrival Time
Average Waiting Time = ∑Actual Waiting Time
Total Number of Jobs

Short Method:
Actual Waiting Time = Waiting Time – Arrival Time

Average Waiting Time = ∑Actual Waiting Time - Arrival Time
Total number of Jobs

2. To compute the average turn-around time:

Long Method:
Actual Turn - Around Time = Turn - Around Time – Arrival Time
Average Turn – Around Time = ∑Actual Turn - Around Time
Total Number of Jobs

Short Method:
Actual Turn - Around Time = Waiting Time – Arrival Time

Average Turn - Around Time = ∑Actual Turn - Around Time - Arrival Time
Total number of Jobs

3. For the Round Robin Scheduling Algorithm:

To compute the Average Waiting Time

Actual WT = Present WT + (Next WT – Previous Turn around Time) – Arrival Time
WT = ∑Actual Waiting Time
Total number of Jobs

To compute the Average Turn – Around Time
Actual Turn - around Time = Last Turn Around Time – Arrival Time

Average Turn - Around Time = ∑Actual Turn - Around Time
Total number of Jobs

CCS Faculty
COLLEGE OF COMPUTER STUDIES 32

OPERATING SYSTEM MELJUN P.CORTES

Example: SINGLE QUEUING
Simulate the Gantt chart and compute for the average waiting time and turn-around time using
FCFS, SJF, PRIORITY and ROUND-ROBIN SchedulIng AlgoBithm.

PROCESS BT AT WI QT
F 10 5ms 2 5ms
L 15 2
A 20 1
W 8 3
S 10 4

SOLUTION: SINGLE QUEUING

FCFS

F 10 L15 A20 W8 S10
CPU
5 15 30 50 58 68

LONG METHOD:

Do compute the Average Waiting Time

WT = (5 -5) + (15 - 5) + 30 – 5) + (50 – 5) + (58 -5)
5

AWT = 0 + 10 + 25 + 45 + 53
5

AWT = 133
5
AWT = 26.6 ms

To compute the Average Turn – ArouNd time

TAT= (15 – 5) + (30 – 5) + (50 - 5) + (58 – ) + (68 – 5)
5

ATAT = 10 + 25 + 45 + 53 + 63
5

ATAT = 196
5
ATAT = 39.2 ms

CCS Faculty
COLLEGE OF COMPUTER STUDIES 33

OPERATING SYSTEM MELJUN P.CORTES

SHORT METHOD:

AWT = 5
15 + 30 + 50 + 58 - 5 = 26.6 ms
5

ATAT = 15 + 0 + 50
58 + 68 - 5 = 39.2 ms
5
SJF
W8 F10 S10 L 15 A20
CPU

AWT = 5 + 13 + 23 + 3 + 48 - 5 = 19.4 ms
5

ATAT = 13 + 23 + 33 + 48 + 8 -5
32 ms
5

PRIORITY

A 20 F10 L15 W8 S10
CPU

AWT = 5 + 25 + 35 + 50 + 8 -5
29.6 ms
5

ATAT = 25 + 35 + 50 + 58 + 68 - 5 = 42. ms
5

ROUND- ROBIN

5 5 5 5 5 5 5 5 3 5 5 5 5
CPU F L A W S F L A W S L A A

5 10 15 20 25 30 35 40 45 48 53 58 63 68

CCS Faculty
COLLEGE OF COMPUTER STUDIES 34

OPERATING SYSTEM MELJUN P.CORTES

F = 10 – 5 = 5 – 5 = 0
L = 15 – 5 = 10 – 5 = 5 – 5 = 0
A = 20 – 5 = 15 – 5 = 10 – 5 = 5 – 5 = 0
W=8–5=3–3=0
S = 10 – 5 = 5 – 5 = 0

WT: F = 5 + 30 – 10 – 5 = 20
L = 10 + 35 – 15 + 53 – 40 – 5 = 38
A = 15 + 40 – 20 + 58 – 45 + 63 – 63 – 5 = 43
W = 20 + 45 – 25 – 5 = 35
S = 25 + 48 – 30 – 5 = 38

AWT = 20 + 38 + 43 + 35 + 38 = 34.8ms
5

TAT: F = 35 – 5 = 30
L = 58 – 5 = 53
A = 68 – 5 = 63
W = 48 – 5 = 43
S = 53 – 5 = 48

ATAT = 30 + 53 + 63 + 43 + 48 = 47.4ms
5

EXAMPLE: MULTIPLE QUEUING

Process Burst time Arrival time Priority Quantum
Time
P1 10 4ms 4 6ms
P2 5 7ms 3
P3 15 10ms 1
P4 10 2ms 2

FCFS: arrangement based on smaller Arrival time

CPU J4 10 J1 10 J2 5 J3 15

2 12 22 27 42

CCS Faculty
COLLEGE OF COMPUTER STUDIES 35

OPERATING SYSTEM MELJUN P.CORTES

WT
J1 = 12 – 4 = 8
J2 = 22 – 7 = 15
J3 = 27 – 10 = 17
J4 = 2 – 2 = 0

AWT = 8 + 15 + 17 + 0 = 10ms
4

TAT
J1 = 22 – 4 = 18
J2 = 27 – 7 = 20
J3 = 42 – 10 = 32
J4 = 12 – 2 = 10

ATAT = 18 + 20 + 32 + 10 = 20ms
4

SJF

CPU 2 J4 10 4 J1 10 7 J2 5 12 J4 8 20 J1 7 27 J3 15 42

WT
J1 = 4 + 20 – 7 – 4 = 13
J2 = 7 – 7 = 0
J3 = 27 – 10 = 17
J4 = 2 + 12 – 4 – 2 = 8

AWT = 13 + 0 + 17 + 8 = 9.5ms
4
TAT
J1 = 27 – 4 = 23
J2 = 12 – 7 = 5
J3 = 42 – 10 = 32
J4 = 4 – 2 = 2

ATAT = 23 + 5 + 32 + 2 = 15.5ms
4

PRIORITY
2
CPU J4 10 J3 15 J4 2 J2 5 J1 10

2 10 25 27 32 42

CCS Faculty
COLLEGE OF COMPUTER STUDIES 36

OPERATING SYSTEM MELJUN P.CORTES

WT
J1 = 32 – 4 = 28
J2 = 27 – 7 = 20
J3 = 10 – 10 = 0
J4 = 2 + 25 – 10 – 2 = 15

AWT = 28 + 20 + 0 + 15 = 15.75ms
4

TAT
J1 = 42 – 4 = 38
J2 = 32 – 7 = 25
J3 = 25 – 10 =15
J4 = 27 – 2 = 25

ATAT = 38 + 25 + 15 + 25 = 25.75ms
4

ROUND - ROBIN
6 6 5 6 4 4 6 3

CPU J4 J1 J2 J3 J4 J1 J3 J3

2 8 14 19 25 29 33 39 42

J1 = 10 – 6 = 4 – 4 = 0
J2 = 5 – 5 = 0
J3 = 15 – 6 = 9 – 6 = 3
J4 = 10 – 6 = 4 – 4 = 0
WT
J1 = 8 + 29 – 14 – 4 = 19
J2 = 14 – 7 = 7
J3 = 19 + 33 – 25 + 39 – 39 – 10 = 17
J4 = 2 + 25 – 8 – 2 =17

AWT = 19 + 7 + 17 + 17 = 15ms
4
TAT
J1 = 33 – 4 = 29
J2 = 19 – 7 =12
J3 = 42 – 10 = 32
J4 = 29 – 2 = 27

ATAT = 29 + 12 + 32 + 27 = 25ms

CCS Faculty
COLLEGE OF COMPUTER STUDIES 37

OPERATING SYSTEM MELJUN P.CORTES

QUIZ #6:

Schedule the following jobs using FCFS, SJF, Priority and Round-Robin

Process Bt AT Wi QT
P1 20 6ms 3 7ms
P2 12 4ms 1
P3 10 10ms 2
P4 5 20ms 4
P5 18 2ms 1

FINAL EXAMINATION

References:
1. Silberchatz, Abraham, et. Al. Operating Systems Concepts, 6th edition, Wiley
Textbooks, 2002
2. Bic, Lubomir F., Shaw, Alan C. Operating System Principles, 1st edition, Prentice Hall,
2002
3. Stalling, William. Operating Systems: Internals and Design Principles, 4th Edition,
Prentice Hall, 4th edition, Prentice Hall, 2000
4. Tanenbaum, Andrew, Modern Operating Systems, 2nd edition, Prentice Hall, 2001
5. Choudhury, P.O. Operating System Principles and Design, 1st edition. CRC Press,
2002

CCS Faculty
COLLEGE OF COMPUTER STUDIES 38

OPERATING SYSTEM MELJUN P.CORTES

CCS Faculty