Professional Documents
Culture Documents
Csc 333 Complete Note
Csc 333 Complete Note
OPERATING SYSTEMS
LECTURE NOTE I
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.
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
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.
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.
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.
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.
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.
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.
(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.
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.
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.
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
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.
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
- 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
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.
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.
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.
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.
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.
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.
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!
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.
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.
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.
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.
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.
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.)
-- 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.
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.
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.
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.
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
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.
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.
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 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.
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.
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.
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.
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.
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.
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:
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.
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.
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.
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.
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.
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.
Operating system performs the task of scheduling processes based on priorities using these
following algorithms:
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.
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.
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,
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.
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.
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
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.
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.
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.
- 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.
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.
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.
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.
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.
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 (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.
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.
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.
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.
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.
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.
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.
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.
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 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.
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.
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.
User Accounts
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.
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.
The users who do not comply with the strong password rule receive a notification to
update their passwords according to the organization password policy.
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
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
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.
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.
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.
System Patches
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.
This protects the logs if the system is compromised and, for example, the hard
drive is destroyed.
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.
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:
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.
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.