Download as pdf or txt
Download as pdf or txt
You are on page 1of 81

CSC 333

OPERATING SYSTEMS

LECTURE NOTE I

What is an Operating System?


An operating system (OS) is software that manages computer (whether it is your smart phone
or a computer system) hardware and system resources to provides the tools that applications
need to operate. The birth of operating systems meant that programs no longer had to be
written to control the entire scope of computer operation. Instead, computer applications
could be written to be run by the operating system while the operating system worried about
computer resources and connected peripheral equipment such as printers and punched paper
card readers.
Most users do not directly interact with their device's operating system. They use other
software, which we call apps, instead to coordinate with the operating system. This
interaction leads to hardware operations. Let's consider the example of you typing a letter and
printing it. Your word processor is an app that will tell the operating system when to send a
file to the printer. While you are initiating the action yourself, you are telling the word
processor app to, in turn, communicate with the operating system, which then communicates
with the printer. This all happens at blazing fast speeds.
The earliest computers did not have operating systems. Every program that ran on these early
systems had to include all of the code necessary to run the computer, communicate with
connected hardware, and perform the computation the program was actually intended to
perform. This situation meant that even simple programs were complex. As computer
systems diversified and became more complex and powerful, it became increasingly
impractical to write programs that functioned as both an operating system and a useful
application. In response, individual mainframe computer owners began to develop system
software that made it easier to write and run programs and operating systems were born.
Any operating system performs some basic tasks like recognizing the input data from a
keyboard, sending output to the display screen, keeping files and directories of the disk and
controlling the peripheral devices like printers. An operating system can perform a single
task or operation as well as multiple tasks or operations at any time.

Categories of Operating Systems


There are lots of operating systems available because there are many types of hardware
available. The first operating systems were created in the 1950s for mainframe and
specialized computers. Today’s personal computers however, can be run with a host of
different operating systems, and the most common ones are Windows or the Macintosh
Operating System.
- Personal Computers:
When personal computers (PC) were first introduced, in the mid-1970s, the operating system
was known as CP/M (Control Program/Monitor). CP/M had a text-based interface.
In 1981, MS-DOS (Microsoft - Disk Operating System) became the standard operating
system for personal computers. MS-DOS was continually updated over several years. In
1985, Microsoft introduced the first operating system with a graphic-user-interface for the
personal computer giving users the ability to have graphic-based menus and icons to click on.
Both MS-DOS and Windows were improved in parallel until the 1995 release of Windows 95
which was a combination of Windows and MS-DOS.
-Apple Computers:
Apple computers, now called Macs, short for Macintosh, have a similar history in that they
came into mainstream use in 1984 with a graphic-based operating system. Both Windows and
Mac OS continue to improve with new versions being released throughout the years.
-Mobile Operating Systems:
Most phones today are smart phones, which indicates their functionality extends beyond just
being able to make phone calls. These smart phones have operating systems referred to as
Mobile Operating Systems. The leading operating systems for smart phones are Android and
iOS. Android, owned by Google, was first released in 2008 with releases each year thereafter.
iOS, owned by Apple, was first released in 2007 and has been continually updated with new
features since then.

History of Operating System


A big time waster in early computing was the time that it took to set up a computer to run a
job and then reset it and load the next job when the first program is completed. To run a
program, a deck of punched cards containing the program was loaded into a machine’s
memory. This program was the only thing that ran on that computer until the program
terminated. When the job is completed, an operator would load a program to dump memory
and would remove the tape, cards, and any printout. After that, the next job would be loaded
on the computer.

a) Batch Processing:
Early operating systems improved system throughput by processing jobs in batches rather
than individually. When a job finished, it would branch to a location in the “operating
system” that would contain software that would dump the state of the current job, and load
the next job. This greatly reduced the need for operator intervention. In the earliest systems,
this job transition software was encapsulated in a set of punched cards that were added to the
deck of cards that contained the user’s program.
Job control languages provided a way for programs to define their resource needs, such as
what tapes or card readers they need to use and what their anticipated run time is.

b) Operating Systems in 1954–1957 (A high-level language FORTRAN was developed):


With high-level languages, programmers no longer had to understand the architecture of a
computer. Early compilers, including early FORTRAN (FORmula TRANslator) had to fit in
1,024 12-character words and still leave enough room for data. It often took two hours to
compile a program because the tape units were kept busy refetching data.

c) Operating Systems by the late 1950s:


By the late 1950s, Operating systems supported the following;
-Single stream batch processing
-Common, standardized, input/output routines for device access
-Program transition capabilities to reduce the overhead of starting a new job
-Error recovery to clean up after a job terminated abnormally. Job control languages that
allowed users to specify the job definition and resource requirements

d) Operating Systems in the 1960s


The goal of operating systems in the early 1960s was to improve throughput. Computers were
incredibly expensive and it was important to find ways of utilizing every possible second of
CPU time.
Multiprogramming: several programs were kept in primary storage at once and the processor
was switched between programs. Multiprogramming works because of the mismatch between
I/O (input/output) device speeds and processor speeds. Tens of thousands of cycles could be
wasted while a program was waiting for an I/O operation to complete (tens of millions to
billions on today’s processors). Instead of having a processor sit there and do nothing while
an I/O operation was going on, it could switch to running a different program.
-Multiprocessing systems: several processors cooperate with one another. Some of these
began to emerge in the 1960’s.
-Transaction processing systems: IBM developed the SABRE airline reservation system for
American Airlines in 1960. It consisted of two connected IBM 7090 computers (built with
discrete transistors) Travel agents communicated with the central computer via typewriter
terminals. Although SABRE was a dedicated system and not a general purpose operating
environment, it ushered in new requirements for computing.
With systems such as SABRE:
-User accounts and concurrent access required the creation of protection mechanisms and
password storage.
-Computers now had to operate interactively (conversationally). Because of this, human
factors became an issue: response time and ease of use.
-With the widespread deployment of disks, access storage organization techniques were
developed followed by file systems.
-Data communication links were used for remote access. For the most part, these were
telephone lines.

e) Operating Systems in1961: (The dawn of minicomputers. Computing for the masses)
Digital Equipment Corporation (DEC) introduces the Programmed Data Processor 1 (PDP–
1). It’s a veritable bargain at $125,000-$250,000 as any competitive systems at that time
began at $1 million. Moreover, it needed no staff of attendants and operators. A lot more
companies could now afford computers. In fact, individual departments could have their own
computer.

f) Operating Systems in 1962 (Compatible Time-Sharing System (CTSS) from MIT -Time
sharing)
CTSS ran on the IBM 7094 with special hardware. It proved the value of interactive time
sharing systems and the value of sharing data and programs on-line. This system was a
precursor to the Multics operating system.

g) Operating Systems in 1963 (Burroughs Master Control Program (MCP) for the B5000
system)
-Virtual memory and multiprocessing
MCP was the first operating system written in a high-level language (note that this was not a
portable operating system; it only ran on the B5000 computer). The B5000 system running
MCP gave the user:
-Multiprogramming
-Multiprocessing
-Virtual storage (provides the illusion of a system having more physical memory than it really
does)
-Source language debugging capability

h) Operating Systems in 1964: (IBM System/360 The “system”)


Traditionally, a simulator interprets all operations in software while an emulator has
hardware to support the execution of instructions. These days, it is common to use both terms
to refer to software. Emulation now usually refers to software or hardware that models the
interfaces and behaviour of a device but not necessarily its internal state. The emulated
system may behave differently internally but provides the same external interface. API hooks
to implement a given hardware function of some device are an example. Simulation refers to
modelling the internal components of a system.
IBM bet the company on this one. It created a line of five computers, all compatible, that
gave users a migration path as their computing needs grew. It included the largest assortment
of simulators and emulators ever assembled for backward compatibility. Card readers, tape
drives, printers, and memory devices were redesigned to make them faster (for instance, the
System/360 Model 1403 Chain Printer printed 1,100 lines of text per minute). R&D for the
project cost over $1 billion dollars. Within six months after its announcement, IBM booked
orders for System/360s that totalled more than three times IBM’s entire annual income. The
bet paid off big time. System/360 operating system goal was to deliver one operating system
for the entire line of computers.
The reality: It proved difficult to create a system that would satisfy users with varying
degrees of sophistication. It also didn’t seem fair to burden smaller machines with heavy-duty
operating systems. A family of operating systems therefore emerged. These includes;
PCP/360 — sequential job system
MFT: multiple job system, fixed number of tasks. The system memory is divided into a fixed
number of partitions. Programs are loaded into these partitions and the processor spends some
time on each partition
MVT: multiprogramming with a variable number of tasks. A new job asks for a partition of a
certain size, gets it, runs, and then the partition is free again. This later became IBM’s MVS
system. All memory references are direct memory references at this time (the memory
address you ask for is the one you get).
The first disk drive, the IBM 350 disk storage unit, was introduced in 1956. It had a capacity
of 3.75 megabytes stored as five million six-bit characters on fifty (!) 24-inch diameter disks.
IBM leased it for $3,200 per month.
By the 1960’s disk storage finally comes into widespread use. It offers high capacity, almost-
random-access-storage. IBM created a family of Disk Operating Systems (DOS, DOS–2314,
DOS MP, DOS VS, DOS/VSE) to take advantage of this technology.
Multics was an ambitious operating system developed by MIT, General Electric, and Bell
Labs. It was designed to be the operating system for GE’s GE–645 mainframe but was later
targeted to Honeywell machines after Honeywell acquired GE’s computer business

i) Operating Systems in the 1966s


Minicomputers get cheaper, more powerful, and really useful
-Widespread computing
DEC introduces the PDP–8. It costs a mere $20,000 and becomes used by small businesses,
universities, and high schools. Five operating systems are available. Here’s a list,
paraphrased, from Introduction to Programming PDP–8 Family Computers, Digital
Equipment Corporation, 1969:
-Paper Tape Programming System — I/O of programs and data is performed manually via a
paper tape reader and punch All programming systems begin by loading certain system and
utility programs into core via a paper tape.
-DEC tape Programming System — I/O of programs and data is performed via a DECtape
unit.
-4K Disk Monitor System — 4K system programs are run under control of the Disk Monitor
with disk input and output. You’d use this with a 4K memory system. A DECtape contains
over half a million octal words of storage.
-PS/8 Programming System — 8K system programs are run under control of the 8K
executive program using either DECtape or disk input/output. System and utility programs
include languages (FOCAL, BASIC, FORTRAN-D, assembler), and utilities (PIP for
peripheral device control, DDT for debugging, and an editor).
-TSS/8 Time-Sharing System — More than one user is sharing the computer under control of
he TSS/8 Monitor, using 4K system programs in a disk environment. Each user has a separate
Teletype terminal. It allows device-independent access to as many as 15 I/O devices. The
user program may call upon the executive routines for several services, including loading
device handlers, assigning names to devices, creating files, and performing line input/output
to the Teletype.

j) Operating Systems in 1967–1968: (The mouse)


Introduced a new form of user interaction … dominant until the iPhone & iPad
The mouse was created by Douglas Engelbart at the Stanford Research Institute’s
Augmentation Research Center (ARC). He and his team at the ARC invented the mouse, the
bit-mapped display, graphical user interface concepts, teleconferencing, and hypertext. This
was demonstrated in 1968 at the Fall Joint Computer Conference and is known as The
Mother of All Demos. This was back in 1968. We have not seen substantial changes to this
for 47 years!

k) Operating Systems in 1969:


The UNIX Time-Sharing System from Bell Telephone Laboratories
Small OS, toolkit approach
The first edition of UNIX ran on a PDP–7 and was written in assembly language. It
emphasized a small and simple kernel and a rich set of utilities (that mostly handled line-
oriented text-based data) that could be connected together to perform a variety of tasks. It
incorporated a number of ideas from Multics, such as a hierarchical file system, multiple
levels of file access permission, input/output redirection, and pipes.

l) Operating Systems for the 1970s


The 1970s were characterized by the following traits:
-Multi-user, multi-tasking reigns supreme.
-Dynamic address translation hardware creates virtual memory that operating systems must
handle. Virtual machines can now exist.
-Modular architectures
-Emergence of portable design
-Personal, interactive systems
-We also see two developments that will transform computing:
-Data networking. Computers begin to get connected over data communication links.
-Microprocessors. These will make computers small, cheap, and personal. For about 20 years,
these will be technological laggards, rediscovering what real computers already had many
years earlier. By the 1990s, they transform into technology leaders. DEMOS, Los Alamos
Message passing this system ran on the CRAY–1 supercomputer and was the first operating
system to be based on message-passing.

m) Operating Systems for the 1971: Intel announces the microprocessor


Not a big deal yet, but just wait…
The Intel 4004 contained 2,000 transistors and performed 60,000 operations per second. It
was a four bit machine with effectively as much power as the ENIAC. It found a home in
some desktop calculators.

n) Operating Systems for the 1972:


IBM comes out with VM: the Virtual Machine Operating System
Virtual memory and virtual machines
Goal: Can we build a machine on which we could run different operating systems
concurrently to develop them, debug them, and measure their performance?
Developing an operating system is tricky: you need a dedicated computer on which to run the
operating systems. With mainframe computers being incredibly expensive (millions of
dollars) and taking up a lot of space, even IBM programmers couldn’t get one apiece.
IBM built a modified System/360 (the model 67) that supported address translation. Address
translation means that the processor thinks it’s referencing one memory location but it really
gets translated into another. Every process can now get its own address space and feel like it
owns the machine.
VM was built with a modular approach: resource management and user support were split
into separate components. The Control Program (CP) is the part of VM that creates virtual
machines on which various operating systems run. A virtual machine contains not only a
virtual address space, but also virtual readers, disks, punches, printers, and tape drives.
Accessing devices or executing privileged instructions, both of which operating systems do,
causes an interrupt to the CP which maps the requested action into a physical action. With
VM, one can:
-Test out a new operating system while still doing production work on the old one
-Run multiple copies of the same operating system (VM/CMS runs a copy of CMS, a single-
user system, for each user).
-Run special-purpose operating systems for certain tasks
VM started as an internal IBM project to give its engineers the ability to develop and test
operating systems but turned out to be useful for IBM customer’s as well. Virtual machines
pretty much died off after this until the 1990s but are enjoying a renaissance in the 2000s.
Operating Systems for 1973: UNIX 4th Edition is published
The number of UNIX installations is now above 20, and many more are expected. None of
these has exactly the same complement of hardware or software
— Preface to the fourth edition.
Portable operating system
This is the first version of UNIX that was mostly written in the C programming language.
The system runs on a PDP–11 and comes with an editor, assembler, calculator, electronic
mail, compiler, and a bunch of utilities. Since the Bell System was a regulated monopoly and
could not be in the computer business, UNIX was practically free to universities (they had to
pay for the documentation and tape). You didn’t get support, but you got source. UNIX was
an easy system to understand and modify. It was soon ported to different machines.
Three things about UNIX were crucially important:
-UNIX was mostly written in C. This made it easier to write, debug, enhance, and maintain
the software. The approach of using a high-level language for writing an operating system
was a relatively novel one. Operating systems were written for specific machines, had to be
efficient, and had to access various low-level aspects of the machine. The main compiled
high-level languages of the 1950s and 1960s were FORTRAN and COBOL (LISP was also
out there but it was interpreted). Both were unsuitable for the task. Previously, Burroughs
wrote their operating system for the B5000 in a version of Algol. MULTICS, a large OS
project that preceded UNIX, was written in EPL, an early version of PL/I. The language was
largely unsuited to operating systems and the compiler was so unoptimized that “ a simple
PL/I statement might translate into a whole page of code” [ref]. C was a simplified high-level
language that was ideal for systems programing. While it incurred some inefficiencies, they
were not unreasonable ones.
-The use of a high level language made it easier to recompile the operating system for a
different computer architecture. Traditionally, operating systems were targeted for a specific
machine architecture. For example, MULTICS, the predecessor to UNIX, was designed
specifically for a GE–645 computer. The architecture and the OS went hand-in-hand. While
UNIX was initially written for a PDP–8 and then a PDP–11, the fact that large sections of the
operating system were architecture independent and written in a high-level language meant
that it was not a daunting task to port the code onto different computer architectures.
-By 1975 (sixth edition), UNIX was distributed to universities. This exposed a large group of
computer science students to the operating system at the source code level. Here was a
system they could use, modify, and fully learn. This led to numerous enhancements. Most
came from the University of California at Berkeley in the form of the Berkeley Software
Distribution (BSD).

o) Operating Systems for 1973: Ethernet


Robert Metcalfe invents Ethernet while at Xerox PARC (Palo Alto Research Center). It’s not
the first data network but it was quickly promoted as a standard and its packet switching
approach made it inexpensive and highly scalable. It quickly becomes the dominant
networking technology for local area networks.
Xerox Alto
Video display, the desktop, the mouse, ethernet networking, WYSIWYG editing
The Alto was a project developed at Xerox PARC. Although it was not a commercial success
and Xerox abandoned the project, it was pivotal in the history of computer systems since it
integrated the mouse, ethernet networking, a bitmapped video display, and a detachable key.
It also introduced the desktop interaction metaphor on a graphical display.

p) Operating Systems for 1974 The Personal Computer Age begins


Intel announces the 8080 microprocessor. It has a larger instruction set than its predecessor,
the 8008. Better yet, it requires only six additional chips to produce a working computer. It
executes one million instructions per second and initially costs $360. Prices fall to under
$100 by late 1975 thanks to competition.
The first personal computer
Popular Electronics featured the MITS Altair computer on its cover. A kit for this 8080-based
machine cost $397. It had no keyboard, video display, disk drive, tape storage, or software.
Most systems had 256 bytes of memory (that’s bytes, not kilo-, or megabytes). Instructions
were entered through switches on the front panel.
A later model, the Altair 8800b, had a serial line to support a video terminal and printer. At
the time, a Lear-Siegler ADM–3A, a dumb video terminal with an 80x24 character display,
cost $995/kit, $1195/fully assembled). If you couldn’t afford that, you might get a used
teletype. Thousands upon thousands of people bought these computers. They couldn’t do all
that much, but it was pretty cool for many to own your very own computer. This led to the
Homebrew Computer Club, which led to the creation of more PC and peripheral
manufacturers as well as to the creation of software.
Now that there was an obvious market for this, Intel was under attack. By 1975, the Intel
8080 processor was being sold for $179. In 1975, the 6502 processor was introduced for a
mere $25. With this low price, it became the processor of choice for a number of personal
computers, including the Commodore PET, The Apple II, Atari, and others. Also, a better and
cheaper processor that was backward compatible with the Intel 8080 instruction set was
introduced by Zilog in 1976 — the Z80. Mainstream personal computers would not see an
Intel processor in them until the IBM PC.
Gates and Allen write BASIC for the Altair
PC programming made simple
Now lots of people could write programs on their PC without having to use assembly
language. Most people stole this software, which led to Bill Gates’ Open Letter to Hobbyists.

