Module 3 Operating Systems
Module 3 Operating Systems
OPERATING SYSTEMS
OPERATING SYSTEMS AND COMPUTER NETWORKS
Process Management 10
Process states 10
Process Control Block 10
What is a Deadlock? 11
How to avoid deadlocks 11
Mutual Exclusion 11
Hold and Wait 12
No Preemption 12
Circular Wait 12
Handling deadlock 12
Preemption 12
Rollback 12
Kill one or more processes 12
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 1
Process Scheduling & Scheduling Algorithms 13
Pre-emptive 13
Non-pre-emptive 13
Throughput 13
Turnaround Time 13
Waiting Time 14
Load Average 14
Response Time 14
Scheduling Algorithms 14
Aim of scheduling 14
Shortest Job First(SJF) Scheduling 15
Problem with Non-pre-emptive SJF 15
Pre-emptive Shortest Job First 15
Round Robin Scheduling 15
First Come First Serve Scheduling 16
Problems with FCFS Scheduling 16
Priority Scheduling 16
Device Management 23
Device drivers 23
Devices, Interrupt handling and the PCB 23
Input/output control & peripheral control 23
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 2
Polling 24
Buffer 24
Spooling 24
File Management 25
File 25
Directories/Folders 25
Security of files 25
User IDs 25
Passwords 25
Lockwords, 26
Access control list, 26
File Encryption 26
File compression 26
Activity logs 26
User Interface 27
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 3
The Operating System
A computer system has many resources (hardware and software), which may be required to
complete a task. The commonly required resources are input/output devices, memory, file
storage space, CPU etc. The operating system acts as a manager of the above resources and
allocates them to specific programs and users, whenever necessary to perform a particular task.
Therefore operating system is the resource manager i.e. it can manage the resource of a
computer system internally. The resources are processor, memory, files, and I/O devices. In
simple terms, an operating system is the interface between the user and the machine.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 4
● User interface which allows you to communicate with your computer.
● Program transition capabilities to reduce the overhead of starting a new job was
added.
● Job control languages that allowed users to specify the job definition and resource
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 5
Operating Systems - In 1960s
● 1961: The dawn of minicomputers
● Dynamic address translation hardware and Virtual machines came into picture.
● 1972: IBM comes out with VM: the Virtual Machine Operating System
● 1973: Ethernet
● 1976: Apple II
● 1991 GNU/Linux
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 6
● 1992 The first Windows virus comes out
● 1993 Windows NT
● 2007: iOS
● 2008: Android OS
And as the research and development work continues, we are seeing new operating systems
being developed and existing ones getting improved and modified to enhance the overall user
experience, making operating systems fast and efficient like never before.
Also, with the onset of new devices like wearables, which includes, Smart Watches, Smart
Glasses, VR gears etc, the demand for unconventional operating systems is also rising.
3. Multiprocessor System
4. Desktop System
6. Clustered System
8. Handheld System
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 7
Simple Batch Systems
● In this type of system, there is no direct interaction between user and the
computer.
● The user has to submit a job (written on cards or tape) to a computer operator.
● Then a special program, the monitor, manages the execution of each program in the
batch.
● The monitor is always in the main memory and available for execution.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 8
sure that the requirements of the various users are balanced, and that each of
the programs they are using has sufficient and separate resources so that a
problem with one user doesn't affect the entire community of users. Unix,
VMS and mainframe operating systems, such as MVS, are examples of
multi-user operating systems.
Bootstrap process
A bootstrap is the program that initializes the operating system (OS) during startup.
Bootstrapping is the process of loading a set of instructions when a computer is first turned on
or booted. During the startup process, diagnostic tests are performed, such as the power-on
self-test (POST), that set or check configurations for devices and implement routine testing for
the connection of peripherals, hardware and external memory devices. The bootloader or
bootstrap program is then loaded to initialize the OS.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 9
Process Management
A process is a program in execution. Process is not as same as program code but a lot more
than it. A process is an 'active' entity as opposed to program which is considered to be a
'passive' entity. Attributes held by process include hardware state, memory, CPU etc.
Process states
● NEW- The process is being created.
● BLOCKED- The process is waiting for some event to occur(such as an I/O completion
or reception of a signal).
● CPU registers and Program Counter. Program Counter holds the address of the
scheduling queues.
● Accounting information: The User and kernel CPU time consumed, account
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 10
● I/O Status information: Devices allocated, open file tables, etc.
What is a Deadlock?
Deadlocks are a set of blocked processes each holding a resource and waiting to acquire a
resource held by another process.
Mutual Exclusion
Resources shared such as read-only files do not lead to deadlocks but resources, such as
printers and tape drives, requires exclusive access by a single process.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 11
Hold and Wait
In this condition processes must be prevented from holding one or more resources while
simultaneously waiting for one or more others.
No Preemption
Preemption of process resource allocations can avoid the condition of deadlocks, where ever
possible.
Circular Wait
Circular wait can be avoided if we number all resources, and require that processes request
resources only in strictly increasing(or decreasing) order.
Handling deadlock
The above points focus on preventing deadlocks. But what to do once a deadlock has occured.
Following three strategies can be used to remove deadlock after its occurrence.
Preemption
We can take a resource from one process and give it to other. This will resolve the deadlock
situation, but sometimes it does causes problems.
Rollback
In situations where deadlock is a real possibility, the system can periodically make a record of
the state of each process and when deadlock occurs, roll everything back to the last checkpoint,
and restart, but allocating resources differently so that deadlock does not occur.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 12
Process Scheduling & Scheduling Algorithms
The act of determining which process is in the ready state, and should be moved to the
running state is known as Process Scheduling.
The prime aim of the process scheduling system is to keep the CPU busy all the time and to
deliver minimum response time for all programs. For achieving this, the scheduler must apply
appropriate rules for swapping processes IN and OUT of CPU.
● Non Pre-emptive Scheduling: When the currently executing process gives up the
CPU voluntarily.
Pre-emptive
● Shortest-Job-First (SJF),
● round robin
Non-pre-emptive
● First come first serve (FCFS),
● Shortest-Job- First (SJF)
Throughput
It is the total number of processes completed per unit time or rather say total amount of work
done in a unit of time. This may range from 10/second to 1/hour depending on the specific
processes.
Turnaround Time
It is the amount of time taken to execute a particular process, i.e. The interval from time of
submission of the process to the time of completion of the process(Wall clock time).
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 13
Waiting Time
The sum of the periods spent waiting in the ready queue amount of time a process has been
waiting in the ready queue to acquire get control on the CPU.
Load Average
It is the average number of processes residing in the ready queue waiting for their turn to get
into the CPU.
Response Time
Amount of time it takes from when a request was submitted until the first response is produced.
Remember, it is the time till the first response and not the completion of process execution(final
response).
In general CPU utilization and Throughput are maximized and other factors are reduced for
proper optimization.
Scheduling Algorithms
The method used to determine which of several processes, each of which can safely have a
resource allocated to it, will actually be granted use of the resource. The algorithm may take into
account the priority of the user associated with the process, the requirement to maintain high
utilization of system resources, and deadlines for the job.
Aim of scheduling
● Max CPU utilization [Keep CPU as busy as possible]
● Fair allocation of CPU.
● Max throughput [Number of processes that complete their execution per time unit]
● Min turnaround time [Time taken by a process to finish execution]
● Min waiting time [Time a process waits in ready queue]
● Min response time [Time when a process produces first response]
● No task must be starved of resources - all tasks must get their chance at CPU time;
● If using priorities, a low-priority task must not hold up a high-priority task;
● the scheduler must scale well with a growing number of tasks, ideally being O(1). This
has been done, for example, in the Linux kernel.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 14
Shortest Job First(SJF) Scheduling
Shortest Job First scheduling works on the process with the shortest burst time or duration first.
● This is the best approach to minimize waiting time.
● This is used in Batch Systems.
● It is of two types:
1. Non-pre-emptive
2. Pre-emptive
● To successfully implement it, the burst time/duration time of the processes should be
known to the processor in advance, which is practically not feasible all the time.
● This scheduling algorithm is optimal if all the jobs/processes are available at the same
time. (either Arrival time is 0 for all, or Arrival time is same for all)
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 15
First Come First Serve Scheduling
In the "First come first serve" scheduling algorithm, as the name suggests, the process which
arrives first, gets executed first, or we can say that the process which requests the CPU first,
gets the CPU allocated first.
● First Come First Serve, is just like FIFO(First in First out) Queue data structure, where
the data element which is added to the queue first, is the one who leaves the queue first.
● This is used in Batch Systems.
● It's easy to understand and implement programmatically, using a Queue data structure,
where a new process enters through the tail of the queue, and the scheduler selects
process from the head of the queue.
● A perfect real life example of FCFS scheduling is buying tickets at ticket counter.
Priority Scheduling
● Priority is assigned for each process.
● Process with highest priority is executed first and so on.
● Processes with same priority are executed in FCFS manner.
● Priority can be decided based on memory requirements, time requirements or any other
resource requirement.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 16
Comparison of Scheduling Algorithms
By now, you must have understood how CPU can apply different scheduling algorithms to
schedule processes. Now, let us examine the advantages and disadvantages of each
scheduling algorithms that we have studied so far.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 17
Round Robin (RR)
Here are some Advantages: of using the Round Robin Scheduling:
● Each process is served by the CPU for a fixed time quantum, so all processes are given
the same priority.
● Starvation doesn't occur because for each round robin cycle, every process is given a
fixed time to execute. No process is left behind.
and here comes the Disadvantages:
● The throughput in RR largely depends on the choice of the length of the time quantum. If
time quantum is longer than needed, it tends to exhibit the same behavior as FCFS.
● If time quantum is shorter than needed, the number of times that CPU switches from one
process to another process, increases. This leads to decrease in CPU efficiency.
Situation 1:
The incoming processes are short and there is no need for the processes to execute in a
specific order.
In this case, FCFS works best when compared to SJF and RR because the processes are short
which means that no process will wait for a longer time. When each process is executed one by
one, every process will be executed eventually.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 18
Situation 2:
The processes are a mix of long and short processes and the task will only be completed if all
the processes are executed successfully in a given time.
Round Robin scheduling works efficiently here because it does not cause starvation and also
gives equal time quantum for each process.
Situation 3:
The processes are a mix of user based and kernel based processes.
Priority based scheduling works efficiently in this case because generally kernel based
processes have higher priority when compared to user based processes.
For example, the scheduler itself is a kernel based process, it should run first so that it can
schedule other processes.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 19
Interrupts
In early years of computing, the processor has to wait for the signal for processing. So the
processor has to check if each and every hardware and software program in the system has
any signal to process. This method of checking the signal in the system for processing is called
Polling Method. With this method, the problem is that the processor has to waste a number of
clock cycles just for checking the signal, by doing this processor will become busy
unnecessarily. If any signal came for the process, the processor will take some time to process
the signal due to the polling process in action. So the system performance also will degrade and
response time of the system will also increase (it will take longer to respond).
To overcome this problem, engineers introduced a new mechanism. In this mechanism the
processor will not check for any signal from hardware or software but instead hardware/software
will notify (send a signal to) the processor that it has data for processing. The signal from
hardware or software should have highest priority because the processor should leave the
current process and process the signal of hardware or software. This mechanism of processing
the signal is called Interrupt of the system.
What is an Interrupt?
Interrupt is a signal which has highest priority from hardware or software which processor
should process its signal immediately.
Types of Interrupts:
Although interrupts have highest priority than other signals, there are many type of interrupts but
basic type of interrupts are
1. Hardware Interrupts: If the signal for the processor is from external device or hardware is
called hardware interrupts. Example: from keyboard we will press the key to do some
action this pressing of key in keyboard will generate a signal which is given to the
processor to do action, such interrupts are called hardware interrupts. Hardware
interrupts can be classified into two types they are
● Maskable Interrupt: The hardware interrupts which can be delayed when a much
highest priority interrupt has occurred to the processor.
● Non Maskable Interrupt: The hardware which cannot be delayed and should
process by the processor immediately.
2. Software Interrupts: Software interrupt can also divided in to two types. They are
● Normal Interrupts: the interrupts which are caused by the software instructions
are called software instructions.
● Exception: unplanned interrupts while executing a program is called Exception.
For example: while executing a program if we got a value which should be
divided by zero is called a exception.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 20
Interrupt Handling:
We know that instruction cycle consists of fetch, decode, execute and read/write functions. After
every instruction cycle the processor will check for interrupts to be processed if there is no
interrupt is present in the system it will go for the next instruction cycle which is given by the
instruction register.
If there is an interrupt present then it will trigger the interrupt handler, the handler will stop the
present instruction which is processing and save its configuration in a register and load the
program counter of the interrupt from a location which is given by the interrupt vector table. After
processing the interrupt by the processor interrupt handler will load the instruction and its
configuration from the saved register, process will start its processing where it’s left. This saving
the old instruction processing configuration and loading the new interrupt configuration is also
called as context switching.
The interrupt handler is also called as Interrupt service routine (ISR). There are different
types of interrupt handler which will handle different interrupts. For example for the clock in a
system will have its interrupt handler, keyboard it will have its interrupt handler for every device
it will have its interrupt handler.
The main features of the ISR are
● Interrupts can occur at any time they are asynchronous. ISR’s can call for asynchronous
interrupts.
● Interrupt service mechanism can call the ISR’s from multiple sources.
● ISR’s can handle both maskable and non maskable interrupts. An instruction in a
program can disable or enable an interrupt handler call.
● ISR on beginning of execution it will disable other devices interrupt services. After
completion of the ISR execution it will re initialize the interrupt services.
● The nested interrupts are allowed in ISR for diversion to other ISR.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 21
Memory Management & Device Management
Virtual Memory
Virtual memory combines active RAM and inactive memory on Secondary Storage to form a
large range of contiguous addresses.
The primary benefits of virtual memory include freeing applications from having to manage a
shared memory space, increased security due to memory isolation, and being able to
conceptually use more memory than might be physically available, using the technique of
paging.
Paging
While copying virtual memory into physical memory, the OS divides memory into pagefiles or
swap files with a fixed number of addresses. Each page is stored on a disk and when the page
is needed, the OS copies it from the disk to main memory and translates the virtual addresses
into real addresses.
The portion of the hard disk that acts as physical memory is called a page file.
A page fault is a type of exception raised by computer hardware when a running program
accesses a memory page that is not currently mapped by the memory management unit (MMU).
Page faults usually indicate the need to allocate more memory.
Thrashing
The computer spends an unsuitably large amount of time transferring pages to and from a
backing store, hence slowing down useful work.
In computer science, thrashing occurs when a computer's virtual memory resources are
overused, leading to a constant state of paging and page faults, inhibiting most application-level
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 22
processing. This causes the performance of the computer to degrade or collapse. The situation
can continue indefinitely until either the user closes some running applications or the active
processes free up additional virtual memory resources.
Device Management
Device management is the process of managing the implementation, operation
and maintenance of a physical and/or virtual device.
Device drivers
A computer program that operates or controls a particular type of device that is attached to a
computer.
A driver provides a software interface to hardware devices, enabling operating systems and
other computer programs to access hardware functions without needing to know precise details
about the hardware being used.
They provide the interrupt handling required for any necessary asynchronous time-dependent
hardware interface.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 23
The input/output controller is a device that interfaces between an input or output device and the
computer or hardware device.
The input/output controller on a computer is commonly located on the motherboard. However,
an I/O controller can also be an internal add-on that can either be used as a replacement or
allow for additional input or output devices for the computer.
A controller is a chip, an expansion card, or a stand-alone device that interfaces with a
peripheral device.
Polling
This is the continuous checking of other programs or devices by a program or device to see
what state they are in, usually to see whether they are still connected or want to communicate.
In terms of device management, polling is the opposite of interrupting.
disadvantage – if they are too many devices to check, the time required to poll them can exceed
the time available to service the I/O device.
Buffer
This is a memory area that stores data while they are transferred between two devices or
between a device and an application. It is done for three (3) reasons:
● To cope with a speed mismatch between the producer and consumer of a data stream
● To adapt between devices that have different data transfer sizes
● To support copy semantics for application I/O
Spooling
To send (data that is intended for printing or processing on a peripheral device) to an
intermediate store (e.g. buffer).
In contemporary systems it is usually used for mediating between a computer application and a
slow peripheral, such as a printer.
Spooling allows programs to "hand off" work to be done by the peripheral and then proceed to
other tasks, or do not begin until input has been transcribed.
Spooling is a combination of buffering and queueing.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 24
File Management
The OS manages how data is organised into files. This makes it easier for the user to see files
using programs like the Windows File Explorer or Mac OS X Finder. The OS organises where
and how files are stored, deleted, read, found and repaired. It detects errors such as missing
disks or incorrect file names, and informs the user that errors have occurred.
File
A file is a named collection of related information that is recorded on secondary storage such as
magnetic disks, magnetic tapes and optical disks. In general, a file is a sequence of bits, bytes,
lines or records whose meaning is defined by the files creator and user.
Directories/Folders
A directory is a location for storing files on your computer. Directories are found in a hierarchical
file system, such as Linux, MS-DOS, OS/2, and Unix. The analogy of calling a directory a folder
came from the file folders used in an office filing system.
Security of files
User IDs
Each file is owned by a user. That user is identified by a User ID. The OS will usually only
permit the file owner or those users designated by the file owner to access a file.
Passwords
A password is a word or string of characters used for user authentication to prove identity or
access approval to gain access to a resource (a file), which is to be kept secret from those not
allowed access. A password is usually combined with some other identified (username, user id)
and is often used as a key to encrypt data.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 25
Lockwords,
In security a lockword is a password associated with a file or data set. The lockword is set by
the owner or creator and must be supplied in order to gain access to the file.
A lockword is different from a password in that it is meant to be shared by all persons who need
to gain access to a file, it is also not usually used to encrypt the file.
File Encryption
File Encryption means providing security for files. Encryption is the process of encoding a file in
such a way that only authorized parties can access it and those who are not authorized cannot.
Encryption does not itself prevent interference, but denies the intelligible content to a would-be
interceptor.
File compression
File compression is a data compression method in which the logical size of a file is reduced to
save disk space for easier and faster transmission over a network or the Internet. It enables the
creation of a version of one or more files with the same data at a size substantially smaller than
the original file.
Activity logs
The operating system keeps a log of every action taken on a file. This log records what was
done, what time and by which user.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 26
User Interface
Command line interface – it requires the user to type in commands using a special language.
This special language makes command-line interfaces difficult to use, especially for new
computer users. An example of a command-line interface is Microsoft Disk Operating System
(MS-DOS).
Menu-driven interface – a menu is a list of options from which you can choose what you want to
do. Application programs use menus as an easy alternative to having to learn program
commands. You can control the computer by choosing commands and available options from a
menu, using the keyboard or a mouse.
Graphical user interface (GUI) – these are provided by the Windows and Macintosh operating
systems. GUIs are presently regarded as the user interfaces which are easiest to use. As a
result, all computers are now supplied with a GUI system installed. The best way to remember
what makes up a GUI is to think of the word WIMP, which stands for Windows, Icons, Menus
and Pointers.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 27
Links and References
https://www.studytonight.com/operating-system/introduction-operating-systems
https://www.studytonight.com/operating-system
https://computer.howstuffworks.com/operating-system3.htm
https://www.techopedia.com/definition/3328/bootstrap
https://www.electronicshub.org/types-of-interrupts-and-how-to-handle-interrupts/
https://whatis.techtarget.com/definition/interrupt
https://www.bbc.com/bitesize/guides/ztcdtfr/revision/6
https://www.computerhope.com/jargon/d/director.htm
http://www.3kranger.com/HP3000/mpeix/en-mpe60/32650-90421/ch06s10.html
https://www.techopedia.com/definition/892/file-compression
Acknowledgement
The information contained herein are not necessarily original works. Much of
the content is widely defined terms and were taken from suitable publicly
available sources. Insofar as necessary the content was changed to suit the
requirements of CAPE Computer Science (2010 Syllabus).
These notes were compiled by Shane Edwards in 2019 for students at Saint
Jago High School.
~~~~~~~~~~
CAPE Unit 2 – Module 3 / Operating Systems / 28