1.
Introduction to OS and
Unix
With introduction to the
module
OS
An OS is a program which acts as an
interface between computer system users
and the computer hardware.
It provides a user-friendly environment in
which a user may easily develop and
execute programs.
Otherwise, hardware knowledge would be
mandatory for computer programming.
So, it can be said that an OS hides the
complexity of hardware from uninterested
users.
functions
controls the backing store and peripherals such
as scanners and printers
deals with the transfer of programs in and out
of memory
organises the use of memory between
programs
organises processing time between programs
and users
maintains security and access rights of users
deals with errors and user instructions
allows the user to save files to a backing store
provides the interface between the user and the
3
computer issues simple error messages
computer system resources
In general, a computer system has
some resources which may be
utilized to solve a problem. They are
Memory
Processor(s)
I/O
File System
etc.
computer system resources
Mainboard
Motherboard
Motherboard
mainboard
processor
RAM
OS services
The OS manages these resources and
allocates them to specific programs and users.
With the management of the OS, a
programmer is rid of difficult hardware
considerations.
An OS provides services for
Processor Management
Memory Management
File Management
Device Management
Concurrency Control
A kernel connects the application
software to the hardware of a
computer
11
predefined library
Another aspect for
the usage of OS is
that; it is used as a
predefined library for
hardware-software
interaction.
This is why, system
programs apply to
the installed OS
since they cannot
Application Programs
System Programs
Operating System
Machine Language
HARDWARE
hides the complexity
Since we have an already written
library, namely the OS, to add two
numbers we simply write the
following line to our program:
c=a+b;
hides the complexity
in a system where there is no OS installed, we
should consider some hardware work as:
(Assuming an MC 6800 computer hardware)
LDAA $80
LDAB $81
ADDB
STAA $55
Loading the number at memory location 80
Loading the number at memory location 81
Adding these two numbers
Storing the sum to memory location 55
As seen, we considered memory locations
and used our hardware knowledge of the
system.
Portability
In an OS installed machine, since we
have an intermediate layer, our
programs obtain some advantage of
mobility by not dealing with
hardware.
For example, the above program
segment would not work for an 8086
machine, where as the
c = a + b ;
syntax will be suitable for both.
hides the complexity
A simple program
segment with no
hardware
consideration
OS
A more
sophisticated
program segment
with hardware
consideration
Hardware
Machine response
Languag
e
virtual (extended) machine
With the advantage of easier programming
provided by the OS, the hardware, its machine
language and the OS constitutes a new
combination called as a virtual (extended)
machine.
Operating
Machine
Language
Hardware
System
Machine
Machine
Language
Hardware
Virtual
(Extended)
Machine
kernel mode vs user mode
In a more simplistic approach, in fact, OS itself
is a program.
But it has a priority which application programs
dont have.
OS uses the kernel mode of the
microprocessor, whereas other programs use
the user mode.
The difference between two is that; all hardware
instructions are valid in kernel mode, where
some of them cannot be used in the user mode.
History of Operating Systems
It all started with computer hardware in
about 1940s.
ENIAC 1943
History of Operating Systems
ENIAC (Electronic Numerical Integrator
and Computer), at the U.S. Army's
Aberdeen Proving Ground in Maryland.
built in the 1940s,
weighed 30 tons,
was eight feet high, three feet deep, and
100 feet long
contained over 18,000 vacuum tubes that
were cooled by 80 air blowers.
History of Operating Systems
Computers were using vacuum tube
technology.
ENIACs vacuum tubes
History of Operating
Systems
ENIACs backside
1.2 History of Operating Systems
Programs were loaded into memory manually using switches, punched
cards, or paper tapes.
ENIAC : coding by cable connections
History of Operating
Systems
punch card
History of Operating
Systems
History of Operating
Systems
Paper tape
History of Operating
Systems
1.2 History of Operating Systems
Babbages analytical engine
(designed in 1840s by Charles Babbage, but could not be constructed by him.
An earlier and simpler version is constructed in 2002, in London )
http://www.computerhistory.org/babbage/
History of Operating Systems
Ada Lovalence (at time of Charles
Babbage) wrote code for analytical
engine to compute Bernulli Numbers
History of Operating
Systems
As time went on, card readers, printers,
and magnetic tape units were developed
as additional hardware elements.
Assemblers, loaders and simple utility
libraries were developed as software
tools.
Later, off-line spooling and channel
program methods were developed
sequentially.
History of Operating Systems
Commodore PET,
1977
History of Operating Systems
Finally, the idea of multiprogramming
came.
Multiprogramming means sharing of
resources between more than one
processes.
By multiprogramming the CPU, time is
not wasted, because, while one process
moves on some I/O work, the OS picks
another process to execute till the current
History of Operating Systems
With the development of interactive
computation in 1970s, time-sharing
systems emerged.
In these systems, multiple users have
terminals (not computers) connected to a
main computer and execute her task in
the main computer.
History of Operating Systems
Main computer; having a
CPU executing processes by
utilization of the OS, (e.g.
UNIX).
Terminals are connected to
the main computer and used
for input and output. No
processing is made. They do
not have CPUs.
History of Operating Systems
Another computer system is the
multiprocessor system having
multiple processors sharing memory and
peripheral devices.
With this configuration, they have
greater computing power and higher
reliability.
History of Operating Systems
Multiprocessor systems are classified into
two as tightly-coupled and looselycoupled (distributed).
In the tightly-coupled one, each
processor is assigned a specific duty but
processors work in close association,
possibly sharing the same memory.
In the loosely coupled one, each
processor has its own memory and copy
History of Operating Systems
Use of the networks required OSs appropriate for
them.
In network systems, each process runs in its
own machine but the OS have access to other
machines.
By this way, file sharing, messaging, etc. became
possible.
In networks, users are aware of the fact that s/he
is working in a network and when information is
exchanged. The user explicitly handles the
transfer of information.
History of Operating Systems
Each is a computer having its own
CPU, RAM, etc. An OS supporting
networks is installed on them.
History of Operating Systems
Distributed systems are similar to networks.
However in such systems, there is no need to
exchange information explicitly, it is handled
by the OS itself whenever necessary.
With continuing innovations, new architectures
and compatible OSs are developed. But their
details are not in the scope of this course since
the objective here is to give only a general
view about developments in OS concept.
Common OSs
Windows
Windows is an operating system owned and operated by
Microsoft.
It differs from open source systems in that only Microsoft has
the ability to make changes to the code.
However, it also differs from Mac OS X in that it can be installed
on a variety of different computers from a host of competing
manufacturers, offering the user more freedom of choice when
it comes to hardware.
According to Net Market Share, Windows is the most widely
used operating system
Mac OS X
While a version of Mac OS X comes pre-installed on all Apple
Macintosh computers, users must pay if they wish to use newer
versions when they become available.
The system is not open source, so only Apple developers have
the ability to legitimately make alterations or improvements to
40
its code.
Common OSs
Android
Android is a "mobile" operating system maintained
by the Open Handset Alliance, a group of
companies and organizations that contribute to the
system's development under the management of
Google Inc
The system is an "open standard," meaning that an
entire community of developers can alter the
software, not just Google. Android comes preinstalled on smartphones and tablet PCs for which it
was designed.
41
Common OSs
Linux
Linux is a family of open-source operating
systems, which means they can be modified and
distributed by anyone around the world.
This is different from proprietary software like
Windows, which can only be modified by the
company that owns it (Microsoft).
The advantages of Linux are that it is free, and
there are many different distributionsor versions
you can choose from.
Each distribution has a different look and feel, and
the most popular ones include Ubuntu, Mint, and
Fedora.
Linux is named after Linus Torvalds, who created
the Linux kernel in 1991.
42
43
Market share
2013 worldwide device shipments by operating
system
Whitney, Lance (7 January 2014). "Android device shipments to top 1
billion this year -- Gartner".
44
What is Unix ?
The UNIX operating system is a set of programs
that act as a link between the computer and
the user.
The computer programs that allocate the
system resources and coordinate all the details
of the computer's internals is called the
operating system or kernel.
Users communicate with the kernel through a
program known as the shell. The shell is a
command line interpreter; it translates
commands entered by the user and converts
them into a language that is understood by the
kernel.
45
About Unix
Unix was originally developed in 1969 by a
group of AT&T employees at Bell Labs,
including Ken Thompson, Dennis Ritchie,
Douglas McIlroy, and Joe Ossanna.
There are various Unix variants available in
the market. Solaris Unix, AIX, HP Unix and
BSD are few examples. Linux is also a flavor
of Unix which is freely available.
Several people can use a UNIX computer at
the same time; hence UNIX is called a
multiuser system.
A user can also run multiple programs at the
46
same time; hence UNIX is called multitasking.
Unix Architecture
Here is a basic block diagram of a UNIX
system
47
Understand the general design of the
Unix operating system including the
kernel, file system and the shell.
Main Parts of Unix
The main concept that unites all versions of UNIX is
the following four basics
Kernel: The kernel is the heart of the operating
system. It interacts with hardware and most of the
tasks like memory management, task scheduling
and file management.
Shell: The shell is the utility that processes your
requests. When you type in a command at your
terminal, the shell interprets the command and
calls the program that you want. The shell uses
standard syntax for all commands. C Shell, Bourne
Shell and Korn Shell are most famous shells
which
48
Main Parts of Unix
Commands and Utilities: There are various
command and utilities which you would use in
your day to day activities. cp, mv, cat and grep
etc. are few examples of commands and utilities.
There are over 250 standard commands plus
numerous others provided through 3rd party
software. All the commands come along with
various optional options.
Files and Directories: All data in UNIX is
organized into files. All files are organized into
directories. These directories are organized into a
49
tree-like structure called the filesystem.
FUNCTIONS OF THE KERNEL
kernel is the Engine of any Operating System, so all
the vital functions should be controlled and
managed by kernel itself. There are various tasks
and functions of a kernel but some of the important
are given below:
1.
2.
Resource allocation- The kernel's primary function is
to manage the computer's resources and allow other
programs to run and use these resources. These
resources are- CPU, Memory and I/O devices.
Process Management- A process defines
which memory portions the application can
access. The main task of a kernel is to allow the
execution of applications and support them with
features such as hardware abstraction.
To run an application, a kernel first set up an address space for the
application, then loads the file containing the application's
50
code
KERNEL
3.
4.
Memory Management- The kernel has full access to
the system's memory. It allows processes to safely
access this memory as they require it.
I/O Device Management- To perform useful
functions, processes need access to the peripherals
connected to the computer, which are controlled by
the kernel through Device Drivers. A device driver is
a computer program that enables the operating
system to interact with a hardware device. It provides
the operating system with information of how to
control and communicate with a certain piece of
hardware.
kernel maintains a list of available devices. A device
manager first performs a scan on different hardware buses,
such as Peripheral Component Interconnect (PCI) or Universal
Serial Bus (USB), to detect installed devices, then searches for
51
the appropriate drivers. The kernel provides the I/O
to allow
A
KERNEL
5.
6.
Inter- Process Communication- Kernel
provides methods for Synchronization and
Communication between processes, called InterProcess Communication (IPC). There are various
approaches of IPC say, semaphore, shared
memory, message queue, pipe (or named fifo),
etc.
Scheduling- In a Multitasking system, the kernel
will give every program a slice of time and switch
from process to process so quickly that it will
appear to the user as if these processes were
being executed simultaneously. The kernel uses
Scheduling Algorithms to determine which
process is running next and how much time it will
52
be given. The algorithm sets priority among
the
FUNCTIONS OF THE KERNEL
7.
8.
System Calls and Interrupt Handling- A
system call is a mechanism that is used by the
application program to request a service from the
operating system. System calls include close,
open, read, wait and write. To access the services
provided by the kernel we need to invoke the
related kernel functions. Most kernels provide a C
Library or an API, which in turn invokes the related
kernel functions.
Security or Protection Management- Kernel
also provides protection from faults (error control)
and from malicious behaviors (Security). One
approach toward this can be Language based
protection system, in which the kernel will only
allow code to execute which has been produced
53
Explain the function of the Unix kernel
The UNIX Filesystem
The task of the filesystem is to provide a way to
store data, in an organised structure, and
retrieve it when requested
On one system, there may be a large
accounting application, which will store details
of financial transactions.
At the other end of the scale, an individual may
use a system to store private letters, or college
notes.
Someone else may store an address book,
phone numbers, and their diary on the system.
Of course, one system could be used for any or
all of these applications, and endless others.
54
They all have one thing in common: the need to
the file concept
The basic 'unit' of the filesystem is, as you may
guess, the 'file'.
To understand the concept of a file, think of a blank
piece of paper.
At first, it contains nothing. However, you can write on it,
and you can write anything. Similarly, a 'file' may be
empty, or it may contain any amount of data. The data it
contains can be anything, for example a list of phone
numbers, a letter to a customer, or your company's
accounts. In effect, a file is just like a piece of paper - the
main difference is that it may store any amount of data.
The only other thing to note about files is that each
one has a name
Everything in Unix is considered to be a file,
including physical devices such as DVD-ROMs,
USB
55
the file concept
A file is a named collection of related
information, usually as a sequence of
bytes, with two views:
Logical (programmers ) view, as the
users see it.
Physical (operating system) view, as it
actually resides on secondary storage.
Explain the file concept of Unix.
56
File attributes
Each file is associated with a collection
of information, known as attributes:
NAME, owner, creator
type (e.g., source, data, binary)
location (e.g., I-node or disk address)
organization (e.g., sequential, indexed,
random)
access permissions
time and date (creation, modification, and
lastcaccessed)
size
variety of other (e.g., maintenance)
57
information
File operations
There are six basic operations for file
manipulation:
create, write, read, delete, reposition r/w
pointer (a.k.a. seek), and truncate (not very
common.)
58
File types
A common implementation technique (as
organizational help with consistent usage) is to
include the type as an extension to the file
name:
Music, video file types
Files are structured internally to meet the
59
expectations of the program(s) that manipulate
File access methods
The information stored in a file can be accessed
in a variety of methods:
Sequential: in order, one record after another.
Direct (random): in any order, skipping the
previous records.
Keyed: in any order, but with particular
value(s); e.g., hash table or dictionary. TLB
lookup is one example of a keyed search.
Other access methods, such as indexed, can be
built on top of the above basic techniques.
IBMs indexed sequential access method (ISAM)
60
is built on random and sequential access.
Everything is a file
Everything is a file" describes one of the defining
features of Unix, and its derivatives that a wide
range of input/output resources such as
documents, directories, hard-drives, modems,
keyboards, printers and even some inter-process
and network communications are simple streams of
bytes exposed through the filesystem name space
Unix does not distinguish between different types
of file.
The advantage of this approach is that the same
set of tools, utilities and APIs can be used on a wide
range of resources.
Understand that Unix does not
distinguish between different types of
file.
61
Directories
A directory is a symbol table, which can be
searched for information about the files. Also,
it is the fundamental way of organizing files.
Usually, a directory is itself a file.
A typical directory entry contains information
(attributes) about a file. Directory entries are
added as files are created, and are removed
when files are deleted.
Common directory structures are:
Single-level (flat): shared by all users.
Two-level: one level for each user.
Tree: arbitrary (sub)-tree for each user.
62
UNIX directory structure
UNIX uses an advanced form of tree structure,
known as directed acyclic-graph (DAG) directory
63
The Filesystem (eg)
/
bin
etc
hollid2
netprog
unix
home/
scully
X
tmp
bin
ls
usr
etc
who
File sharing
Allowing users to share files raises a major issue:
protection.
A general approach is to provide controlled access to
files through a set of operations such as read, write,
delete, list, and append. Then permit users to
perform one or more operations.
One popular protection mechanism is a condensed
version of access list, where the system recognizes
three classifications of users with each file and
directory:
user
group
65
File system services
A file system provides a mapping between the
logical and physical views of a file, through a
set of services and an interface. Simply put, the
file system hides all the device-specific
aspects of file manipulation from users.
The basic services of a file system include:
keeping track of files (knowing location),
I/O support, especially the transmission
mechanism to and from main memory,
management of secondary storage,
sharing of I/O devices,
providing protection mechanisms for
66
information held on the system.
File system abstraction
67