q) Operating Systems for 1975 CP/M: An operating system for 8-bit Intel-based PCs
The introduction of the BIOS (sort of) into Intel PC architectures
Gary Kildall of Digital Research gives the world CP/M (Control Program for
Microcomputers). It runs on Intel 8080 (and on the later 8085 and Zilog Z80) machines. It
was not targeted to any specific machine and was designed to be adaptable to any machine
with an 8080-family processor and a floppy disk drive. It was a rudimentary operating
system: a simple command interpreter, program loader, and file system manager. Only one
program ran at a time. When it was done, command transferred to the console command
processor code, which prompted the user for the next command. This operating system
consists of:
CCP: The Console Command Processor (command interpreter)
BDOS: The “Basic Disk Operating System”. This was the program loader and the software
that figured out how to manage and interpret the file system on a floppy-disk.
BIOS: This term should sound familiar. The Basic I/O System (BIOS). Since each machine
was different, you had to write the low-level functions yourself (get a character from an input
device, read a sector from the floppy disk, write a sector, write a character to an output
device, …).
The system also came with a few programs, such as an assembler, a line editor, and a
program to copy files. This is the sort of software people expected to come with their
computers at that time. CP/M was a direct precursor of MS-DOS. MS-DOS was derived from
QDOS, the Quick and Dirty Operating System, which was essentially a reverse-engineered
version of CP/M for the 8086 processor, Intel’s first 16-bit CPU. Microsoft bought QDOS
from Seattle Computer Products for $50,000. Gary Kildall could have had the IBM contract
for the IBM PC operating system, but he botched it. The first IBM PC came with a BASIC
interpreter in ROM and an assembler, a line editor, and a program to copy files.

r) Operating Systems for 1976: Apple II


A ready-to-use computer
BASIC is built-in. It allows the display of text and graphics in color. This was a “plug &
play” machine that remained in production for fifteen years. This machine made personal
computers accessible to non-geeks. That was a good chunk of the population.
By 1977, a couple other ready-to-use PCs were sold: Radio Shack’s TRS–80 and the
Commodore Pet.

s) Operating Systems for 1977


DEC introduces the first VAX computer running VMS (the VAX 11/780)
A 32-bit family of minicomputers sharing the same instruction set and virtual memory
The VAX 11/780 was a hugely popular larger minicomputer and one of the earliest
computers to use virtual memory to manage the [at the time] huge 32-bit address space of the
computer (the smaller PDP–11 series was a 16-bit machine).
Like the IBM System/360 (but smaller and cheaper and from a different company), this was
to become a series of computers. Despite the range of size and power of different models,
they all have the same architecture. VAXes (also called Vaxen) could be networked together
and operate in a peer-to-peer relationship (any machine can be a client or a server).
VMS (Virtual Memory System) was the DEC-issued operating system for the VAX, although
the VAX soon became a popular platform for UNIX.
VMS was designed to take advantage of the VAX’s architecture, incorporating demand
paging, which enabled the computer to allocate and load a page of memory when the process
needed it and map it onto the correct memory location for the process. This avoided having to
pre-load an entire program into memory. Securiy was a core facet of the design. It supported
privilege checks and account lock0outs. VMS supported 32 priority levels for process
scheduling and had support for real-time processes.

t) Operating Systems for 1979:


Visicalc and WordStar come out
Killer apps
These are the first of the killer apps for the personal computer: programs that would justify
your purchase of the computer.

u) Operating Systems for the 1980s


Personal computers are a strong force, but the operating systems are primitive: not much
more than a command interpreter, program loader, and device drivers. Even with that,
programmers often break convention and access devices directly. Networking, particularly
among workstations, becomes widespread and fast. It’s feasible to access files across a
network as one would locally. Networked operating systems become interesting.
Microkernels with a message passing structure become hot topics, but never really become
mainstream operating systems. Mach, designed as a microkernel, becomes a basis for both
Windows NT (and derivatives) as well as OS X but is really too big to be considered a
microkernel architecture.
A key mechanism that entered operating systems was multithreading, the ability for one
process to have multiple concurrent threads of execution. Initially, this was primarily useful
for network servers since one process may now service many requests concurrently.
User interfaces start becoming important. Windowing systems get refined.

August 12, 1981: IBM introduces the IBM PC


IBM legitimizes the personal computer
The IBM PC was an open machine based on the Intel 8088 processor (IBM will give you the
schematics and parts list). With the most respected brand in computers selling a personal
computer, it was no longer a hobbyist’s toy but something that could be a serious personal
business machine. A lot of people bought these. You couldn’t go wrong buying IBM and
IBM set a standard that is still followed. Intel and Microsoft (not IBM) were the big winners
here because lots of other companies started building clones of the IBM PC but those clones
still needed the processor and needed the operating system.
The first IBM PC featured:
-16K bytes memory (expandable to 256K)
-2 floppies, each holding 160K bytes
-2 displays available: a color and a monochrome
-PC-DOS from Microsoft. This was essentially a CP/M clone. Bill Gates agreed to provide an
OS to IBM even though he had nothing to give at the time. He cleverly negotiated the rights
to sell the operating system (probably anticipating the PC clones that would come out in the
near future).
-A price of $2495 with 16K bytes RAM and one floppy. Add $1000 to get 256K bytes RAM
1983 Microsoft begins work on MS-Windows
It’s slow, buggy, and generally an embarrassment. People stick with MS-DOS.

1984 Apple Macintosh comes out


Personal computers for everyone
The Mac introduces the mass market to the mouse and windows. The command line is now
dead as far as the average consumer is concerned. Popular for its user-friendly interface. The
point-and-click mouse-based interface is derived from the Xerox Star system created at
Xerox PARC (Palo Alto Research Center).

1985: Networked file systems on workstations


Remote resources that look like local ones
SUN’s NFS allows users to mount file systems from other machines onto their own
machines. Apollo’s Domain system incorporates the entire network of machines into its file
name space. Now you can access data that lives on other machines in just the same way as
you access data on your machine. A bunch of companies start selling networked personal
workstations for the enterprise. Sun wins.
1986: Mach
Microkernels
Mach is a microkernel system that was designed to allow the emulation of a variety of other
operating systems over it (such as various variants of UNIX). It allows transparent access to
network resources, can exploit parallelism, and can support a large address space. The
principles of Mach become a basis for Microsoft’s Windows NT and for Apple’s OS X.
1980’s Amoeba
A microkernel with autonomous components
The system is a distributed collection of process servers (processor pools), file servers,
compute servers, and others.
Amoeba is built with a microkernel architecture. The Amoeba microkernel runs on all
machines in the system The fundamental concept under Amoeba is the object (a collection of
data upon which certain well-defined operations may be performed). These objects are named
and created by capabilities. Amoeba demonstrated a number of interesting concepts but was
never adopted commercially.

Late 1980’s: Plan 9 from Bell Labs


UNIX is getting old; let’s take the good ideas, dump the bad, and start over
Built with the realization that previous efforts of building distributed networks of systems and
getting them appear as one uniform entity weren’t entirely successful.
Goal: Build a distributed, scalable system that appears as one time-sharing system that can
support thousands of users, terabytes of files, and gigabytes of memory. Plan 9 is composed
of a number of separate components: CPU servers, terminals (with processing), file servers,
and networks.
Plan 9 never gained commercial traction or even much adoption within Bell Labs. Although
it had great ideas, the user community didn’t care a whole lot about new operating systems;
they were no longer satisfied when presented with an operating system and a few programs.
They want to run their favorite applications. Backward compatibility was important.

v) Operating Systems for 1990 Microsoft Windows 3.0 comes out


Microsoft Windows 1.0 first came out in 1985, followed by Windows 2.0 in 1987. These
were essentially just graphical shells over MS-DOS, which is a single user, single-tasking
system. However, Windows provided users with drop-down menus, scroll bars on on-screen
windows, and dialog boxes. Windows 1.0 required a PC with a minimum of 256 KB of
memory. Neither of these releases were hugely popular as most applications still ran under
MS-DOS.
In 1990, Microsoft introduced Windows 3.0. This was the first hugely popular version of
Windows, although many of the DOS underpinnings were still clearly visible. Performance
improved, icons were better developed, and the system fully supported Intel’s new 386
processor. The 386 processor was the first Intel processor to provide support for virtual
memory, which now allowed Windows to multitask multiple instances of MS-DOS
programs, giving each program its own virtual address space. Equally importantly, Microsoft
introduced a Windows Software Development Kit (SDK), which provided developers with a
standard API for accessing system functions, including graphics, ushering in a huge wave of
application development for the platform.
1992 The first Windows virus comes out
The virus, named WinVir, was discovered. An infected program would search for other
executable files and edit those files to insert copies of itself in them. Then it would remove
itself from the original file to restore that file to its original condition. Viruses became an
endemic problem largely because operating systems users generally ran with administrative
privileges in systems such as Windows, allowing programs that they execute to have free
access to all files in the system.
1991 GNU/Linux
A free Unix-like operating system becomes available
UNIX, while achieving great popularity, was only freely available to universities. The Bell
System was a regulated monopoly and could not sell computer products. After the breakup of
the Bell System in 1984, AT&T wanted to get into the computer business and free university
licensing of the UNIX operating system was revoked. Minix was created by Andrew
Tanenbaum as a small Unix-like operating system. Unfotrunately, like UNIX in the past, it
was freely available only to universities and research.
Linux started as a kernel originally written by Linus Torvalds and was complemented with a
wide range of GNU user-level tools (gcc, make, emacs, and much of the other stuff that one
expects in a Unix distribution). It evolved over time. Although it has not achieved widespread
popularity in PC desktops (where Windows and OS X dominate), it runs on many servers as
well as embedded systems. In the latter category, it serves as the underpinnings for Google’s
Android and Chrome OS operating systems, the TiVo digital video recorder, various set-top
boxes, automotive computers, and industrial controllers.
1993 Windows NT
The design of VMS was led by David Cutler. When the project was canceled in 1988,
Microsoft hired Cutler and around 20 other DEC employees from the VMS team to work on a
next generation operating system for Windwos that would rival UNIX. This led to the
creation of Windows NT. NT is, in many ways, a successor to VMS and shares much
terminology and concepts in common.
Windows NT was also inspired by Mach’s microkernel architecture. NT is not a microkernel
but enables OS emulation subsystems to run as user-level server processes. This enables it to
implement backward compatibility support with other operating systems, including DOS,
OS/2, POSIX (UNIX interface), and 16-bit Windows.
“NT” stood for New Technology. It was designed to be a better Windows, offering
networking, per-object based processes, and file protection mechanisms. Unlike VMS, it was
written almost entirely in C and designed to be portable across different processor and
hardware architectures. MS-DOS and earlier editions of Microsoft Windows were written
only for the Intel x86 family of processors. NT introduced a hardware abstraction layer to
provide an abstract interface to the underlying hardware. The system was fully 32-bit while
Windows was written with 16-bit architectures in mind. At the high levels of the operating
system, API modules provided the option to support a variety of system call interfaces,
although only Win32 was ultimately supported. The system could also handle a variety of
installable file system modules, with NTFS being the core file system.
NT was arguably the last modern operating system that was written from scratch. Every
successive version of Windows has been based on an evolution of Windows NT.
1993: Mosaic
The web browser is born
Mosaic, the Netscape Navigator (1994), and Internet Explorer (1995) usher in the web. The
web browser becomes the killer app for the mid–1990s and onward. At first, the web is just
an information navigation tool but it very quickly becomes an applications and service
delivery platform where the web browser serves as a user interface to services that reside on
remote Internet-accessible servers. It is almost inconceivable to image life without the web.
The browser, of course, is not an operating system, but it let many to reexamine the role of
the operating system for consumer computing and imagine a world where all services are
provided via a web browser.
w) Operating Systems for The 2000s
1997 and another try in 2009: The Internet appliance
If all the good stuff is on the web, how much do you really need in a PC and operating
system?
The complexity and cost of managing bloated PCs (and the requisite software and disks) led
to the idea of thin clients or the appliance computer (take it out of the box, plug it in, and it
works) that will run a very limited set of software (such as a web browser) All the interesting
stuff will be out on the network.
The first attempt to do this didn’t succeed. In July 2009, Google announced Google Chrome
OS. The goal of Chrome OS is to create a lightweight system with a minimal user interface
running a browser. All the applications are on the web. The jury is still out on whether this
will be a success.
2007: iOS
Multitouch UI
Apple’s iPhone makes the multi-touch user interface mainstream. The user interaction model
includes a virtual keyboard and support for tap, swipe, pinch and un-pinch gestures to zoom
and unzoom to support direct, finger-based, manipulation of on-screen objects. The concept
of multi-touch interfaces goes back to the 1970s, with interfaces using pinch-to-zoom
gestures being created in the early 1980s. The underlying operating system, named iOS, is
derived from OS X but with changes to support a different windowing system, restrictions on
background processes to enable better application performance and improved battery life, and
mobile services such as push notification and the ability to notify apps when a location
changes.
2008: Android OS
A free [2] OS platform for mobile phones
Google develops a variant of Linux that is targeted to mobile phones. The Linux system and
its libraries are stripped down of excess baggage, standard libraries for accessing components
such as a GPS, accelerometer, telephony, and other components found on mobile phones are
added, and a graphical UI framework is put in place. All applications are written in Java run
on a Java-like virtual machine (Dalvik). This ensures that the applications are not dependent
on any specific processor platform.
2009 The Internet of Things (IoT)
All sorts of appliances and devices talking with each other
The term, Internet of Things was coined by Kevin Ashton in 2009 but the ideas go much
further back in time. As microcontrollers became smaller, cheaper, and more power efficient
and wireless networking became ubiquitous, it became clear that all manner of objects could
be controlled or could report their status. This include things such as
-light bulbs (e.g., the Philips Hue connected bulb)
-fitness devices (e.g., the Fitbit activity wristband)
-home alarms, heating, AC systems (e.g., the Nest thermostat and Nest Protect smoke
detectors)
-hot water heaters
-washing machines, ovens, and other appliances
-shipping containers
-vending machines
-digital signage, from billboards to shelf tags
and many more. A key development is not just the ability to control devices from an iPhone
but to enable intelligent machine-to-machine (M2M) communication. To enable this requires
standardized APIs and network protocols. Given that many of these devices are small and
simple, installing a bloated operating system such as Linux is overkill. However, security can
be an important concern and needs to be incorporated at the most fundamental levels of the
system while still providing convenience and expected functionality. Because these devices
are not likely to get software updates and patches as often as PCs (or, in most cases, never),
they are at risk of harboring known security vulnerabilities. The research and industrial
community is still in the process of developing suitable operating environments and
communication protocols for these systems.

Overview of Hardware Fundamentals


A computer is a fast calculating device that can perform arithmetic operations. It is not just a
calculating device. It can perform any kind of work involving arithmetic and logical
operations on data. It gets the data through an input device, processes it as per the instructions
given and gives the information as output.

Hardware refers to any physical component of a computer. In today’s computer industry, a


wide variety of hardware components are available. Hardware components are classified
according to their functional use within a computer system. They can be broadly classified
into three categories namely input devices, output devices and storage devices. It is essential
for us to be aware of the working and uses of different hardware components of a computer.

Every part of your computer is the result of years of research and development. Parts that
were once hand made at a cost of thousands of man-hours are now mass produced for a
fraction of a rupee. Computer parts can be divided into two groups, hardware and software.

Hardware is any part of the computer that you can touch. The seeming miles of wires that get
tangled on your desk, the CD drive, the monitor are all hardware. Software is a set of
electronic instructions consisting of complex codes (Programs) that make the computer
perform tasks. Windows is a software, so is any other program that runs on your computer.

While there are thousands of parts even in the smallest computers that make up its hardware,
you are not required to know them all. You only need to know about basic computer
hardware.

Basic computer hardware consists of the following parts:

1. CPU (Central Processing Unit)

The CPU is considered the brain of the computer. It performs all types of data processing
operations, stores data, intermediate results and instructions (program). It controls the
operation of all parts of computer. A CPU has 3 components as listed below.

(A) CU (Control Unit)


The control unit (CU) is a component of a computer’s central processing unit (CPU) that
directs operations of the processor. It tells the computer’s memory, arithmetic logic unit and
input and output devices how to respond to a program’s instructions. However, the Control
Unit doesn’t process any data.
(B) ALU (Arithmetic Logic Unit)
Think of the ALU as the logical part of the brain. When any mathematical calculation or
decision/logic needs to be carried out, the instruction is passed on to the ALU. The ALU
thinks in bits (i.e. binary digits – ‘0’s and ‘1’s.)

It is made up of a group of memory locations built directly into the CPU called registers.
These are used to hold the data (binary information) that are being processed by the current
instruction.

(C) Memory
Primary memory is memory that is part of the computer itself and necessary for its
functioning. It consists of mainly two types of memories:
(i) Random Access Memory (RAM)
RAM is the internal memory of the CPU for storing data, program and program result. It is
read/write memory which stores data until the machine is working. As soon as the machine is
switched off, data is erased. RAM is volatile. Volatile means that the data stored in memory
is lost when we switch off the computer or if there is a power failure. Hence a backup
Uninterruptible Power System (UPS) is often used with computers. There are different types
of RAM available. Some of them are described below.

Dynamic Random Access Memory (DRAM): A type of physical memory used in most
personal computers. The term dynamic indicates that the memory must be constantly
refreshed or it loses its contents. This type of memory is more economical.

Static Random Access Memory (SRAM): A type of memory that is faster and less volatile
than DRAM, but requires more power and is more expensive. The term static is derived from
the fact that it does not need to be refreshed like DRAM.
Synchronous Dynamic Random Access Memory (SDRAM): A type of DRAM that has a
much higher processing speed.

(ii) Read Only Memory (ROM)


The memory from which we can only read but cannot write on it. This type of memory is
non-volatile. The information is stored permanently in such memories during manufacture. A
ROM, stores such instructions that are required to start a computer. This operation is referred
to as bootstrap. The different types of ROM are given below.

MROM (Masked ROM): The very first ROMs were hard-wired devices that contained a pre-
programmed set of data or instructions. These kinds of ROMs are known as masked ROMs
which are inexpensive. The MROM cannot be programmed by the user.

PROM (Programmable Read only Memory): PROM is read-only memory that can be
modified only once by a user. The user buys a blank PROM and enters the desired contents
using a PROM program.

EPROM (Erasable and Programmable Read Only Memory): The EPROM is a type of a
PROM which can be programmed by the user multiple times. EPROM is erased by exposing
it to ultra-violet light for a duration of up to 40 minutes. Usually, an EPROM eraser achieves
this function.

EEPROM (Electrically Erasable and Programmable Read Only Memory): The EEPROM is
programmed and erased electrically. It can be erased and reprogrammed about ten thousand
times. Both erasing and programming take about 4 to 10 milliseconds.

2. Secondary Storage (External Storage Devices)

Floppy diskettes, hard disk, tapes and optical disks come under the category of external
storage devices or ancillary storage devices. These devices are very sensitive to
environmental conditions (humidity and temperature) as well as to external magnetic fields
and need to be stored carefully. They are not compulsory for the functioning of the computer
but are useful for expanding the computer’s memory.

(A) Floppy Disk


Floppy disks are primarily used on PCs. Information on a floppy disk is recorded in the
magnetized states of particles of iron oxides evenly placed upon concentric circles known as
tracks.
(B) Hard Disk
It is a non-removable enclosed magnetic disk included in most PCs. It contains a stack of
metal platters, each coated with iron oxide, that spin on a spindle and the entire unit is
encased in a sealed chamber.
(C) Magnetic Tape
This is plastic tape, usually made of Mylar that is coated with iron oxide, thereby enabling the
introduction (writing); retention (memory) and reading of magnetically recorded information.
The best use of tape storage is for data that you do not use very often.
(D) Optical Disc Drive
An optical disc drive (ODD) is a disk drive that uses laser light or electromagnetic waves for
reading or writing data to or from optical discs (normally CD-ROM). A CD-ROM is a pre-
pressed optical compact disc which contains data. The name is an acronym which stands for
“Compact Disc Read-Only Memory”. Computers can read CD-ROMs, but cannot write
to CD-ROMs which are not writable or erasable.
(E) USB
A USB flash drive, also commonly known as a USB drive, USB stick and a variety of other
names. It is a data storage device that includes flash memory with an
integrated USB interface. USB flash drives are typically removable and rewritable, and
physically much smaller than an optical disc.

(3) Peripherals

Peripheral devices are devices connected to the computer externally. If a peripheral device is
disconnected, the computer will still be able to work; only functions performed by this
peripheral device will not be available. Here are the most used types of peripheral devices:

(A) Keyboard
The most common and very popular input device which helps in inputting data to the
computer. It consists of keys that are capable of inputting alphabets, numbers and special
characters. You can also navigate using the keyboard and perform shortcut functions.
(B) Mouse
Mouse is the most popular pointing device and cursor-control device having a small palm
size box with a round ball at its base which senses the movement of mouse and sends
corresponding signals to CPU when the mouse buttons are pressed.
(C) Monitors
Monitors, commonly called as Visual Display Unit (VDU), are the main output device of a
computer. It forms images from tiny dots, called pixels that are arranged in a rectangular
form. The sharpness of the image depends upon the number of pixels.
(D) Printer
Printer is an output device, which is used to print information on paper.
Impact Printers: The impact printers print the characters by striking them on the ribbon which
is then pressed on the paper.

Non-Impact Printers: Non-impact printers print the characters without using ribbon. These
printers print a complete page at a time so they are also called as Page Printers. Laser
Printers, Inkjet Printers.

(E) Joy Stick


It is a device used to move cursor position on a monitor screen. It is mainly used in Computer
Aided Designing (CAD) and playing computer games.
(F) Scanner
A scanner allows you to scan printed material and convert it into a file format that may be
used within the PC.
(G) Plotter
A plotter is used to create high-quality visuals on paper. Plotters were used in applications
such as computer-aided design, though they have generally been replaced with wide-format
conventional printers. A plotter gives a hard copy of the output. It draws pictures on a paper
using a pen. It can be used to create presentation-charts, graphics, tables and high quality
technical drawings. There are two types of plotter.

Drum Plotter: The paper is placed over the drum that rotates back and forth. A carriage
holding one or more pens is mounted horizontally across the drum. The carriage with the
pens moves horizontally over the paper. Each pen could be filled with different colours. This
plotter has the ability to produce colour pictures.

Flat Bed Plotter: In flat bed plotter, the paper does not move. The carriage holding the pens
should provide all motions. Inkjet plotters can also produce large drawings with different
colours.
Lecture Note Two

Process

A process is a program that is running on your computer. This can be anything from a small
background task, such as a spell-checker or system events handler to a full-blown application
like Internet Explorer or Microsoft Word. It could also be referred to as a set of instructions
currently being processed by the computer processor. For example, in Windows you can see
each of the processes running by opening the Processes tab in Task Manager. Windows
Processes are Windows Services and background programs you normally don't see running
on the computer. For example, a process may be a printer program that runs in the
background and monitors the ink and other printer settings while the computer is running.

A process is close in meaning to task , a term used in some operating systems. In UNIX and
some other operating systems, a process is started when a program is initiated (either by a
user entering a shell command or by another program). Like a task, a process is a running
program with which a particular set of data is associated so that the process can be kept track
of. An application that is being shared by multiple users will generally have one process at
some stage of execution for each user.

You may only have three programs running, but there may be twenty active processes. You
can view active processes in Windows by opening the Task Manager (press Ctrl-Alt-Delete
and click Task Manager). On a Mac, you can see active processes by opening Activity
Monitor (in the Applications→Utilities folder).

The term "process" can also be used as a verb, which means to perform a series of operations
on a set of data. For example, your computer's CPU processes information sent to it by
various programs.

All processes are composed of one or more threads. Processes and threads have one goal:
Getting a computer to do more than one thing at a time. To do that, the processor (or
processors) must switch smoothly among several tasks, which requires application programs
designed to share the computer's resources.

That is why programmers need to split what programs do into processes and threads.

Every program running on a computer uses at least one process. That process consists of an
address space (the part of the computer's memory where the program is running) and a flow
of control (a way to know which part of the program the processor is running at any instant).
In other words, a process is a place to work and a way to keep track of what a program is
doing. When several programs are running at the same time, each has its own address space
and flow of control.

To serve multiple users, a process may need to fork, or make a copy of itself, to create a child
process. Like its parent process, the child process has its own address space and flow of
control. Usually, however, when a parent process is terminated, all of the child processes it
has launched will also be killed automatically.
A multitasking operating system, such as Unix or Windows, switches among the running
processes, giving CPU time to each in turn. If a computer has multiple CPUs, each process
may be specifically assigned to one of the CPUs.

That's fine for simple programs. But a complex modern application, such as a word processor
or spreadsheet, may actually look to the operating system like several different programs,
with almost continuous switching and communication among them.

That's a problem, because it takes time to switch among processes. Modern CPUs include
memory management units (MMU) that prevent any process from overrunning another's
address space. Moving from one process to another—called context switching—means
reprogramming the MMU to point to a different address space plus saving and restoring
process information.

The operating system handles the details of the context switch, but it all takes time. And
because each process is isolated from the others, communicating between processes requires
special functions with names like signals and pipes. Like context switches, inter process
communications require processor time.

All that time adds up when many programs are running at once or when many users each
require several processes running at the same time. The more processes running, the greater
the percentage of time the CPU and operating system will spend doing expensive context
switches.

With enough processes to run, a server might eventually spend almost all of its time
switching among processes and never do any real work.

Threading Through

To avoid that problem, programmers can use threads. A thread is like a child process, except
all the threads associated with a given process share the same address space.

For example, when there are many users for the same program, a programmer can write the
application so that a new thread is created for each user.

Each thread has its own flow of control, but it shares the same address space and most data
with all other threads running in the same process. As far as each user can tell, the program
appears to be running just for him.

The advantage of threading is that it takes much less CPU time to switch among threads than
between processes, because there's no need to switch address spaces. In addition, because
they share address space, threads in a process can communicate more easily with one another.

If the program is running on a computer with multiple processors, a single-process program


can be run by only one CPU, while a threaded program can divide the threads up among all
available processors. So moving a threaded program to a multiprocessor server should make
it run faster.

The disadvantage is that programs using threads are harder to write and debug. Not all
programming libraries are designed for use with threads. And not all legacy applications
work well with threaded applications. Some programming tools also make it harder to design
and test threaded code.

Thread-related bugs can also be more difficult to find. Threads in a process can interfere with
one another's data. The operating system may limit how many threads can perform
operations, such as reading and writing data, at the same time. Scheduling different threads to
avoid conflicts can be a nightmare.

Still, as complex, shared code and multiprocessor servers become more common, threads will
continue to speed up multitasking.

is a replica of the parent process and shares some of its resources, but cannot exist if the
parent is terminated.

Memory Management
Memory management is the functionality of an operating system which handles or manages
primary memory and moves processes back and forth between main memory and disk during
execution. Memory management keeps track of each and every memory location, regardless
of either it is allocated to some process or it is free. It checks how much memory is to be
allocated to processes. It decides which process will get memory at what time. It tracks
whenever some memory gets freed or unallocated and correspondingly it updates the status.

Memory management is the process of controlling and coordinating computer memory,


assigning portions called blocks to various running programs to optimize overall system
performance. Memory management resides in hardware, in the OS (operating system), and in
programs and applications.

In hardware, memory management involves components that physically store data, such as
RAM (random access memory) chips, memory caches, and flash-based SSDs (solid-state
drives). In the OS, memory management involves the allocation (and constant reallocation) of
specific memory blocks to individual programs as user demands change. At the application
level, memory management ensures the availability of adequate memory for the objects and
data structures of each running program at all times. Application memory management
combines two related tasks, known as allocation and recycling.

When the program requests a block of memory, a part of the memory manager called the
allocator assigns that block to the program.

When a program no longer needs the data in previously allocated memory blocks, those
blocks become available for reassignment. This task can be done manually (by the
programmer) or automatically (by the memory manager).

In summary, memory management is the task carried out by the OS and hardware to
accommodate multiple processes in main memory

If only a few processes can be kept in main memory, then much of the time all processes will
be waiting for I/O and the CPU will be idle

Hence, memory needs to be allocated efficiently in order to pack as many processes into
memory as possible

In most schemes, the kernel occupies some fixed portion of main memory and the rest is
shared by multiple processes

Memory Management Requirements


Relocation
- programmer cannot know where the program will be placed in memory when it is executed
a process may be (often) relocated in main memory due to swapping
- swapping enables the OS to have a larger pool of ready-to-execute processes
- memory references in code (for both instructions and data) must be translated to actual
physical memory address

Protection
- processes should not be able to reference memory locations in another process without
permission
- impossible to check addresses at compile time in programs since the program could be
relocated
- address references must be checked at run time by hardware

Sharing
- must allow several processes to access a common portion of main memory without
compromising protection
- cooperating processes may need to share access to the same data structure
better to allow each process to access the same copy of the program rather than have their
own separate copy

Logical Organization
- users write programs in modules with different characteristics
- instruction modules are execute-only
- data modules are either read-only or read/write
- some modules are private others are public
- To effectively deal with user programs, the OS and hardware should support a basic form of
module to provide the required protection and sharing.

Physical Organization
secondary memory is the long term store for programs and data while main memory holds
program and data currently in use
moving information between these two levels of memory is a major concern of memory
management (OS)
it is highly inefficient to leave this responsibility to the application programmer.

Simple Memory Management

An executing process must be loaded entirely in main memory (if overlays are not used) the
following simple memory management techniques are not used in modern OS, they lay the
ground for a proper discussion of virtual memory.

fixed partitioning
dynamic partitioning
simple paging
simple segmentation

Fixed Partitioning
- Partition main memory into a set of non overlapping regions called partitions
Partitions can be of equal or unequal sizes
- any process whose size is less than or equal to a partition size can be loaded into the
partition
- if all partitions are occupied, the operating system can swap a process out of a partition
- a program may be too large to fit in a partition. The programmer must then design the
program with overlays
- when the module needed is not present the user program must load that module into the
program’s partition, overlaying whatever program or data are there
- Main memory use is inefficient. Any program, no matter how small, occupies an entire
partition. This is called internal fragmentation.
- Unequal-size partitions lessens these problems but they still remain...
- Equal-size partitions was used in early IBM’s OS/MFT (Multiprogramming with a Fixed
number of Tasks).

Placement Algorithm with Partitions


- Equal-size partitions
- If there is an available partition, a process can be loaded into that partition
- because all partitions are of equal size, it does not matter which partition is used
- If all partitions are occupied by blocked processes, choose one process to swap out to make
room for the new process
- Unequal-size partitions: use of multiple queues
- assign each process to the smallest partition within which it will fit
- A queue for each partition size
- tries to minimize internal fragmentation
- Problem: some queues will be empty if no processes within a size range is present
- Unequal-size partitions: use of a single queue
- When its time to load a process into main memory the smallest available partition that will
hold the process is selected
- increases the level of multiprogramming at the expense of internal fragmentation
Dynamic Partitioning
- Partitions are of variable length and number
- Each process is allocated exactly as much memory as it requires
- Eventually holes are formed in main memory. This is called external fragmentation
- Must use compaction to shift processes so they are contiguous and all free memory is in one
block

Used in IBM’s OS/MVT (Multiprogramming with a Variable number of Tasks)

Dynamic Partitioning: an example


- A hole of 64K is left after loading 3 processes: not enough room for another process
- Eventually each process is blocked. The OS swaps out process 2 to bring in process 4
another hole of 96K is created
- Eventually each process is blocked. The OS swaps out process 1 to bring in again process 2
and another hole of 96K is created...
- Compaction would produce a single hole of 256K

Placement Algorithm
- Used to decide which free block to allocate to a process
- Goal: to reduce usage of compaction (time consuming)
- Possible algorithms:
- Best-fit: choose smallest hole
- First-fit: choose first hole from beginning
- Next-fit: choose first hole from last placement

Placement Algorithm: comments


-Next-fit often leads to allocation of the largest block at the end of memory
-First-fit favors allocation near the beginning: tends to create less fragmentation then Next-fit
-Best-fit searches for smallest block: the fragment left behind is small as possible
-main memory quickly forms holes too small to hold any process: compaction generally
needs to be done more often.
Replacement Algorithm
- When all processes in main memory are blocked, the OS must choose which process to
replace
- A process must be swapped out (to a Blocked-Suspend state) and be replaced by a new
process or a process from the Ready-Suspend queue
- We will discuss later such algorithms for memory management schemes using virtual
Memory.

File System
In a computer, a file system -- sometimes written filesystem -- is the way in which files are
named and where they are placed logically for storage and retrieval. Without a file system,
stored information wouldn't be isolated into individual files and would be difficult to identify
and retrieve. Digital file systems and files are named for and modelled after paper-based
filing systems using the same logic-based method of storing and retrieving documents.

File systems can differ between operating systems (OS), such as Microsoft Windows, macOS
and Linux-based systems. Some file systems are designed for specific applications. Major
types of file systems include distributed file systems, disk-based file systems and special
purpose file systems.

How file systems work


A file system stores and organizes data and can be thought of as a type of index for all the
data contained in a storage device. These devices can include hard drives, optical drives and
flash drives.

File systems specify conventions for naming files, including the maximum number of
characters in a name, which characters can be used and, in some systems, how long the file
name suffix can be. In many file systems, file names are not case sensitive.

Along with the file itself, file systems contain information such as the size of the file, as well
as its attributes, location and hierarchy in the directory in the metadata. Metadata can also
identify free blocks of available storage on the drive and how much space is available.

A file system also includes a format to specify the path to a file through the structure of
directories. A file is placed in a directory -- or a folder in Windows OS -- or subdirectory at
the desired place in the tree structure. PC and mobile OSes have file systems in which files
are placed somewhere in a hierarchical tree structure.

Before files and directories are created on the storage medium, partitions should be put into
place. A partition is a region of the hard disk or other storage that the OS manages separately.
One file system is contained in the primary partition, and some OSes allow for multiple
partitions on one disk. In this situation, if one file system gets corrupted, the data in a
different partition will be safe.

File systems and the role of metadata


File systems use metadata to store and retrieve files. Examples of metadata tags include:
1. Date created
2. Date modified
3. Last date of access
4. Last backup
5. User ID of the file creator
6. Access permissions
7. File size

Metadata is stored separately from the contents of the file, with many file systems storing the
file names in separate directory entries. Some metadata may be kept in the directory, whereas
other metadata may be kept in a structure called an inode.

In Unix-like operating systems, an inode can store metadata unrelated to the content of the
file itself. The inode indexes information by number, which can be used to access the location
of the file and then the file itself.

An example of a file system that capitalizes on metadata is OS X, the OS used by Apple. It


allows for a number of optimization features, including file names that can stretch to 255
characters.

File system access


File systems can also restrict read and write access to a particular group of users. Passwords
are the easiest way to do this. Along with controlling who can modify or read files, restricting
access can ensure that data modification is controlled and limited.

File permissions such as access or capability control lists can also be used to moderate file
system access. These types of mechanisms are useful to prevent access by regular users, but
not as effective against outside intruders.

Encrypting files can also prevent user access, but it is focused more on protecting systems
from outside attacks. An encryption key can be applied to unencrypted text to encrypt it, or
the key can be used to decrypt encrypted text. Only users with the key can access the file.
With encryption, the file system does not need to know the encryption key to manage the data
effectively.

Types of file systems


There are a number of types of file systems, all with different logical structures and
properties, such as speed and size. The type of file system can differ by OS and the needs of
that OS. The three most common PC operating systems are Microsoft Windows, Mac OS X
and Linux. Mobile OSes include Apple iOS and Google Android.

Major file systems include the following:

File allocation table (FAT): This is supported by the Microsoft Windows OS. FAT is
considered simple and reliable, and it is modeled after legacy file systems. FAT was designed
in 1977 for floppy disks, but was later adapted for hard disks. While efficient and compatible
with most current OSes, FAT cannot match the performance and scalability of more modern
file systems.
Global file system (GFS): This is a file system for the Linux OS, and it is a shared disk file
system. GFS offers direct access to shared block storage and can be used as a local file
system.

GFS2: This is an updated version with features not included in the original GFS, such as an
updated metadata system. Under the terms of the GNU General Public License, both the GFS
and GFS2 file systems are available as free software.

Hierarchical file system (HFS): This was developed for use with Mac operating systems.
HFS can also be referred to as Mac OS Standard, and it was succeeded by Mac OS Extended.
Originally introduced in 1985 for floppy and hard disks, HFS replaced the original Macintosh
file system. It can also be used on CD-ROMs.

The NT file system (New Technology File System (NTFS)): This is the default file system
for Windows products from Windows NT 3.1 OS onward. Improvements from the previous
FAT file system include better metadata support, performance and use of disk space. NTFS is
also supported in the Linux OS through a free, open-source NTFS driver. Mac OSes have
read-only support for NTFS.

Universal Disk Format (UDF): This is a vendor-neutral file system used on optical media
and DVDs. UDF replaces the ISO 9660 file system and is the official file system for DVD
video and audio as chosen by the DVD Forum.

File system vs. DBMS


Like a file system, a database management system (DBMS) efficiently stores data that can be
updated and retrieved. The two are not interchangeable, however. While a file system stores
unstructured, often unrelated files, a DBMS is used to store and manage structured, related
data.

A DBMS creates and defines the restraints for a database. A file system allows access to
single files at a time and addresses each file individually. Because of this, functions such as
redundancy are performed on an individual level, not by the file system itself. This makes a
file system a much less consistent form of data storage than a DBMS, which maintains one
repository of data that is defined once.

The centralized structure of a DBMS allows for easier file sharing than a file system and
prevents anomalies that can occur when separate changes are made to files in a file system.

There are methods to protect files in a file system, but for heavy-duty security, a DBMS is the
way to go. Security in a file system is determined by the OS, and it can be difficult to
maintain over time as files are accessed and authorization is granted to users.

A DBMS keeps security constraints high, relying on password protection, encryption and
limited authorization. More security does result in more obstacles when retrieving data, so in
terms of general, simple-to-use file storage and retrieval, a file system may be preferred.

File systems definition evolves


While previously referring to physical, paper files, the term file system was used to refer to
digital files as early as 1961. By 1964, it had entered general use to refer to computerized file
systems.
Computers use particular kinds of file systems (sometimes abbreviated FS) to store and
organize data on media, such as a hard drive, the CDs, DVDs, and BDs in an optical drive or
on a flash drive.

A file system can be thought of as an index or database containing the physical location of
every piece of data on the hard drive or another storage device. The data is usually organized
in folders called directories, which can contain other folders and files.

Any place that a computer or other electronic device stores data is employing the use of some
type of file system. This includes your Windows computer, your Mac, your smartphone, your
bank's ATM... even the computer in your car!

Windows File Systems


The Microsoft Windows operating systems have always supported, and still do support,
various versions of the FAT (File Allocation Table) file system.
In addition to FAT, all Microsoft Windows operating systems since Windows NT support a
newer file system called NTFS (New Technology File System).
All modern versions of Windows also support exFAT, a file system designed for flash drives.
A file system is a setup on a drive during a format.

Files on a storage device are kept in what are called sectors. Sectors marked as unused can be
utilized to store data, which is typically done in groups of sectors called blocks. It's the file
system that identifies the size and position of the files as well as which sectors are ready to be
used.

Tip: Over time, due to the way the file system stores data, writing to and deleting from a
storage device causes fragmentation because of the gaps that inevitably occur between
different parts of a file. A free defrag utility can help fix that.

Without a structure for organizing files, it not only would be next to impossible to remove
installed programs and retrieve specific files, but no two files could exist with the same name
because everything might be in the same folder (which is one reason folders are so useful).

Note: What I mean by files with the same name is like an image, for example. The file
IMG123.jpg can exist in hundreds of folders because each folder is used to separate the JPG
file, so there isn't a conflict. However, files can not contain the same name if they're in the
same directory.

A file system doesn't just store the files but also information about them, like the sector block
size, fragment information, file size, attributes, file name, file location, and directory
hierarchy.

Some operating systems other than Windows also take advantage of FAT and NTFS but
many different kinds of file systems exist, like HFS+ used in Apple product like iOS and
macOS. Wikipedia has a comprehensive list of file systems if you're more interested in the
topic.
Sometimes, the term "file system" is used in the context of partitions. For example, saying
"there are two file systems on my hard drive" doesn't mean that the drive is split between
NTFS and FAT, but that there are two separate partitions that are using the file system.

Most applications you come into contact with require a file system in order to work, so every
partition should have one. Also, programs are file system-dependant, meaning you can't use a
program on Windows if it was built for use in macOS.

System Calls
In computing, a system call is the programmatic way in which a computer program requests a
service from the kernel of the operating system it is executed on. A system call is a way for
programs to interact with the operating system. System calls are used for hardware services,
to create or execute a process, and for communicating with kernel services, including
application and process scheduling.

A computer program makes a system call when it makes a request to the operating system’s
kernel. System call provides the services of the operating system to the user programs via
Application Program Interface (API). It provides an interface between a process and
operating system to allow user-level processes to request services of the operating system.
System calls are the only entry points into the kernel system. All programs needing resources
must use system calls. System calls provide an interface between user programs and
operating system. It is a programmatic way in which a computer program requests a service
from the kernel of the operating system.

When a program is executing in user mode, it is not in privileged mode. So whenever it needs
any hardware resource like ram or printer, it needs to make a call to the kernel and this is
known as system call.

Some of the services provided by System Calls include:


1. Process creation and management
2. Main memory management
3. File Access, Directory and File system management
4. Device handling(I/O)
5. Protection
6. Networking, etc.

Types of System Calls: There are 5 different categories of system calls –


1. Process control: end, abort, create, terminate, allocate and free memory.
2. File management: create, open, close, delete, read file etc.
3. Device management
4. Information maintenance
5. Communication

When a program is executing in kernel mode, it is executing in privileged mode. So it can


access any hardware resource. So when a program needs to access any resource while it is
running in user mode it makes a System Call to the kernel then a context switch occurs which
takes the program from user mode to kernel mode. After the resource is accessed one more
context switch occurs which takes back the program’s execution to user mode.
Now you may wonder why all programs aren’t occurring in kernel mode so we can skip the
context switching. This is because if a program crashes in kernel mode entire system will be
halted. So most programs are executed in user mode because if it crashes there, entire system
won’t be affected. If we want to write a program to copy the content of one file into another
then, first of all this program will need the names of these files. User will give these names by
either typing them in the console or selecting them by using GUI. So our program will need
to make system calls to the kernel to enable it to access the input and output devices.

Kernel Mode
 When CPU is in kernel mode, the code being executed can access any memory address
and any hardware resource.
 Hence kernel mode is a very privileged and powerful mode.
 If a program crashes in kernel mode, the entire system will be halted.

User Mode
 When CPU is in user mode, the programs don't have direct access to memory and
hardware resources.
 In user mode, if any program crashes, only that particular program is halted.
 That means the system will be in a safe state even if a program in user mode crashes.
 Hence, most programs in an OS run in user mode.

Also our program will need to display certain message if the program is successfully
completed or even if it stops and is aborted. All these tasks require System calls.

Types of System Calls

There are 5 different categories of system calls: process control, file manipulation, device
manipulation, information maintenance and communication.

1. Process Control
A running program needs to be able to stop execution either normally or abnormally. When
execution is stopped abnormally, often a dump of memory is taken and can be examined with
a debugger.
2. File Management
Some common system calls are create, delete, read, write, reposition, or close. Also, there is
a need to determine the file attributes – get and set file attribute. Many times the OS provides
an API to make these system calls.

3. Device Manipulation
Process usually require several resources to execute, if these resources are available, they will
be granted and control returned to the user process. These resources are also thought of as
devices. Some are physical, such as a video card, and others are abstract, such as a file.
User programs request the device, and when finished they release the device. Similar to files,
we can read, write, and reposition the device.
4. Information Management
Some system calls exist purely for transferring information between the user program and the
operating system. An example of this is time, or date.
The OS also keeps information about all its processes and provides system calls to report this
information.
5. Communication
There are two models of interprocess communication, the message-passing model and the
shared memory model.
 Message-passing uses a common mailbox to pass messages between processes.
 Shared memory use certain system calls to create and gain access to create and gain
access to regions of memory owned by other processes. The two processes exchange
information by reading and writing in the shared data.

Virtual Memory
Virtual Memory is a storage allocation scheme in which secondary memory can be addressed
as though it were part of main memory. The addresses a program may use to reference
memory are distinguished from the addresses the memory system uses to identify physical
storage sites, and program generated addresses are translated automatically to the
corresponding machine addresses. The size of virtual storage is limited by the addressing
scheme of the computer system and amount of secondary memory is available not by the
actual number of the main storage locations.

It is a technique that is implemented using both hardware and software. It maps memory
addresses used by a program, called virtual addresses, into physical addresses in computer
memory.

1. All memory references within a process are logical addresses that are dynamically
translated into physical addresses at run time. This means that a process can be swapped
in and out of main memory such that it occupies different places in main memory at
different times during the course of execution.
2. A process may be broken into number of pieces and these pieces need not be
continuously located in the main memory during execution. The combination of dynamic
run-time address translation and use of page or segment table permits this.

If these characteristics are present then, it is not necessary that all the pages or segments are
present in the main memory during execution. This means that the required pages need to be
loaded into memory whenever required. Virtual memory is implemented using Demand Paging or
Demand Segmentation.

A computer can address more memory than the amount physically installed on the system.
This extra memory is actually called virtual memory and it is a section of a hard disk that's
set up to emulate the computer's RAM.

The main visible advantage of this scheme is that programs can be larger than physical
memory. Virtual memory serves two purposes. First, it allows us to extend the use of physical
memory by using disk. Second, it allows us to have memory protection, because each virtual
address is translated to a physical address.

Following are the situations, when entire program is not required to be loaded fully in main
memory.
- User written error handling routines are used only when an error occurr in the data or
computation.
- Certain options and features of a program may be used rarely.
- Many tables are assigned a fixed amount of address space even though only a small amount
of the table is actually used.
- The ability to execute a program that is only partially in memory would counter many
benefits.
- Less number of I/O would be needed to load or swap each user program into memory.
- A program would no longer be constrained by the amount of physical memory that is
available.
- Each user program could take less physical memory, more programs could be run the same
time, with a corresponding increase in CPU utilization and throughput.

Modern microprocessors intended for general-purpose use, a memory management unit, or


MMU, is built into the hardware. The MMU's job is to translate virtual addresses into
physical addresses.

Advantages and Disadvantages of using Virtual Memory

Among the primary benefits of virtual memory is its ability to handle twice as many
addresses as main memory. It uses software to consume more memory by using the HDD as
temporary storage while memory management units translate virtual memory addresses to
physical addresses via the central processing unit. Programs use virtual addresses to store
instructions and data; when a program is executed, the virtual addresses are converted into
actual memory addresses.

Other advantages of virtual memory are that it frees applications from managing shared
memory and saves users from adding more memory modules when RAM space runs out.

However, the use of virtual memory has its tradeoffs, particularly with speed. It's generally
better to have as much physical memory as possible so programs work directly from RAM or
physical memory. The use of virtual memory slows a computer because data must be mapped
between virtual and physical memory, which requires extra hardware support for address
translations.

In a virtualized computing environment, administrators can use virtual memory management


techniques to allocate additional memory to a virtual machine (VM) that has run out of
resources. Such virtualization management tactics can improve VM performance and
management flexibility.
Shell Programs

Being a Linux user means you play around with the command-line. Like it or not, there are
just some things that are done much more easily via this interface than by pointing and
clicking. The more you use and learn the command-line, the more you see its potential. Well,
the command-line itself is a program: the shell. Most Linux users today use Bash, and this is
what you’re really entering commands into.

Now, some of you who used Windows before using Linux may remember batch files. These
were little text files that you could fill with commands to execute and Windows would run
them in turn. It was a clever and neat way to get some things done, like run games in your
high school computer lab when you couldn’t open system folders or create shortcuts. Batch
files in Windows, while useful, are a cheap imitation of shell scripts.

A “shell program” is the user interface to the computer system for the Linux OS. The
interface accepts commands from the user and translate into a language that the operating
system (Linux kernel) can understand. Even if you are using one of the graphical interface
designed for some windows system, you might still need to type commends at the shell
prompt to start or stop a program. It is a skeleton of a program that can be developed for
particular applications by the user. It is also program called a terminal emulator. That is, a
program that opens a window and lets you interact with the shell. There are a bunch of
different terminal emulators you can use. Most Linux distributions supply several, such as:
gnome-terminal, konsole, xterm, rxvt, kvt, nxterm, and eterm.

Simply put, the shell is a program (sometimes called a shell script) that takes commands from
the keyboard and gives them to the operating system to perform. In the old days, it was the
only user interface available on a Unix-like system such as Linux. Nowadays, we have
graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such as the
shell.

Shell scripts allow us to program commands in chains and have the system execute them as a
scripted event, just like batch files. They also allow for far more useful functions, such as
command substitution. You can invoke a command, like date, and use it’s output as part of a
file-naming scheme. You can automate backups and each copied file can have the current
date appended to the end of its name. Scripts aren’t just invocations of commands, either.
They’re programs in their own right. Scripting allows you to use programming functions –
such as ‘for’ loops, if/then/else statements, and so forth – directly within your operating
system’s interface. And, you don’t have to learn another language because you’re using what
you already know: the command-line.

On most Linux systems a program called bash (which stands for Bourne Again SHell, an
enhanced version of the original Unix shell program, sh, written by Steve Bourne) acts as the
shell program. Besides bash, there are other shell programs that can be installed in a Linux
system. These include: ksh, tcsh and zsh.

Shell programming is a basic skill that every UNIX System Administrator should have. The
Systems Administrator must be able to read and write shell programs because:

- there are many tasks that can and should be quickly automated by using shell programs,
- many software products come with install scripts that have to be modified for your system
before they will work.

Shell programs are interpreted and not compiled programs. This means when you run a shell
program a child shell is started. This child shell reads each line in the shell program and
carries out the command on that line. When it has read all the commands the child shell
finishes.

-- Support for programming


To be truly useful a programming language must provide the following services
 comments,
 variables,
 conditional commands, and
 repeated action commands.

These extra services are provided by the shell. Different shells use different syntax for these
services. This means that a shell program written for the Bourne shell cannot be run by the C
shell (though it can be run by the bash shell.)

-- Creating a shell program


To create a shell program you need to complete the following steps:
 create a text file to hold the shell program
 decide which shell you will use
 add the required commands to the file
 save the file
 change the permissions on the file so it is executable
 run the shell program

-- Which shell?
The first step is to decide which shell to use. You decision here will control the syntax of the
shell commands you use. You may decide to use the Bourne shell as the standard Linux shell
bash supports the Bourne shell syntax.
Once you've made that decision the first line of your shell program should indicate which
shell should be used to interpret your shell program. This is done by having the first line of
the shell program have the following: #!path_to_shell.
For example, suppose that on my machine I want to use the Bourne shell (sh). The full path to
the sh program on my system is /bin/sh (this will be the same on virtually all Unix systems).
So the first line of every shell program I write will be:
#!/bin/sh
If you do not specify which shell should be used your current shell will be used. If the first
line of your shell script is blank, most versions of Unix will use the Bourne shell.
-- Add the commands
The next step is to add the commands you wish the shell program to perform. The commands
can be any standard UNIX or shell command. Of course any shell commands you use must
be supported by the shell that will interpret your shell program.
-- Make the file executable
Once you've added all the commands you can then save the file. In order to execute a shell
program both the read and execute permissions must be set. By default when you save a text
file the execute file permission will not be set. You will have to set this manually For
example i want to find out the number of files and directories in the current directory so I
have created the following shell program called files
#!/bin/sh
ls | wc -w
Create the files shell program and execute it.

-- Running a shell program


By default a shell reads commands from standard input. This is the mode of operation you are
use to. It is also possible for the shell to read commands from a file. For example
unx1:~$ sh files
will start a new shell but rather than reading commands from standard input the shell will
read its commands from the file called files.

-- Executing a shell program


The other method to execute a shell program is to enter its name in the same way as you
would execute any other command. For example to run the files shell script you would
simply type

unx1:~$ files
--- Shell program names
A common mistake for many new shell programmers is to create a shell program called test
and then wonder why it doesn't work as expected.
Execute the following command:
/usr/bin/which test
Do you see the problem? There is already a command called test and it is the command that is
usually found first when you try to run a command called test. Use which when you have a
question as to whether you are running the correct shell program.

-- File permissions
Anyone who wishes to execute the shell programs should have at least read permission on the
shell program's file. They must have read permission so that a shell they run can read the file
in order to interpret the commands.
If they wish to execute the shell program simply by typing its name they must also have
execute permission. It is possible to execute a shell program using the shell filename
format without execute permission.

Any good programmer can tell you the reasons why comments are important. It is especially
true for UNIX shell programs which can be truly mystifying, even to the expert.
When you are writing shell programs as a Systems Administrator comments are doubly
important. Chances are you won't be at the site forever. At some stage another Systems
Administrator is going to come along and have to decipher what your shell programs are
doing.
Shell programs use the # character to signify comments. Anything after a # character until the
end of the line is considered a comment and is ignored by the shell.

-- Comment style
You should choose a standard commenting style for all the shell programs you will write. On
an established site there may well already exist such a style.
The following is a trivial example. The benefit from plentiful comments are not obvious until
you start writing large, complex programs.
#!/bin/sh
# FILENAME: test_shell
# AUTHOR: Joe Buffalo
# PURPOSE: Demonstration of comment style
# HISTORY: 1 March, 1998 Created
# 5 March, 1998 Modified to show mods

ls | more
-- Passing parameters
As you've seen, most UNIX commands will accept a list of parameters. The shell provides a
number of pre-defined shell variables that are used to pass parameters to a shell script.
Shell programming is a skill that every UNIX Systems Administrator should have. A shell
program is simply a text file that contains shell and UNIX commands. Each shell supplies
support for programming by supplying

 comments, #
 variables
 conditional commands if case
 repeated action commands for while until
 and functions.

Different shells will use a different syntax to supply this programming support. This
treatment concentrates on the Bourne shell syntax.
Every process returns and exit status when it finishes. An exit status of 0 indicates success.
An exit status of any other value indicates failure. The exit command can be used set the exit
status of a shell or a shell program.

The Workings of a Shell Program


The Shell Program is the Interpreter through which you communicate with the operating
system. When the command is typed at the shell prompt, it is interpreted and passed to the
Linux kernel. The kernel, in turn, tells the computer what to do. The shell found in the most
Linux distribution install by default is the base shell.

Lecture Note Three


Thread

A thread is a flow of execution through the process code, with its own program counter that
keeps track of which instruction to execute next, system registers which hold its current
working variables, and a stack which contains the execution history. A thread shares with its
peer threads few information like code segment, data segment and open files. When one
thread alters a code segment memory item, all other threads see that.
A thread is also called a lightweight process. Threads provide a way to improve application
performance through parallelism. 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 figure shows the working of a single-threaded and a multithreaded process.

Difference between Process and Thread


Process Thread
Process is heavy weight or resource Thread is light weight, taking lesser resources
1
intensive. than a process.
Process switching needs interaction with Thread switching does not need to interct with
2
operating system. operating system.
In multiple processing environments,
All threads can share same set of open files,
3 each process executes the same code but
child processes.
has its own memory and file resources.
If one process is blocked, then no other
While one thread is blocked and waiting, a
4 process can execute until the first process
second thread in the same task can run.
is unblocked.
Multiple processes without using threads Multiple threaded processes use fewer
5
use more resources. resources.
In multiple processes each process One thread can read, write or change another
6
operates independently of the others. thread's data.
Advantages of Thread
-- Threads minimize the context switching time.
-- Use of threads provides concurrency within a process.
-- Efficient communication.
-- It is more economical to create and context switch threads.
-- Threads allow utilization of multiprocessor architectures to a greater scale and efficiency.

Types of Thread
Threads are implemented in following two ways −
-- User Level Threads − User managed threads.
-- Kernel Level Threads − Operating System managed threads acting on kernel, an operating
system core.

User Level Threads


In this case, the thread management kernel is not aware of the existence of threads. The
thread library contains code for creating and destroying threads, for passing message and data
between threads, for scheduling thread execution and for saving and restoring thread
contexts. The application starts with a single thread.

Advantages
-- Thread switching does not require Kernel mode privileges.
-- User level thread can run on any operating system.
-- Scheduling can be application specific in the user level thread.
-- User level threads are fast to create and manage.

Disadvantages
-- In a typical operating system, most system calls are blocking.
-- Multithreaded application cannot take advantage of multiprocessing.
Kernel Level Threads
In this case, thread management is done by the Kernel. There is no thread management code
in the application area. Kernel threads are supported directly by the operating system. Any
application can be programmed to be multithreaded. All of the threads within an application
are supported within a single process.
The Kernel maintains context information for the process as a whole and for individuals
threads within the process. Scheduling by the Kernel is done on a thread basis. The Kernel
performs thread creation, scheduling and management in Kernel space. Kernel threads are
generally slower to create and manage than the user threads.

Advantages
-- Kernel can simultaneously schedule multiple threads from the same process on multiple
processes.
-- If one thread in a process is blocked, the Kernel can schedule another thread of the same
process.
-- Kernel routines themselves can be multithreaded.

Disadvantages
-- Kernel threads are generally slower to create and manage than the user threads.
-- Transfer of control from one thread to another within the same process requires a mode
switch to the Kernel.

Multithreading Models
Some operating system provide a combined user level thread and Kernel level thread facility.
Solaris is a good example of this combined approach. In a combined system, multiple threads
within the same application can run in parallel on multiple processors and a blocking system
call need not block the entire process. Multithreading models are three types

-- Many to many relationship.


-- Many to one relationship.
-- One to one relationship.

Many to Many Model


The many-to-many model multiplexes any number of user threads onto an equal or smaller
number of kernel threads.
The following diagram shows the many-to-many threading model where 6 user level threads
are multiplexing with 6 kernel level threads. In this model, developers can create as many
user threads as necessary and the corresponding Kernel threads can run in parallel on a
multiprocessor machine. This model provides the best accuracy on concurrency and when a
thread performs a blocking system call, the kernel can schedule another thread for execution.
Many to One Model
Many-to-one model maps many user level threads to one Kernel-level thread. Thread
management is done in user space by the thread library. When thread makes a blocking
system call, the entire process will be blocked. Only one thread can access the Kernel at a
time, so multiple threads are unable to run in parallel on multiprocessors.
If the user-level thread libraries are implemented in the operating system in such a way that
the system does not support them, then the Kernel threads use the many-to-one relationship
modes.

One to One Model


There is one-to-one relationship of user-level thread to the kernel-level thread. This model
provides more concurrency than the many-to-one model. It also allows another thread to run
when a thread makes a blocking system call. It supports multiple threads to execute in
parallel on microprocessors.
Disadvantage of this model is that creating user thread requires the corresponding Kernel
thread. OS/2, windows NT and windows 2000 use one to one relationship model.

Difference between User-Level & Kernel-Level Thread

User-Level Threads Kernel-Level Thread


User-level threads are faster to create and Kernel-level threads are slower to create
1
manage. and manage.
Implementation is by a thread library at the Operating system supports creation of
2
user level. Kernel threads.
User-level thread is generic and can run on Kernel-level thread is specific to the
3
any operating system. operating system.
Multi-threaded applications cannot take Kernel routines themselves can be
4
advantage of multiprocessing. multithreaded.

Inter-process Communication

Inter Process Communication (IPC) refers to a mechanism, where the operating systems
allow various processes to communicate with each other. This involves synchronizing their
actions and managing shared data.
Interprocess communication (IPC) is a set of programming interfaces that allows a
programmer to coordinate activities among different program processes that can run
concurrently in an operating system. This allows a program to handle many user requests at
the same time. Since even a single user request may result in multiple processes running in
the operating system on the user's behalf, the processes need to communicate with each other.
The IPC interfaces make this possible. The Windows operating system provides mechanisms
for facilitating communications and data sharing between applications. Collectively, the
activities enabled by these mechanisms are called inter-process communications (IPC). Some
forms of IPC facilitate the division of labour among several specialized processes. Other
forms of IPC facilitate the division of labour among computers on a network. Each IPC
method has its own advantages and limitations so it is not unusual for a single program to use
all of the IPC methods. IPC methods include pipes and named pipes; message
queueing;semaphores; shared memory; and sockets.

Typically, applications can use IPC categorized as clients or servers. A client is an


application or a process that requests a service from some other application or process. A
server is an application or a process that responds to a client request. Many applications act
as both a client and a server, depending on the situation. For example, a word processing
application might act as a client in requesting a summary table of manufacturing costs from a
spreadsheet application acting as a server. The spreadsheet application, in turn, might act as a
client in requesting the latest inventory levels from an automated inventory control
application.

A process can be of two type:


-- Independent process.
-- Co-operating process.
An independent process is not affected by the execution of other processes while a co-
operating process can be affected by other executing processes. Though one can think that
those processes, which are running independently, will execute very efficiently but in
practical, there are many situations when co-operative nature can be utilised for increasing
computational speed, convenience and modularity. Inter process communication (IPC) is a
mechanism which allows processes to communicate with each other and synchronize their
actions. The communication between these processes can be seen as a method of co-operation
between them. Processes can communicate with each other using these two ways:

i Shared Memory
ii Message passing

An operating system can implement both method of communication. First, we will discuss
the shared memory method of communication and then message passing. Communication
between processes using shared memory requires processes to share some variable and it
completely depends on how programmer will implement it. One way of communication using
shared memory can be imagined like this: Suppose process1 and process2 are executing
simultaneously and they share some resources or use some information from other process,
process1 generate information about certain computations or resources being used and keeps
it as a record in shared memory. When process2 need to use the shared information, it will
check in the record stored in shared memory and take note of the information generated by
process1 and act accordingly. Processes can use shared memory for extracting information as
a record from other process as well as for delivering any specific information to other
process.

Deadlock

Deadlock in operating system is one of the most important concepts you must know. It is the
basic topic in the operating system that every computer software student be should aware of,
Deadlock is a condition that occurs when multiple processes wait for each other to free up
resources and as a result, all processes remains halted. In other words, deadlocks are the set
of processes which are blocked. In this, each process is holding a resource and waiting to
acquire a resource held by another process.

The deadlock in operating system seems to be a common issue in multiprocessor systems,


parallel and distributed computing setups. In a multiprogramming system, numerous
processes get competed for a finite number of resources. Any process requests resources, and
as the resources aren't available at that time, the process goes into a waiting state. At times, a
waiting process is not at all able again to change its state as other waiting processes detain the
resources it has requested. That condition is termed as deadlock.

Let us understand the concept of deadlock with the help of an example. Suppose there are
two processes Pros 1 and Pros 2. Both processes Pros 1 and Pros 2 are running in a computer
system. Process Pros 1 request for a resource, such as a printer that is being utilized by the
process Pros 2. As a result, the process Pros 1 has to wait until the time Pros 2 complete its
processing and free the resource. At the same time Pros 2 process request for a resource, such
as shared data that has been locked by the process Pros 1. Thus, both the processes Pros 1 and
Pros 2 ends up waiting for each other to free up the required resources. This special situation
is known as deadlock of the operating system.

The following figure shows the occurrence of deadlock:

The following are the various reasons of arise of deadlock in an operating system:

1. Mutual Exclusion
In mutual exclusion, processes are not allowed to share resources with each other. In other
words, if one process has control over a resource, then that resource cannot be used by
another process until the first process releases the resource.

2. Hold and wait


In hold and wait, a process takes control of a resource and waits for some other resource or
activity to complete.

3. No Preemption
In this condition, a process is not allowed to force some other process to release the resource.
4. 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.

There are a number of methods through which the deadlock conditions can be avoided. Some
of which include:

1. Ignore deadlock
In this method, it is assumed that deadlock would never occur. There is a good chance that
deadlock may not occur in a computer system. For a long period of time. As a result, the
ignore deadlock method can be useful in many cases. But still, it is not a perfect solution to
remove deadlock in the operating system.

2. Detect and recover from deadlock


In this method, the deadlock is first detected by using some algorithms of allocation/request
graph. This graph is used to represent the allocations of various resources to different
processes. After a deadlock has been detected, a number of methods can be used to recover
from that deadlock. One way is preemption in which a resource held by one process is
provided to another process. The second way is to roll back in which operating system keeps
a record of the process state and makes a process roll back to its previous state. Thus,
eliminating the deadlock situation. The third way is to kill one or more processes to overcome
the deadlock situation.
3. Avoid deadlock
In this method, a process requesting a resource is allocated the resource only if there is no
possibility of deadlock occurrence.

Mutual Exclusion

A way of making sure that if one process is using a shared modifiable data, the other
processes will be excluded from doing the same thing.

When you go into a changing room at a department store, no one else can enter that room.
You can come out to show off your new outfits to friends in the hallway, but no one is
allowed in the room. Mutual exclusion is a key requirement when it comes to concurrency. In
a payroll example, it would mean that Process B would not be able to set salary until Process
A finishes with its calculation.
Mutual exclusion is a critical requirement for today's operating systems, and is part of
numerous resources. Files, Input/Output (I/O) devices, shared data systems etc., all benefit
from mutual exclusion.

Formally, while one process executes the shared variable, all other processes desiring to do so
at the same time moment should be kept waiting; when that process has finished executing
the shared variable, one of the processes waiting should be allowed to proceed. In this
fashion, each process executing the shared data (variables) excludes all others from doing so
simultaneously.
Note that mutual exclusion needs to be enforced only when processes access shared
modifiable data - when processes are performing operations that do not conflict with one
another they should be allowed to proceed concurrently.

Mutual Exclusion Conditions


If we could arrange matters such that no two processes were ever in their critical sections
simultaneously, we could avoid race conditions. We need four conditions to hold to have a
good solution for the critical section problem (mutual exclusion).
-- No two processes may at the same moment inside their critical sections.
-- No assumptions are made about relative speeds of processes or number of CPUs.
-- No process should outside its critical section should block other processes.
-- No process should wait arbitrary long to enter its critical section.

Semaphore
In programming, especially in Unix systems, semaphores are a technique for coordinating or
synchronizing activities in which multiple processes compete for the same operating system
resources. A semaphore is a value in a designated place in operating system (or kernel)
storage that each process can check and then change. Depending on the value that is found,
the process can use the resource or will find that it is already in use and must wait for some
period before trying again. Semaphores can be binary (0 or 1) or can have additional values.
Typically, a process using semaphores checks the value and then, if it using the resource,
changes the value to reflect this so that subsequent semaphore users will know to wait.

The diagram below will help you understand the process operation.

In step one the user types a command after the shell prompt and send it to the shell. The shell
first determine whether the command is one of its built or if it is an application program. If
the command is an application program, it must be located in one of the directories listed in
the shell’s search path.
If the command is found, the shell interprets the command (look in step 2) and send to the
kernel. The kernel then tells the shell (step 3) to lunch the application which it does as shown
in step 4. After the application is running the user communicates directly (step 5) while the
shell (step 6) maintain the necessary data flow between the application and kernel.

.Learning this easy and powerful programming method can help you save time, learn the
command-line better, and banish tedious file management tasks.
Lecture Note Four

Scheduling

A typical process involves both I/O time and CPU time. In a uniprogramming system like
MS-DOS, time spent waiting for I/O is wasted and CPU is free during this time. In
multiprogramming systems, one process can use CPU while another is waiting for I/O. This
is possible only with process scheduling.

Process scheduling is very important in multiprogramming and multitasking operating


system, where multiple processes execute simultaneously. Process scheduling ensures
maximum utilization of central processing unit (CPU) because a process is always running at
the specific instance of time. At first, the process that are to be executed are placed in a queue
called Job queue. The processes which are already placed in the main memory and are ready
for CPU allocation, are placed in a queue called Ready queue. If the process is waiting for
input / output, then that process is placed in the queue called Device queue.

CPU scheduling is a process which allows one process to use the CPU while the execution of
another process is on hold(in waiting state) due to unavailability of any resource like I/O etc,
thereby making full use of CPU. The aim of CPU scheduling is to make the system efficient,
fast and fair.

Whenever the CPU becomes idle, the operating system must select one of the processes in the
ready queue to be executed. The selection process is carried out by the short-term scheduler
(or CPU scheduler). The scheduler selects from among the processes in memory that are
ready to execute, and allocates the CPU to one of them.

Operating system scheduling is the process of controlling and prioritizing messages sent to a
processor. An internal operating system program, called the scheduler, performs this task.
The goal is maintaining a constant amount of work for the processor, eliminating highs and
lows in the workload and making sure each process is completed within a reasonable time
frame. While scheduling is important to all systems, it is especially important in a real-time
system.

Since nearly every operation on a computer has at least a small amount of processor time
involved, the processor can be a major source of slowdowns and bottlenecks. In order to
alleviate the strain on the processor, and make sure tasks are completed in a timely manner,
most operating systems use some form of task scheduling. The operating system scheduling
process varies based on the system, but they tend to fall within familiar categories.

In most circumstances, operating system scheduling is a way of making a computer function


more efficiently, but in a real-time operating system, it is vital to its purpose. A real-time
system needs to execute processes within a set time, and if these process lag, then their
purpose is lost. These important programs require very specific system scheduling in order to
make sure information and responses are where they need to be, when they need to be.

Consider a 2.4 GHz processor. It executes approximately 2,400 million instructions per
second (and this does not even count multi-core or hyperthreaded processors). It can run 24
billion instructions in the ten seconds it might take you to skim a web page before you click
on a link — or 1.2 billion instructions in the half second it might take you to hit the next key
as you’re typing. The big idea in increasing overall system throughput was the realization that
we could keep several programs in memory and switch the processor to run another process
when a process has to wait on an I/O operation. This is multiprogramming. The next big
idea was realizing that you could preempt a process and let another process run and do this
quickly enough to give the illusion that many processes are running at the same time. This is
multitasking.

An operating system uses a program scheduler to schedules the processes of computer


system. Scheduling is typically broken down into three parts: long-, mid- and short-term
scheduling. Not every operating system fully uses each type — midterm and long-term are
often combined — but they will use some combination of them. Each type of scheduling
provides a slightly different benefit to the system.

Schedulers are special system software which handle process scheduling in various ways.
Their main task is to select the jobs to be submitted into the system and to decide which
process to run. Schedulers are of three types:

1. Long term scheduler


2. Mid - term scheduler
3. Short term scheduler

1) Long Term Scheduler

It is also called a job scheduler Long-term scheduling revolves around admitting programs to
the scheduling process. When a new program initiates, the long-term scheduler determines if
there is enough space for the new entrant. If there isn’t, then the scheduler delays the
activation of the program until there is enough room.

It selects the process that are to be placed in ready queue. The long term scheduler basically
decides the priority in which processes must be placed in main memory. Processes of long
term scheduler are placed in the ready state because in this state the process is ready to
execute waiting for calls of execution from CPU which takes time that’s why this is known as
long term scheduler.

2) Mid – Term Scheduler


Medium-term scheduling is a part of swapping The midterm scheduler decides which
processes have been idle and which are active. It leaves the active processes alone and writes
idle ones to the hard drive. This frees up memory for other programs to come in through the
long-term scheduler. When the mid- and long-term schedulers are combined, instead of
delaying activation of a new process, the scheduler simply swaps it into storage.

It places the blocked and suspended processes in the secondary memory of a computer
system. The task of moving from main memory to secondary memory is called swapping
out.The task of moving back a swapped out process from secondary memory to main
memory is known as swapping in. The swapping of processes is performed to ensure the best
utilization of main memory.
3) Short Term Scheduler
It is also called as CPU scheduler. The short-term scheduler is the part that works directly
with the processor. This portion activates processes, sets priorities and oversees the
processor’s workload. The short-term scheduler is constantly trying to anticipate computer
needs to keep the processor running smoothly.

It decides the priority in which processes is in the ready queue are allocated the central
processing unit (CPU) time for their execution. The short term scheduler is also referred as
central processing unit (CPU) scheduler.

Comparison among Scheduler

S.N. Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler

It is a process swapping
1 It is a job scheduler It is a CPU scheduler
scheduler.
Speed is lesser than short Speed is fastest among Speed is in between both short
2
term scheduler other two and long term scheduler.
It provides lesser control
It controls the degree of It reduces the degree of
3 over degree of
multiprogramming multiprogramming.
multiprogramming
It is almost absent or
It is also minimal in time It is a part of Time sharing
4 minimal in time sharing
sharing system systems.
system
It selects processes from pool It can re-introduce the process
It selects those processes
5 and loads them into memory into memory and execution
which are ready to execute
for execution can be continued.

An operating system uses two types of scheduling processes execution, preemptive and non -
preemptive.

1. Preemptive process:
In preemptive scheduling policy, a low priority process has to be suspend its execution if high
priority process is waiting in the same queue for its execution.

2. Non - Preemptive process:


In non - preemptive scheduling policy, processes are executed in first come first serve basis,
which means the next process is executed only when currently running process finishes its
execution.

The OS maintains all PCBs in Process Scheduling Queues. The OS maintains a separate
queue for each of the process states and PCBs of all processes in the same execution state are
placed in the same queue. When the state of a process is changed, its PCB is unlinked from
its current queue and moved to its new state queue.

The Operating System maintains the following important process scheduling queues −

 Job queue − This queue keeps all the processes in the system.
 Ready queue − This queue keeps a set of all processes residing in main memory,
ready and waiting to execute. A new process is always put in this queue.
 Device queues − The processes which are blocked due to unavailability of an I/O
device constitute this queue.

Process Scheduling Queues

The process scheduling is the activity of the process manager that handles the removal of the
running process from the CPU and the selection of another process on the basis of a particular
strategy.

Process scheduling is an essential part of a Multiprogramming operating systems. Such


operating systems allow more than one process to be loaded into the executable memory at a
time and the loaded process shares the CPU using time multiplexing.

The OS can use different policies to manage each queue (FIFO, Round Robin, Priority, etc.).
The OS scheduler determines how to move processes between the ready and run queues
which can only have one entry per processor core on the system; in the above diagram, it has
been merged with the CPU.

 First-Come, First-Served (FCFS) Scheduling


 Shortest-Job-Next (SJN) Scheduling
 Priority Scheduling
 Shortest Remaining Time
 Round Robin(RR) Scheduling
 Multiple-Level Queues Scheduling
These algorithms are either non-preemptive or preemptive. Non-preemptive algorithms are
designed so that once a process enters the running state, it cannot be preempted until it
completes its allotted time, whereas the preemptive scheduling is based on priority where a
scheduler may preempt a low priority running process anytime when a high priority process
enters into a ready state.

Operating system performs the task of scheduling processes based on priorities using these
following algorithms:

1. First come first serve (FCFS)


In this scheduling algorithm the first process entered in queue is processed first. Jobs are
executed on first come, first serve basis. It is a non-preemptive, pre-emptive scheduling
algorithm. Easy to understand and implement. Its implementation is based on FIFO queue.
Poor in performance as average wait time is high.

2. Shortest job first (SJF)


In this scheduling algorithm the process which requires shortest CPU time to execute is
processed first.

3. Priority scheduling
In this scheduling algorithm the priority is assigned to all the processes and the process with
highest priority executed first. Priority assignment of processes is done on the basis of
internal factor such as CPU and memory requirements or external factor such as user’s
choice. The priority scheduling algorithm supports preemptive and non - preemptive
scheduling policy.

4. Round Robin (RR) scheduling


In this algorithm the process is allocated the CPU for the specific time period called time
slice, which is normally of 10 to 100 milliseconds. If the process completes its execution
within this time slice, then it is removed from the queue otherwise it has to wait for another
time slice.

Two-State Process Model

Two-state process model refers to running and non-running states which are described below

Running
When a new process is created, it enters into the system as in the running state.
Not Running
Processes that are not running are kept in queue, waiting for their turn to execute. Each entry
in the queue is a pointer to a particular process. Queue is implemented by using linked list.
Use of dispatcher is as follows. When a process is interrupted, that process is transferred in
the waiting queue. If the process has completed or aborted, the process is discarded. In either
case, the dispatcher then selects a process from the queue to execute.
Context Switch

A context switch is the mechanism to store and restore the state or context of a CPU in
Process Control block so that a process execution can be resumed from the same point at a
later time. Using this technique, a context switcher enables multiple processes to share a
single CPU. Context switching is an essential part of a multitasking operating system
features.

The concept of context switching applies to multiprogramming as well as to multitasking yet


at a different level of granularity. In the former, the “context” refers to that of a whole
process whereas in the latter the “context” may be that of a lighter thread. In fact, process
context switching involves switching the virtual memory address space: this includes
memory addresses, mappings, page tables, and kernel resources. On the other hand, thread
context switching is context switching from one thread to another in the same process (i.e.
there is no need of switching the virtual memory address space as the “switcher” and the
“switchee” threads share the same virtual address space). This requires switching processor
state (such as the program counter and register contents), which is generally very efficient.
Of course, switching from thread to thread across different processes is just like process
context switching.

When the scheduler switches the CPU from executing one process to execute another, the
state from the current running process is stored into the process control block. After this, the
state for the process to run next is loaded from its own PCB and used to set the PC, registers,

etc. At that point, the second process can start executing.

Context switches are computationally intensive since register and memory state must be
saved and restored. To avoid the amount of context switching time, some hardware systems
employ two or more sets of processor registers. When the process is switched, the following
information is stored for later use.

 Program Counter
 Scheduling information
 Base and limit register value
 Currently used register
 Changed State
 I/O State information
 Accounting information

Multi programming
A program in execution is called a "Process", "Job" or a "Task". The concurrent execution of
programs improves the utilization of system resources and enhances the system throughput as
compared to batch and serial processing. In this system, when a process requests some I/O to
allocate; meanwhile the CPU time is assigned to another ready process. So, here when a
process is switched to an I/O operation, the CPU is not set idle.

Multiprogramming is a rudimentary form of parallel processing in which several programs


are run at the same time on a uniprocessor. Since there is only one processor, there can be no
true simultaneous execution of different programs. Instead, the operating system executes
part of one program, then part of another, and so on. To the user it appears that all programs
are executing at the same time.

If the machine has the capability of causing an interrupt after a specified time interval, then
the operating system will execute each program for a given length of time, regain control, and
then execute another program for a given length of time, and so on. In the absence of this
mechanism, the operating system has no choice but to begin to execute a program with the
expectation, but not the certainty, that the program will eventually return control to the
operating system.

If the machine has the capability of protecting memory, then a bug in one program is less
likely to interfere with the execution of other programs. In a system without memory
protection, one program can change the contents of storage assigned to other programs or
even the storage assigned to the operating system. The resulting system crashes are not only
disruptive, they may be very difficult to debug since it may not be obvious which of several
programs is at fault.

A multiprogramming operating system is one that allows end-users to run more than one
program at a time. The development of such a system, the first type to allow this
functionality, was a major step in the development of sophisticated computers. The
technology works by allowing the central processing unit (CPU) of a computer to switch
between two or more running tasks when the CPU is idle.

Early computers were largely dedicated to executing one program — or, more accurately, one
task initiated by a program — at a time. Understanding the concept of tasks is key to
understanding how a multiprogramming operating system functions. A "task" is a small
sequence of commands that, when combined, comprises the execution of a running program.
For example, if the program is a calculator, one task of the program would be recording the
numbers being input by the end-user.

A multiprogramming operating system acts by analyzing the current CPU activity in the
computer. When the CPU is idle — when it is between tasks — it has the opportunity to use
that downtime to run tasks for another program. In this way, the functions of several
programs may be executed sequentially. For example, when the CPU is waiting for the end-
user to enter numbers to be calculated, instead of being entirely idle, it may run load the
components of a web page the user is accessing.

Multiprogramming is a common approach to resource management. The essential


components of a single-user operating system include a command processor, an input/ output
control system, a file system, and a transient area. A multiprogramming operating system
builds on this base, subdividing the transient area to hold several independent programs and
adding resource management routines to the operating system's basic functions.

To overcome the problem of underutilization of CPU and main memory, multiprogramming


was introduced. The multiprogramming is interleaved execution of multiple jobs by the same
computer.

In multiprogramming system, when one program is waiting for I/O transfer; there is another
program ready to utilize the CPU. So it is possible for several jobs to share the time of the
CPU. But it is important to note that multiprogramming is not defined to be the execution of
jobs at the same instance of time. Rather it does mean that there are a number of jobs
available to the CPU (placed in main memory) and a portion of one is executed then a
segment of another and so on. A simple process of multiprogramming is shown in figure

As shown in fig, at the particular situation, job' A' is not utilizing the CPU time because it is
busy in I/ 0 operations. Hence the CPU becomes busy to execute the job 'B'. Another job C is
waiting for the CPU for getting its execution time. So in this state the CPU will never be idle
and utilizes maximum of its time.

The main benefit of this functionality (multiprogramming) is that it can reduce wasted time in
the system's operations. As in a business, efficiency is the key to generating the most profit
from an enterprise. Using this type of operating system eliminates waste in the system by
ensuring that the computer's CPU is running at maximum capacity more of the time. This
results in a smoother computing experience from the end-user's point of view, as program
commands are constantly being executed in the background at all times, helping to speed
execution of programs.

The multiprogramming operating system has been largely supplanted by a new generation of
operating system known as multitasking operating systems. In a multitasking operating
system, the system does not have to wait for the completion of a task before moving to work
on an active program. Instead, it can interrupt a running program at any time in order to shift
its CPU resources to a different active program. This provides for a more dynamic approach
to handling concurrent programs.

When you approach operating system concepts there might be several confusing terms that
may look similar but in fact refer to different concepts. In a modern computing system, there
are usually several concurrent application processes which compete for (few) resources like,
for instance, the CPU. As we have already introduced, the Operating System (OS), amongst
other duties, is responsible for the effective and efficient allocation of those resources.
Generally speaking, the OS module which handles resource allocation is called scheduler. On
the basis of the type of OS to be realized, different scheduling policies may be implemented.

Multiprogramming

In a multiprogramming system there are one or more programs loaded in main memory
which are ready to execute. Only one program at a time is able to get the CPU for executing
its instructions (i.e., there is at most one process running on the system) while all the others
are waiting their turn.
The main idea of multiprogramming is to maximize the use of CPU time. Indeed, suppose the
currently running process is performing an I/O task (which, by definition, does not need the
CPU to be accomplished). Then, the OS may interrupt that process and give the control to
one of the other in-main-memory programs that are ready to execute (i.e. process context
switching). In this way, no CPU time is wasted by the system waiting for the I/O task to be
completed, and a running process keeps executing until either it voluntarily releases the CPU
or when it blocks for an I/O operation. Therefore, the ultimate goal of multiprogramming is
to keep the CPU busy as long as there are processes ready to execute.
Note that in order for such a system to function properly, the OS must be able to load
multiple programs into separate areas of the main memory and provide the required
protection to avoid the chance of one process being modified by another one. Other problems
that need to be addressed when having multiple programs in memory is fragmentation as
programs enter or leave the main memory. Another issue that needs to be handled as well is
that large programs may not fit at once in memory which can be solved by using pagination
and virtual memory..

Multiprocessing

Multiprocessing sometimes refers to executing multiple processes (programs) at the same


time. This might be misleading because we have already introduced the term
“multiprogramming” to describe that before.
In fact, multiprocessing refers to the hardware (i.e., the CPU units) rather than the software
(i.e., running processes). If the underlying hardware provides more than one processor then
that is multiprocessing. Several variations on the basic scheme exist, e.g., multiple cores on
one die or multiple dies in one package or multiple packages in one system.
Anyway, a system can be both multiprogrammed by having multiple programs running at the
same time and multiprocessing by having more than one physical processor.
Multitasking

Multitasking has the same meaning of multiprogramming but in a more general sense, as it
refers to having multiple (programs, processes, tasks, threads) running at the same time. This
term is used in modern operating systems when multiple tasks share a common processing
resource (e.g., CPU and Memory). At any time the CPU is executing one task only while
other tasks waiting their turn. The illusion of parallelism is achieved when the CPU is
reassigned to another task (i.e. process or thread context switching).
There are subtle differences between multitasking and multiprogramming. A task in a
multitasking operating system is not a whole application program but it can also refer to a
“thread of execution” when one process is divided into sub-tasks. Each smaller task does not
hijack the CPU until it finishes like in the older multiprogramming but rather a fair share
amount of the CPU time called quantum.
Just to make it easy to remember, both multiprogramming and multitasking operating
systems are (CPU) time sharing systems. However, while in multiprogramming (older OSs)
one program as a whole keeps running until it blocks, in multitasking (modern OSs) time
sharing is best manifested because each running process takes only a fair quantum of the
CPU time.

Multithreading
Up to now, we have talked about multiprogramming as a way to allow multiple programs
being resident in main memory and (apparently) running at the same time. Then, multitasking
refers to multiple tasks running (apparently) simultaneously by sharing the CPU time.
Finally, multiprocessing describes systems having multiple CPUs. So, where does
multithreading come in?
Multithreading is an execution model that allows a single process to have multiple code
segments (i.e., threads) run concurrently within the “context” of that process. You can think
of threads as child processes that share the parent process resources but execute
independently. Multiple threads of a single process can share the CPU in a single CPU
system or (purely) run in parallel in a multiprocessing system
Why should we need to have multiple threads of execution within a single process context?
Well, consider for instance a GUI application where the user can issue a command that
require long time to finish (e.g., a complex mathematical computation). Unless you design
this command to be run in a separate execution thread you will not be able to interact with the
main application GUI (e.g., to update a progress bar) because it is going to be unresponsive
while the calculation is taking place.
Of course, designing multithreaded/concurrent applications requires the programmer to
handle situations that simply don’t occur when developing single-threaded, sequential
applications. For instance, when two or more threads try to access and modify a shared
resource (race conditions), the programmer must be sure this will not leave the system in an
inconsistent or deadlock state. Typically, this thread synchronization is solved using OS
primitives, such as mutexes and sempaphores.

The main benefit of this functionality is that it can reduce wasted time in the system's
operations. As in a business, efficiency is the key to generating the most profit from an
enterprise. Using this type of operating system eliminates waste in the system by ensuring
that the computer's CPU is running at maximum capacity more of the time. This results in a
smoother computing experience from the end-user's point of view, as program commands are
constantly being executed in the background at all times, helping to speed execution of
programs.

Advantages of multiprogramming systems

 CPU is used most of time and never become idle


 The system looks fast as all the tasks runs in parallel
 Short time jobs are completed faster than long time jobs
 Multiprogramming systems support multiple users
 Resources are used nicely
 Total read time taken to execute program/job decreases
 Response time is shorter
 In some applications multiple tasks are running and multiprogramming systems better
handle these type of applications

Disadvantages of multiprogramming systems

 It is difficult to program a system because of complicated schedule handling


 Tracking all tasks/processes is sometimes difficult to handle
 Due to high load of tasks, long time jobs have to wait long

Swapping
Alternatively referred to as a page file or paging file, a swap file is a file on a hard drive that
is used as a temporary location to store information not being used by the computer RAM. By
using a swap file, a computer can use more memory than what is physically installed in the
computer. However, if the computer is low on drive space the computer can run slower
because of the inability of the swap file to grow.
It is normal for the swap file or page file to grow, sometimes growing several hundred megs
in size. Below is a listing of common Microsoft operating system default swap file names and
locations. Finally, by default, the swap files are hidden.

Operating system Swap file name Location


Windows NT, 2000, XP, Vista, and 7 PAGEFILE.SYS C:\
Windows 95, 98, and ME WIN386.SWP C:\
Windows 3.x 386PART.PAR C:\WINDOWS

To replace pages or segments of data in memory. Swapping is a useful technique that enables
a computer to execute programs and manipulate data files larger than main memory. The
operating system copies as much data as possible into main memory, and leaves the rest on
the disk. When the operating system needs data from the disk, it exchanges a portion of data
(called a page or segment) in main memory with a portion of data on the disk.

DOS does not perform swapping, but most other operating systems, including OS/2,
Windows, and UNIX, do.

Swapping, often called paging.is a simple memory/process management technique used by


the operating system(os) to increase the utilization of the processor by moving some blocked
process from the main memory to the secondary memory(hard disk);thus forming a queue of
temporarily suspended process and the execution continues with the newly arrived
process.After performing the swapping process,the operating system has two options in
selecting a process for execution :

- Operating System can admit newly created process

- Operating system can activate suspended process from the swap memory.

A swap file allows an operating system to use hard disk space to simulate extra memory.
When the system runs low on memory, it swaps a section of RAM that an idle program is
using onto the hard disk to free up memory for other programs. Then when you go back to
the swapped out program, it changes places with another program in RAM. This causes a
large amount of hard disk reading and writing that slows down your computer considerably.

This combination of RAM and swap files is known as virtual memory. The use of virtual
memory allows your computer to run more programs than it could run in RAM alone.

The way swap files are implemented depends on the operating system. Some operating
systems, like Windows, can be configured to use temporary swap files that they create when
necessary. The disk space is then released when it is no longer needed. Other operating
systems, like Linux and Unix, set aside a permanent swap space that reserves a certain
portion of your hard disk.

Permanent swap files take a contiguous section of your hard disk while some temporary swap
files can use fragmented hard disk space. This means that using a permanent swap file will
usually be faster than using a temporary one. Temporary swap files are more useful if you are
low on disk space because they don't permanently reserve part of your hard disk.

Paging
A computer can address more memory than the amount physically installed on the system.
This extra memory is actually called virtual memory and it is a section of a hard that's set up
to emulate the computer's RAM. Paging technique plays an important role in implementing
virtual memory.

Paging is a memory management technique in which process address space is broken into
blocks of the same size called pages (size is power of 2, between 512 bytes and 8192 bytes).
The size of the process is measured in the number of pages.

Similarly, main memory is divided into small fixed-sized blocks of (physical) memory called
frames and the size of a frame is kept the same as that of a page to have optimum utilization
of the main memory and to avoid external fragmentation.

Advantages and Disadvantages of Paging


 Paging reduces external fragmentation, but still suffer from internal fragmentation.
 Paging is simple to implement and assumed as an efficient memory management
technique.
 Due to equal size of the pages and frames, swapping becomes very easy.
 Page table requires extra memory space, so may not be good for a system having small
RAM.

Differences between Swapping and Paging


In spite of the historical interchanging of these two terms, they indicate different things. They
are both methods for managing moving data in memory to another storage device, called a
backing store (often a hard drive), but they use different methods of doing so.

Swapping involves the moving of a process's entire collection data in memory to a range of
space on the backing store, often to a swap file or swap partition. The process goes from
being in memory to swapped out entirely; there is no in-between. Obviously the process will
need to be entirely idle for swapping to be at all worthwhile. The advantage of this is that it is
relatively simple to grasp and memory for a program is always allocated contiguously, the
downside is that performance on a machine can become absolutely abysmal when the system
ends up in a state where things are constantly swapping. The algorithm also involves the
repeated swapping in and out of data that will not be used in the foreseeable future.

Paging attempts to solve these problem, by taking physical memory, and carving it up into
things called "frames" of some fixed size. It also takes the memory space of each running
process, and carves it up into pages (which are the same size as frames); this is called the
physical address space, due to the need to use physical addresses to access each block of
memory.

Each program is presented an environment by the OS, and supported by modern hardware,
which makes the programs memory footprint look like a single contiguous block of a very
large amount of memory; this is called a logical address space.
However, each page of this contiguous block may be in memory, or it may be on the backing
store. The operating system determines where each page is by consulting something called a
"page table". If it finds the page the program has asked for is in memory somewhere, it will
simply go to that page of memory and grab the data requested.

If it finds the page is not in memory; this causes a "page fault". The OS will suspend the
process while it loads the requested page in from the backing store, and may in turn move
another page from memory to the backing store to make room, based on some replacement
algorithm. The backing store may be called a pagefile, or may still be called a swapfile or
swap partition, leading to confusion about which system is being used. Whether it is a
separate partition, or just a file, depends on the operating system.

There are certain parts of memory that aren't subject to being paged out. One of these is the
paging code itself, and the parts of the kernel that handle things like page faults. Some
operating systems, like MacOS, refer to this memory as "wired".

Modern day hardware has several devices that allow an operating system to support paging
far more effectively. The most common of these is a Translation Lookaside Buffer, or TLB.
This stores a sort of hardware page table cache, so that whenever a program needs to do a
logical address to physical address translation, it doesn't have to go ask the operating system
every time.

Modern operating systems also take advantage of paging by lazily-loading parts of the
processes they are running. For instance, if you startup Microsoft Word, instead of loading
the entire program into memory, the operating system will instead load only those parts of the
program it needs into memory, and will grab the other parts of the program only as it needs
them. This has trade-offs as well between memory footprint, boot speed, and how often
delays occur within the program as new parts need to be loaded.

Segmentation
A process is divided into Segments. The chunks that a program is divided into which are not
necessarily all of the same length is called segments.

Segmentation is a memory management technique in which each job is divided into several
segments of different sizes, one for each module that contains pieces that perform related
functions. Each segment is actually a different logical address space of the program.

When a process is to be executed, its corresponding segmentation are loaded into non-
contiguous memory though every segment is loaded into a contiguous block of available
memory.

Segmentation memory management works very similar to paging but here segments are of
variable-length where as in paging pages are of fixed size.

A program segment contains the program's main function, utility functions, data structures,
and so on. The operating system maintains a segment map table for every process and a list of
free memory blocks along with segment numbers, their size and corresponding memory
locations in main memory. For each segment, the table stores the starting address of the
segment and the length of the segment. A reference to a memory location includes a value
that identifies a segment and an offset.
Segmentation is one of the most common ways to achieve memory protection. In a computer
system using segmentation, an instruction operand that refers to a memory location includes a
value that identifies a segment and an offset within that segment. A segment has a set of
permissions, and a length, associated with it. If the currently running process is allowed by
the permissions to make the type of reference to memory that it is attempting to make, and
the offset within the segment is within the range specified by the length of the segment, the
reference is permitted; otherwise, a hardware exception is raised.

In addition to the set of permissions and length, a segment also has associated with it
information indicating where the segment is located in memory. It may also have a flag
indicating whether the segment is present in main memory or not; if the segment is not
present in main memory, an exception is raised, and the operating system will read the
segment into memory from secondary storage. The information indicating where the segment
is located in memory might be the address of the first location in the segment, or might be the
address of a page table for the segment, if the segmentation is implemented with paging. In
the first case, if a reference to a location within a segment is made, the offset within the
segment will be added to address of the first location in the segment to give the address in
memory of the referred-to item; in the second case, the offset of the segment is translated to a
memory address using the page table.

In most systems in which a segment doesn't have a page table associated with it, the address
of the first location in the segment is an address in main memory; in those systems, no paging
is done. In the Intel 80386 and later, that address can either be an address in main memory, if
paging is not enabled, or an address in a paged "linear" address space, if paging is enabled.

A memory management unit (MMU) is responsible for translating a segment and offset
within that segment into a memory address, and for performing checks to make sure the
translation can be done and that the reference to that segment and offset is permitted.

This usage should not be confused with that of the memory segments used by early x86
processors such as the Intel 8086 and Intel 8088, as they did not provide any protection (any
program could access any segment with no restrictions, and a segment consisted of only a
starting location and a fixed length of 64 KiB); segmentation in the Intel 80286 and later
provided protection. It protects the file of the main memory.

There are types of segmentation:

1. Virtual memory segmentation – Each process is divided into a number of segments, not
all of which are resident at any one point in time.
2. Simple segmentation – Each process is divided into a number of segments, all of which
are loaded into memory at run time, though not necessarily contiguously.

There is no simple relationship between logical addresses and physical addresses in


segmentation. A table stores the information about all such segments and is called Segment
Table.

Segment Table – It maps two dimensional Logical address into one dimensional Physical
address. It’s each table entry has:
 Base Address: It contains the starting physical address where the segments reside in
memory.
 Limit: It specifies the length of the segment.

Advantages of Segmentation –

 No Internal fragmentation.
 Segment Table consumes less space in comparison to Page table in paging.

Disadvantage of Segmentation –

 As processes are loaded and removed from the memory, the free memory space is
broken into little pieces, causing External fragmentation.

Difference between paging and segment in memory management


Paging & Segmentation are two contrasting approaches to virtual memory management.
Virtual memory is when a process is not mapped into the actual physical memory space of a
computer but to a virtual imaginary memory space. Every memory request from a process is
mapped from the virtual space to physical space by the OS.

There are many reasons for using virtual memory in multitasked operating systems, one of
the important ones is that you can have a virtual memory space that is bigger than the
physical space by the operating system using disk as an extension of physical memory.

Many people have described this but in a segmented memory space the physical memory is
divided into partitions of differing length and the operating system keeps track of what space
has been allocated and the size of the segment. In a segmented system since the size of
allocated memory is flexible the OS allocates the exact amount of space a process asks for.
In paged systems the physical memory is divided in blocks of equal size and a process is
allocated a number of pages that is just larger than what it physically requires. So a little
space is wasted at the end of the last page (except for the highly unlikely circumstance where
the process requires exactly enough memory to fit into some number of pages).

When a process starts up it is allocated memory and when a process terminates it deallocates
the space allocated to it. The OS keeps track of this. As the process runs and accesses
memory the OS maps the virtually allocated memory space to the physical memory space. If
a process requests access to a piece of virtual memory that is not currently mapped to
physical space then one of the allocated chunks (a segment or a page) is written back to disk,
freed up and allocated to the requesting process.

Because segmented memory is allocated in non-uniform chunks it has the problem of


“fragmentation”. This is a long topic and I won’t describe it all here but in a nutshell if you
keep allocating and de-allocating memory chunks of different sized then eventually between
two adjacent chunks of memory you will start building up small pieces of memory - these
pieces are very small and usually not worth allocating on their own but collectively they start
occupying a larger and larger amount of the overall memory. If the OS utilizes these small
chunks there starts to get a huge number of segments allocated to a process (since each chunk
is very small) and this leads to inefficiency. Because the more overall physical segments
there are the more work the OS has to do.

Paged memory is free from that high level fragmentation because each chunk of memory is
the same size. The only fragmentation is the internal fragmentation at the end of the last page
which is unutilized. But that is not a big problem because it does not get bigger over time.

Device Controllers

The way in which devices connected to a bus cooperate is another part of a bus standard.

A device controller is a system that handles the incoming and outgoing signals of the CPU. A
device is connected to the computer via a plug and socket, and the socket is connected to a
device controller. Device controllers use binary and digital codes. An IO device contains
mechanical and electrical parts. A device controller is the electrical part of the IO device.

Any device connected to the computer is connected by a plug and socket, and the socket is
connected to a device controller. The device controller receives data from a connected device.
It stores that data temporarily in a special purpose register called a local buffer inside the
controller. Each device controller has a corresponding device driver. The memory is
connected to the memory controller. The monitor is connected to the video controller while
the keyboard is connected to the keyboard controller. In brief, device driver is software while
device controller is hardware. Disk drive is connected to the disk controller, and the USB
drive is connected to the USB controller. These controllers are connected to the CPU via the
common bus.

I/O controllers are sometimes called device controllers. Input/output controllers receive input
and output requests from the central processor, and then send device-specific control signals
to the device they control. They also manage the data flow to and from the device. This frees
the central processor from involvement with the details of controlling each device. I/O
controllers are needed only for those I/O devices that are part of the system.
Often the I/O controllers are part of the electronics on the main circuit board (the mother
board) of the computer. Sometimes an uncommon device requires its own controller which
must be plugged into a connector (an expansion slot) on the mother board.

.The software that directly interacts with a device controller is called a device driver. When
you install a new device on your computer (say, a new graphics board) you must also install a
device driver for it.

Every device has a device controller and a device driver to communicate with the operating
system. Device drivers are software modules that can be plugged into an OS to handle a
particular device. Operating System takes help from device drivers to handle all I/O devices.

The Device Controller works like an interface between a device and a device driver. I/O units
(Keyboard, mouse, printer, etc.) typically consist of a mechanical component and an
electronic component where electronic component is called the device controller.

There is always a device controller and a device driver for each device to communicate with
the Operating Systems. A device controller may be able to handle multiple devices. As an
interface its main task is to convert serial bit stream to block of bytes, perform error
correction as necessary.

Following is a model for connecting the CPU, memory, controllers, and I/O devices where
CPU and device controllers all use a common bus for communication.

Each I/O controller is designed specially to handle a particular kind of device. The CPU
communicates with the I/O device through device controller of that device. The CPU sends
signals to device controller to perform a specific I/O operation such as read or write
operation.

Direct Memory Access


Direct memory access (DMA) is a method that allows an input/output (I/O) device to send or
receive data directly to or from the main memory, bypassing the CPU to speed up memory
operations. The process is managed by a chip known as a DMA controller (DMAC).

Direct Memory Access (DMA) is a capability provided by some computer bus architectures
that allows data to be sent directly from an attached device (such as a disk drive) to the
memory on the computer's motherboard. The microprocessor is freed from involvement with
the data transfer, thus speeding up overall computer operation.

Usually a specified portion of memory is designated as an area to be used for direct memory
access. In the ISA bus standard, up to 16 megabytes of memory can be addressed for DMA.

The following types of DMA transfers can be performed:

 Between two devices


 Between a device and memory
 Between memory and memory

Data transfer can be triggered in two ways: either the software asks for data (via a function
such as read) or the hardware asynchronously pushes data to the system.

In the first case, the steps involved can be summarized as follows:

1. When a process calls read, the driver method allocates a DMA buffer and instructs
the hardware to transfer its data into that buffer. The process is put to sleep.
2. The hardware writes data to the DMA buffer and raises an interrupt when it's done.
3. The interrupt handler gets the input data, acknowledges the interrupt, and awakens the
process, which is now able to read data.

The second case comes about when DMA is used asynchronously. This happens, for
example, with data acquisition devices that go on pushing data even if nobody is reading
them. In this case, the driver should maintain a buffer so that a subsequent read call will
return all the accumulated data to user space. The steps involved in this kind of transfer are
slightly different:

1. The hardware raises an interrupt to announce that new data has arrived.
2. The interrupt handler allocates a buffer and tells the hardware where to transfer its
data.
3. The peripheral device writes the data to the buffer and raises another interrupt when
it's done.
4. The handler dispatches the new data, wakes any relevant process, and takes care of
housekeeping.

Interrupt Handler

The job of the kernel isn't just to respond to process requests. Another job, which is every bit
as important, is to speak to the hardware connected to the machine.

An interrupt is a hardware signal from a device to a CPU. An interrupt tells the CPU that the
device needs attention and that the CPU should stop any current activity and respond to the
device. If the CPU is not performing a task that has higher priority than the priority of the
interrupt, then the CPU suspends the current thread. The CPU then invokes the interrupt
handler for the device that sent the interrupt signal. The job of the interrupt handler is to
service the device and stop the device from interrupting. When the interrupt handler returns,
the CPU resumes the work it was doing before the interrupt occurred.

There are two types of interaction between the CPU and the rest of the computer's hardware.
The first type is when the CPU gives orders to the hardware, the other is when the hardware
needs to tell the CPU something. The second, called interrupts, is much harder to implement
because it has to be dealt with when convenient for the hardware, not the CPU. Hardware
devices typically have a very small amount of RAM, and if you don't read their information
when available, it is lost. Under Linux, hardware interrupts are called IRQ's (InterruptRe
quests)

The key to handling hardware events in a timely manner is for the hardware to generate an
interrupt. An interrupt is simply a pause in, or interruption of, whatever the processor was
doing, along with a request to do something else.

An interrupt is produced by electronic signals from hardware devices and directed into input
pins on an interrupt controller (a simple chip that multiplexes multiple interrupt lines into a
single line to the processor):

1. Upon receiving an interrupt, the interrupt controller sends a signal to the processor.
2. The processor detects this signal and interrupts its current execution to handle the
interrupt.
3. The processor can then notify the operating system that an interrupt has occurred, and
the operating system can handle the interrupt appropriately.

Different devices are associated with different interrupts using a unique value associated with
each interrupt. This enables the operating system to differentiate between interrupts and to
know which hardware device caused which interrupt. In turn, the operating system can
service each interrupt with its corresponding handler.

The hardware generates an interrupt whenever it has reached some state where software
intervention is desired. Instead of having the software continually poll the hardware — which
wastes CPU time — an interrupt is the preferred method of “finding out” that the hardware
requires some kind of service. The software that handles the interrupt is therefore typically
called an Interrupt Service Routine (ISR). Although crucial in a realtime system, interrupt
handling has unfortunately been a very difficult and awkward task in many traditional
operating systems
When an event occurs the micro-controller generates a hardware interrupt. The interrupt
forces the micro-controller's program counter to jump to a specific address in program
memory. This special memory address is called the interrupt vector. At this memory location
we install a special function known as an interrupt service routine (ISR) which is also known
as an interrupt handler. So upon generating a hardware interrupt, program execution jumps to
the interrupt handler and executes the code in that handler. When the handler is done, then
program control returns the micro-controller to the original program it was executing. So a
hardware interrupt allows a micro-controller to interrupt an existing program and react to
some external hardware event. This type of flow control is illustrated in figure above.

Device Driver
Drivers are low level programs written by hardware manufacturers which are loaded as
kernel modules and provide the kernel with the knowledge on how to control the devices.

A device driver is a program that controls a particular type of device that is attached to your
computer. There are device drivers for printers, displays, CD-ROM readers, diskette drives,
and so on. When you buy an operating system, many device drivers are built into the product.
However, if you later buy a new type of device that the operating system didn't anticipate,
you'll have to install the new device driver. A device driver essentially converts the more
general input/output instructions of the operating system to messages that the device type can
understand.

A device driver can therefore be defined as a small piece of software that tells the operating
system and other software how to communicate with a piece of hardware.

For example, printer drivers tell the operating system, and by extension whatever program
you have the thing you want to print open in exactly how to print information on the page

Sound card drivers are necessary so your operating system knows exactly how to translate the
1s and 0s that comprise that MP3 file into audio signals that the sound card can output to your
headphones or speakers.

The same general idea applies to video cards, keyboards, monitors, mice, disc drives, etc.
How Exactly Do Device Drivers Work?

Think of device drivers like translators between a program you're using and a device that that
program wants to utilize somehow. The software and the hardware were created by different
people or companies and speak two completely different languages, so a translator (the
driver) allows them to communicate.

In other words, a software program can provide information to a driver to explain what it
wants a piece of hardware to do, information the device driver understands and then can
fulfill with the hardware.

Thanks to device drivers, most software programs don't need to know how to work directly
with hardware, and a driver doesn't need to include a full application experience for users to
interact with. Instead, the program and driver simply need to know how to interface with each
other.

This is a pretty good deal for everyone involved, considering that there is a nearly endless
supply of software and hardware out there. If everyone had to know how to communicate
with everyone else, the process of making software and hardware would be near impossible.

How to Manage Device Drivers

The drivers for each piece of hardware in your Windows computer are centrally managed
from Device Manager, available in all versions of Microsoft Windows.

Most of the time, drivers install automatically and never need more attention, aside from the
occasional updating to fix bugs or add a cool new feature. This is true for some drivers in
Windows that are downloaded via Windows Update.

When a manufacturer releases a driver update, it's your responsibility to install it. Some
companies provide programs that will check for and install any relevant updates, but most
don't make it that easy.

Fortunately, there are free driver updater programs that serve the same purpose, and work
with all types of drivers. Some will even check for updates automatically and download and
install them for you, much like Windows Update.

Here are some common tasks in Windows involving drivers:

When we get a peripheral device such as printer, scanner, keyboard or modem, the device
comes together with a driver CD which needs to be installed before the device starts working.
As soon we install the driver software into the computer, it detects and identifies the
peripheral device and we become able to control the device with the computer. A device
driver is a piece of software that allows your computer’s operating system to communicate
with a hardware device, the driver is written for. Generally a driver communicates with the
device through the computer bus which is used to connect the device with the computer.

Device drivers works within the kernel layer of the operating system. Kernel is the part of the
operating system that directly interacts with the physical structure of the system. Instead of
accessing a device directly, an operating system loads the device drivers and calls the specific
functions in the driver software in order to execute specific tasks on the device. Each driver
contains the device specific codes required to carry out the actions on the device.

If the appropriate driver is not installed, the device may not function properly, if at all. For
Microsoft Windows users, a driver conflict or an error can be seen in the Device Manager. If
problems or conflicts are encountered with a driver, the computer manufacturer or hardware
manufacturer will release a driver update to fix the problems.

Some Windows programs are virtual device drivers. These programs interface with the
Windows Virtual Machine Manager. There is a virtual device driver for each main hardware
device in the system, including the hard disk drive controller, keyboard, and serial and
parallel ports. They're used to maintain the status of a hardware device that has changeable
settings. Virtual device drivers handle software interrupts from the system rather than
hardware interrupts.

In Windows operating systems, a device driver file usually has a file name suffix of DLL or
EXE. A virtual device driver usually has the suffix of VXD.

Disks

A disk drive is a randomly addressable and rewritable storage device. The term can be
broadly interpreted to include optical drives and in earlier times, floppy drives. However, in
popular usage, it has come to relate mainly to hard disk drives (HDDs).

Disk drives can either be housed internally within a computer or housed in a separate box that
is external to the computer. They are found in PCs, servers, laptops and storage arrays, for
example. They work by rotating very rapidly around a head or heads, which read and write
data. They differ from solid state drives (SSDs), which have no moving parts and offer
greater performance, but also cost more and generally offer less capacity.
Disk Drive Terms

Platter: Hard drives are normally composed of multiple disks called platters. These platters
are stacked on top of each other. It is the platter that actually stores the data. It consists of a
substrate coated with magnetic media. The substrate is there to act as a rigid support for the
magnetic media. The magnetic layer is protected by a thin layer of carbon and a lubrication
layer to prevent damage in case the head comes in contact with the platter surface. Typically,
both sides of the platter have magnetic media on which to store data. Tens of thousands of
tracks per inch can be laid down on these platters.

Spindle/Motor: The platters are attached at the centre to a rod or pin called a spindle that is
directly attached to the shaft of the motor that controls the speed of rotation.

The two principal technologies at work in disk drives are Advanced Technology Attachment
(ATA), also known as IDE or Integrated Drive Electronics, and Small Computer System
Interface (SCSI). ATA drives are generally less expensive and more common, while the more
expensive SCSI drives are used for higher-performance applications.

The two main types of HDDs used in storage today are SATA and SAS. SATA is short for
Serial ATA. Basically, the architecture used in ATA disks hit the limit of its data transfer
capability and was severely bottlenecking system performance. A different serial architecture
used in SATA removed that restriction so that disk drive bandwidth could be steadily
improved. These days SATA disk drives are widely deployed to store large quantities of data,
or bulk storage.

SAS stands for Serial Attached SCSI. Like SATA, SAS provides a leap in performance over
SCSI. While SAS disks are able to reach speeds of up to 15,000 rpm (about twice the speed
of many SATA disks), they are more expensive. Hence SATA tends to be used for the largest
volume of data, while SAS is often reserved for frequently accessed data.

The disks themselves have a number of features:

Tracks: A track is a concentric ring on the disk where data is stored.

Cylinders: On drives that contain multiple platters, all the tracks on all the platters that are at
the same distance from the centre are referred to as a cylinder. The data from all the tracks in
the cylinder can be read by simply switching between the different heads, which is much
faster than physically moving the head between the different tracks on a single disk.

Sectors: Tracks are further broken down into sectors, which are the smallest units of storage
on a disk, typically 512 bytes. A larger number of sectors are recorded on the outer tracks,
and progressively fewer toward the centre. Data can also be read faster from the outer tracks
and sectors than the inner ones.

Clusters: Sectors are grouped together into clusters. As far as the operating system is
concerned, all the sectors in one cluster are a single unit.

Extents: A set of contiguous clusters storing a single file or part of a file is called an extent. It
is best to keep the number of extents for any file to a minimum, as each extent requires a
separate input/output (I/O) operation. Reducing the number of extents in a file is achieved
using a process known as defragmentation. This greatly improves performance.

GUI
Stands for "Graphical User Interface" and is pronounced "gooey." GUI is a a program
interface that takes advantage of the computer's graphics capabilities to make the program
easier to use. Well-designed graphical user interfaces can free the user from learning complex
command languages. On the other hand, many users find that they work more effectively
with a command-driven interface, especially if they already know the command language.
With the advent of the Macintosh in the mid-1980s and Windows in the 1990s, GUIs
replaced the character-based display with a graphics display that eliminated the need to enter
cryptic commands in a required sequence. In addition, fonts could be changed and resized on
screen, providing a what-you-see-is-what-you-get (WYSIWYG) capability for creating
printed materials. However, all major operating systems still include a command line
interface that lets programmers and power users enter commands to perform certain tasks
faster and more easily than with a mouse.

The first graphical user interface was designed by Xerox Corporation's Palo Alto Research
Centre in the 1970s, but it was not until the 1980s and the emergence of the Apple Macintosh
that graphical user interfaces became popular. One reason for their slow acceptance was the
fact that they require considerable CPU power and a high-quality monitor, which were
prohibitively expensive. The GUI was first developed at Xerox PARC by Alan Kay, Douglas
Engelbart, and a group of other researchers in 1981. Later, Apple introduced the Lisa
computer with a GUI on January 19, 1983.

(GUI) is an interface through which a user interacts with electronic devices such as
computers, hand-held devices and other appliances. This interface uses icons, menus and
other visual indicator (graphics) representations to display information and related user
controls, unlike text-based interfaces, where data and commands are in text. GUIl
representations are manipulated by a pointing device such as a mouse, trackball, stylus, or a
finger on a touch screen.

Basic Components of a GUI

Graphical user interfaces, such as Microsoft Windows and the one used by the Apple
Macintosh, feature the following basic components:
Pointer: A symbol that appears on the display screen and that you move to select objects
and commands. Usually, the pointer appears as a small angled arrow. Text -processing
applications, however, use an I-beam pointer that is shaped like a capital I.
Pointing device: A device, such as a mouse or trackball, that enables you to select objects
on the display screen.
Icons: Small pictures that represent commands, files, or windows. By moving the pointer
to the icon and pressing a mouse button, you can execute a command or convert the icon into
a window. You can also move the icons around the display screen as if they were real objects
on your desk.
Desktop: The area on the display screen where icons are grouped is often referred to as the
desktop because the icons are intended to represent real objects on a real desktop.
Windows: You can divide the screen into different areas. In each window, you can run a
different program or display a different file. You can move windows around the display
screen, and change their shape and size at will.
Menus: Most graphical user interfaces let you execute commands by selecting a choice
from a menu.
In addition to their visual components, graphical user interfaces also make it easier to move
data from one application to another. A true GUI includes standard formats for representing
text and graphics. Because the formats are well-defined, different programs that run under a
common GUI can share data. This makes it possible, for example, to copy a graph created by
a spreadsheet program into a document created by a word processor.
Many DOS programs include some features of GUIs, such as menus, but are not graphics
based. Such interfaces are sometimes called graphical character-based user interfaces to
distinguish them from true GUIs.

Security and Protection issues


Operating system security (OS security) is the process of ensuring Operating System
integrity, confidentiality and availability. The operating system is the physical environment
where your application runs. Any vulnerability in the operating system could compromise the
security of the application. By securing the operating system, you make the environment
stable, control access to resources, and control external access to the environment.

OS security refers to specified steps or measures used to protect the OS from threats, viruses,
worms, malware or remote hacker intrusions. OS security encompasses all preventive-control
techniques, which safeguard any computer assets capable of being stolen, edited or deleted if
OS security is compromised. . OS security allows different applications and programs to
perform required tasks and stop unauthorized interference.

OS security may be approached in many ways, including adherence to the following:

 Performing regular OS patch updates


 Installing updated antivirus engines and software
 Scrutinizing all incoming and outgoing network traffic through a firewall
 Creating secure accounts with required privileges only (i.e., user management)

The processes in an operating system must be protected from one another's activities. To
provide such protection, we can use various mechanisms to ensure that only processes that
have gained proper authorization from the operating system can operate on the files, memory
segments, CPU, and other resources of a system.

Protection refers to a mechanism for controlling the access of programs, processes, or users to
the resources defined by a computer system. This mechanism must provide a means for
specifying the controls to be imposed, together with a means of enforcement
The physical security of the system is essential. Threats can come through the Web, but they
can also come from a physical terminal. Even if the Web access is very secure, if an attacker
obtains physical access to a server, breaking into a system is much easier. Review security
policies and recommendations for your operating system

Security also refers to provision of a protection system to computer system resources such as
CPU, memory, disk, software programs and most importantly data/information stored in the
computer system. If a computer program is run by an unauthorized user, then he/she may
cause severe damage to computer or data stored in it. So a computer system must be
protected against unauthorized access, malicious access to system memory, viruses, worms
etc.

Authentication

Authentication refers to identifying each user of the system and associating the executing
programs with those users. It is the responsibility of the Operating System to create a
protection system which ensures that a user who is running a particular program is authentic.
Operating Systems generally identifies/authenticates users using following three ways −

 Username / Password − User need to enter a registered username and password with
Operating system to login into the system.
 User card/key − User need to punch card in card slot, or enter key generated by key
generator in option provided by operating system to login into the system.
 User attribute - fingerprint/ eye retina pattern/ signature − User need to pass his/her
attribute via designated input device used by operating system to login into the
system.

One Time passwords

One-time passwords provide additional security along with normal authentication. In One-
Time Password system, a unique password is required every time user tries to login into the
system. Once a one-time password is used, then it cannot be used again. One-time password
are implemented in various ways.

 Random numbers − Users are provided cards having numbers printed along with
corresponding alphabets. System asks for numbers corresponding to few alphabets
randomly chosen.
 Secret key − User are provided a hardware device which can create a secret id
mapped with user id. System asks for such secret id which is to be generated every
time prior to login.
 Network password − Some commercial applications send one-time passwords to user
on registered mobile/ email which is required to be entered prior to login.

Program Threats

Operating system's processes and kernel do the designated task as instructed. If a user
program made these process do malicious tasks, then it is known as Program Threats. One of
the common example of program threat is a program installed in a computer which can store
and send user credentials via network to some hacker. Following is the list of some well-
known program threats.
 Trojan Horse − Such program traps user login credentials and stores them to send to
malicious user who can later on login to computer and can access system resources.
 Trap Door − If a program which is designed to work as required, have a security hole
in its code and perform illegal action without knowledge of user then it is called to
have a trap door.
 Logic Bomb − Logic bomb is a situation when a program misbehaves only when
certain conditions met otherwise it works as a genuine program. It is harder to detect.
 Virus − Virus as name suggest can replicate themselves on computer system. They
are highly dangerous and can modify/delete user files, crash systems. A virus is
generatlly a small code embedded in a program. As user accesses the program, the
virus starts getting embedded in other files/ programs and can make system unusable
for user

System Threats

System threats refers to misuse of system services and network connections to put user in
trouble. System threats can be used to launch program threats on a complete network called
as program attack. System threats creates such an environment that operating system
resources/ user files are misused. Following is the list of some well-known system threats.

 Worm − Worm is a process which can choked down a system performance by using
system resources to extreme levels. A Worm process generates its multiple copies
where each copy uses system resources, prevents all other processes to get required
resources. Worms processes can even shut down an entire network.
 Port Scanning − Port scanning is a mechanism or means by which a hacker can
detects system vulnerabilities to make an attack on the system.
 Denial of Service − Denial of service attacks normally prevents user to make
legitimate use of the system. For example, a user may not be able to use internet if
denial of service attacks browser's content settings.

Computer Security Classifications

As per the U.S. Department of Defense Trusted Computer System's Evaluation Criteria there
are four security classifications in computer systems: A, B, C, and D. This is widely used
specifications to determine and model the security of systems and of security solutions.
Following is the brief description of each classification.

Classification Type & Description


Type A

Highest Level. Uses formal design specifications and verification techniques. Grants a
high degree of assurance of process security.
Type B

Provides mandatory protection system. Have all the properties of a class C2 system.
Attaches a sensitivity label to each object. It is of three types.

 B1 − Maintains the security label of each object in the system. Label is used for
making decisions to access control.
 B2 − Extends the sensitivity labels to each system resource, such as storage objects,
supports covert channels and auditing of events.
 B3 − Allows creating lists or user groups for access-control to grant access or revoke
access to a given named object.

Type C

Provides protection and user accountability using audit capabilities. It is of two types.

 C1 − Incorporates controls so that users can protect their private information and
keep other users from accidentally reading / deleting their data. UNIX versions are
mostly Cl class.
 C2 − Adds an individual-level access control to the capabilities of a Cl level system.

Type D

Lowest level. Minimum protection. MS-DOS, Window 3.1 fall in this category.

Consider implementing the following security best practices.

User Accounts

 Limit the number of user accounts on the server computers.

Unnecessary and legacy user accounts increase system complexity and may present
system vulnerabilities.

Fewer user accounts reduces the amount of time administrators spend on account
administration.

 Ensure that only a few trusted users have administrative access to the server
computers.

Fewer administrators make it easier to maintain accountability. The administrators


must be competent.

 Assign the minimum required access permissions for the account that runs the
application.

If attackers obtain access to the application, they have the permissions of the user who
runs the application.

Account Policies
 Develop and administer password policies that promote operating system security.

Examples of such policies are the strong password rule and the password change
schedule.

 Test the strength of users' passwords by breaking the passwords.

The users who do not comply with the strong password rule receive a notification to
update their passwords according to the organization password policy.

Software is available to help you with this task.

 On a UNIX operating system, activate the shadow password file.

On UNIX, passwords are stored in the /etc/passwd file. This file is open to everyone,
which presents a security risk. To enhance password security, activate the shadow
password file named /etc/shadow. If this file is available, passwords are stored in it
instead of the passwd file. Because permissions for the /etc/shadow file are more
restrictive, the security risk is lower.

File System

 Grant the users read-only permissions for required directories.

If attackers obtain access to an application, they have the user permissions.

 Deny access by default.

Access to resources is denied for everyone except for the users to whom access is
granted explicitly.

You can deny read and write permissions for all directory structures for all users.
Only users to whom these permissions are granted explicitly have access to the
directories and files. This policy also protects any resources that were overlooked by
an administrator.

Network Services

 Provide the minimum number of required services on the server computer.

Use only the services that you need to run the application. Each service is a potential
entry point for a malicious attack. Reducing the number of running services also
makes your system more manageable.

For example, you may not need the ftp, rlogin, or ssh services.

 Reduce the level of access permissions for the network services users.

Network services are exposed to the public.


 Ensure that the user accounts that have access to the Web server do not have access to
the shell functions.
 Ensure that unused services do not exist in the rc files, rc0 through to rc6, in the /etc
directory on UNIX and Linux operating systems.
 Ensure that unused services are not running, and that they do not start automatically
on Microsoft Windows operating systems.
 Ensure that required services are running on UNIX.

You can use the ps and netstat utilities to see the running services. The ps utility gives
a list of processes currently running on the computer. The netstat utility provides a list
of ports that are currently in use.

 Reduce the number of trusted ports specified in the /etc/services file.

Delete or comment out the ports that you do not plan to use to eliminate possible entry
points to the system.

 Protect your system against NetBIOS threats associated with ports 137, 138, and 139.

These ports are listed in the /etc/services file.

 Use wrapper services, such as iptables.


 Ensure that the services are current by checking often for security updates.
 Avoid using services that have a graphical user interface (GUI), if possible.

Such services introduce many known security vulnerabilities.

System Patches

 Run the latest, vendor-recommended patches for the operating system.

The patches may be core OS patches, or patches required by additional applications.

 Schedule regular maintenance of security patches.

Operating System Minimization

 Remove nonessential applications to reduce possible system vulnerabilities.


 Restrict local services to the services required for operation.
 Implement protection for buffer overflow.

You may need third-party software to do this.

Logging and Monitoring

 Log security-related events, including successful and failed logons, logoffs, and
changes to user permissions.
 Monitor system log files.
 Use a time server to correlate time for forensics.
 Secure the system log files by restricting access permissions to them.

Logs are important for daily maintenance and as a disaster recovery tool. Therefore,
they must be protected from system failures and user tampering.

 Use IPF logging to build a more sophisticated logging system.

To increase the security of the log file system, you can

o place all log files in one location, on one server

This simplifies the administration of log files.

o set up multiple logging servers for redundancy


o use a remote server for logging

This protects the logs if the system is compromised and, for example, the hard
drive is destroyed.

Because an IPF server is accessed through the network, it can be located


anywhere in the world.

 Secure the logging configuration file.

The configuration file contains settings that, if changed, can compromise the
reliability of the log system. For example, setting the log level incorrectly may cause
some failures not to be logged.

 Enable logging of access requests on the Web server.

This can be useful in identifying malicious activity.

System Integrity

 Build production systems from a known and repeatable process to ensure the system
integrity.
 Check systems periodically against snapshots of the original system.
 Use available third-party auditing software to check the system integrity.
 Back up the system resources on a regular basis.

Clocks
Real-time systems require a number of operating system timing services. The operating
system must be able to keep an accurate accounting of the passage of time, schedule threads
at precise times, and suspend threads for precise intervals.

There are two main reasons why clocks are very essential to the operation of any
multiprogrammed system.
Clock maintain the time of day and prevent one process from monopolizing the central
processing unit among other things.

The clock software can take the form of a device driver, even though a clock is neither a
block device, nor a character device like disk and mouse.

Clock Driver

The work of clock driver varies among OSs. But the clock driver's work generally include the
following:

 Maintains the time of day


 Prevents the processes from running longer than fixed/allowed
 Accounts for central processing unit usage
 Doing profiling, monitoring and statistics gathering

Power Management

Power management is a computing device feature that allows users to control the amount of
electrical power consumed by an underlying device, with minimal impact on performance. It
enables the switching of devices in various power modes, each with different power usage
characteristics related to device performance.

A native feature of most hardware devices, power management is managed by a computer's


preinstalled firmware or installed host operating system (OS). Firmware or a host OS
typically uses Advanced Configuration and Power Interface (ACPI) to access a computer's
power features.

The power management for microprocessors can be done over the whole processor,[2] or in
specific components, such as cache memory[3] and main memory.[4]

With dynamic voltage scaling and dynamic frequency scaling, the CPU core voltage, clock
rate, or both, can be altered to decrease power consumption at the price of potentially lower
performance. This is sometimes done in real time to optimize the power-performance
tradeoff.

When a computer system hibernates it saves the contents of the RAM to disk and powers
down the machine. On startup it reloads the data. This allows the system to be completely
powered off while in hibernate mode. This requires a file the size of the installed RAM to be
placed on the hard disk, potentially using up space even when not in hibernate mode.
Hibernate mode is enabled by default in some versions of Windows and can be disabled in
order to recover this disk space.

In Windows 7 and later operating systems, a device can operate by default between five
different power modes: high performance, balanced, power saver, sleep and hibernate. A
system's performance is optimal but consumes more energy in high performance mode,
whereas power saver mode saves energy but provides less performance.
Additionally, power settings may be manually adjusted to configure computer brightness, end
unnecessary backend device services or switch a computer to sleep mode, etc.

The Windows operating system provides a comprehensive and system-wide set of power
management features. This enables systems to extend battery life and save energy, reduce
heat and noise, and help ensure data reliability.

The power management functions and messages retrieve the system power status, notify
applications of power management events, and notify the system of each application's power
requirements.

You might also like