OS Notes Unit-1
OS Notes Unit-1
UNIT I INTRODUCTION
OS Concepts
Define Operating System.
Definition1:
An Operating System (OS) is an interface between a computer user and computer
hardware. It is a software that enables applications to interact with a computer's
hardware.
Definition2
An operating system (OS) is system software that manages computer hardware, software
resources, and provides common services for computer programs.:
Kernel
The software that contains the core components of the operating system is called the kernel.
12. Virtualisation OS
Virtualisation operating systems and hypervisors, allow multiple virtual machines (VMs) to
run on a single physical machine. They enable efficient resource sharing and isolation between
VMs, allowing for better utilisation of hardware resources. Examples include VMware ESXi,
Microsoft Hyper-V, and KVM.
OS Services
Program execution
Operating systems handle many kinds of activities from user programs to system programs like
printer spooler, name servers, file server, etc. Each of these activities is encapsulated as a
process.
A process includes the complete execution context (code to execute, data to manipulate,
registers, OS resources in use). Following are the major activities of an operating system with
respect to program management −
Loads a program into memory.
Executes the program.
Handles program's execution.
Provides a mechanism for process synchronization.
Provides a mechanism for process communication.
Provides a mechanism for deadlock handling.
I/O Operation
An I/O subsystem comprises of I/O devices and their corresponding driver software. Drivers hide
the peculiarities of specific hardware devices from the users.
An Operating System manages the communication between user and device drivers.
I/O operation means read or write operation with any file or any specific I/O device.
Operating system provides the access to the required I/O device when required.
A file represents a collection of related information. Computers can store files on the disk
(secondary storage), for long-term storage purpose. Examples of storage media include magnetic
tape, magnetic disk and optical disk drives like CD, DVD. Each of these media has its own
properties like speed, capacity, data transfer rate and data access methods.
A file system is normally organized into directories for easy navigation and usage. These
directories may contain files and other directions. Following are the major activities of an
operating system with respect to file management −
Program needs to read a file or write a file.
The operating system gives the permission to the program for operation on file.
Permission varies from read-only, read-write, denied and so on.
Operating System provides an interface to the user to create/delete files.
Operating System provides an interface to the user to create/delete directories.
Operating System provides an interface to create the backup of file system.
Communication
In case of distributed systems which are a collection of processors that do not share memory,
peripheral devices, or a clock, the operating system manages communications between all the
processes. Multiple processes communicate with one another through communication lines in the
network.
The OS handles routing and connection strategies, and the problems of contention and security.
Following are the major activities of an operating system with respect to communication −
Two processes often require data to be transferred between them
Both the processes can be on one computer or on different computers, but are connected
through a computer network.
Communication may be implemented by two methods, either by Shared Memory or by
Message Passing.
Error handling
Errors can occur anytime and anywhere. An error may occur in CPU, in I/O devices or in the
memory hardware. Following are the major activities of an operating system with respect to error
handling −
The OS constantly checks for possible errors.
The OS takes an appropriate action to ensure correct and consistent computing.
Resource Management
In case of multi-user or multi-tasking environment, resources such as main memory, CPU cycles
and files storage are to be allocated to each user or job. Following are the major activities of an
operating system with respect to resource management −
The OS manages all kinds of resources using schedulers.
CPU scheduling algorithms are used for better utilization of CPU.
Protection
Considering a computer system having multiple users and concurrent execution of multiple
processes, the various processes must be protected from each other's activities.
Protection refers to a mechanism or a way to control the access of programs, processes, or users
to the resources defined by a computer system. Following are the major activities of an operating
system with respect to protection −
The OS ensures that all access to system resources is controlled.
The OS ensures that external I/O devices are protected from invalid access attempts.
The OS provides authentication features for each user by means of passwords.
System Calls
A system call is a method for a computer program to request a service from the kernel of
the operating system on which it is running.
A system call is a method of interacting with the operating system via programs.
A system call is a request from computer software to an operating system's kernel.
Why System calls?
There are various situations where you must require system calls in the operating system.
Following of the situations are as follows:
1. Process Control
2. File Management
3. Device Management
4. Information Maintenance
5. Communication
Process Control
Process control is the system call that is used to direct the processes. Some process control
examples include creating, load, abort, end, execute, process, terminate the process, etc.
File Management
File management is a system call that is used to handle the files. Some file management
examples include creating files, delete files, open, close, read, write, etc.
Device Management
Device management is a system call that is used to deal with devices. Some examples of device
management include read, device, write, get device attributes, release device, etc.
Information Maintenance
Information maintenance is a system call that is used to maintain information. There are some
examples of information maintenance, including getting system data, set time or date, get time or
date, set system data, etc.
Communication
Communication is a system call that is used for communication. There are some examples of
communication, including create, delete communication connections, send, receive messages,
etc.
CreateProcess() Fork()
Process Control ExitProcess() Exit()
WaitForSingleObject() Wait()
CreateFile() Open()
ReadFile() Read()
File Manipulation
WriteFile() Write()
CloseHandle() Close()
SetConsoleMode() Ioctl()
Device Management ReadConsole() Read()
WriteConsole() Write()
GetCurrentProcessID() Getpid()
Information Maintenance SetTimer() Alarm()
Sleep() Sleep()
CreatePipe() Pipe()
Communication CreateFileMapping() Shmget()
MapViewOfFile() Mmap()
Simple Structure
There are many operating systems that have a rather simple structure. These started as small
systems and rapidly expanded much further than their scope. A common example of this is MS-
DOS. It was designed simply for a niche amount for people. There was no indication that it
would become so popular.
z
It is better that operating systems have a modular structure, unlike MS-DOS. That would lead to
greater control over the computer system and its various applications. The modular structure
would also allow the programmers to hide information as required and implement internal
routines as they see fit without changing the outer specifications.
Layered Structure
One way to achieve modularity in the operating system is the layered approach. In this, the
bottom layer is the hardware and the topmost layer is the user interface.
As seen from the image, each upper layer is built on the bottom layer. All the layers hide some
structures, operations etc from their upper layers.
One problem with the layered structure is that each layer needs to be carefully defined. This is
necessary because the upper layers can only use the functionalities of the layers below them.
Advantages
Disadvantages
Monolith Structure
In monolith structured operating system, a central piece of code called kernel is responsible for
all major operations of an operating system. Such operations includes file management, memory
management, device management and so on. The kernal is the main component of an operating
system and it provides all the services of an operating system to the application programs and
system programs.
The kernel has access to the all the resources and it acts as an interface with application
programs and the underlying hardware. A monolithic kernel structure promotes timesharing,
multiprogramming model and was used in old banking systems.
Advantages
Crash Prone - As Kernel is responsible for all functions, if one function fails entire
operating system fails.
Difficult to enhance - It is very difficult to add a new service without impacting other
services of a monolith operating system.
Micro-Kernel Structure
As in case monolith structure, there was single kernel, in micro-kernel, we have multiple kernels
each one specilized in particular service. Each microkernel is developed independent to the other
one and makes system more stable. If one kernel fails the operating sytem will keep working
with other kernel's functionalities.
Advantages
Reliable and Stable - As multiple kernels are working simultaneously, chances of failure
of operating sytem is very less. If one functionlity is down, operating system can still
provide other functionalities using stable kernels.
Maintainability - Being small sized kernels, code size is maintainable. One can enhance
a microkernel code base without impacting other microkernel code base.
Disadvantages
The UNIX operating system is a set of programs that link the computer and the user. UNIX
operating system was created in the 1960s and has been updated continuously since then.
It is a powerful multi-user, multitasking OS created by AT&T Bell Laboratories. It is quite
popular among scientists, engineers, and academics because of its most valued properties such as
flexibility, portability, network capabilities, etc. It is a stable, multi-user, multitasking system for
servers, PCs, and laptops.
It is written in the C language, enabling the UNIX operating system to operate on various
platforms.
UNIX operating system comes with a Command Line Interface (CLI). UNIX knowledge is
required for actions that aren't covered by graphical software or when there isn't a window
interface available, such as during a telnet session.
Advantages
1. Many large online stores operate their websites on UNIX or Linux servers. It has also
been used to control mobile phones and other electronic devices.
2. It consumes less memory when running complicated programs. It may handle the virtual
memory very effectively. The virtual memory grows as many programs come into the
main memory. In UNIX, most of the jobs are completed with fewer resources.
3. The UNIX operating system is both free and safe, so it is commonly used by web hosting
providers. Domain Name Server (DNS), Dynamic Host Configuration Protocol
(DHCP), and the webserver are all tools used by many web hosting servers.
4. It allows you to open many programs, and all the programs execute in parallel using
multiprocessor technology.
Disadvantages
1. For UNIX, there is no proper documentation available. If the user has an issue, he must
seek the advice of an expert, as obtaining online assistance from the documentation is
quite difficult.
2. UNIX commands are far more difficult to learn than Windows, MS-DOS, and macOS.
3. It is difficult to use for new users. Because most UNIX work is done with commands in
the CLI, beginners must learn various commands. It is designed exclusively for
programmers, not for new users. Some users with a lot of experience have trouble
utilizing the commands since the names of some commands are extremely different.
4. Most of the UNIX commands use cryptic words. It's tough for a non-technical user to
grasp how commands work. Some commands use unusual characters, and it may be
difficult for new programmers to grasp them.
5. The user interface of the UNIX operating system is not attractive.
6. Some variants of UNIX need most memory usage.
Windows uses a Graphical User Interface (GUI). It allows the users to store files, watch
videos, run software, play games, and access the Internet. The first version of Microsoft
Windows is version 1.0 that was released on November 10, 1983.
Microsoft Windows comes in various versions, including Windows XP, Vista, Windows 95,
Windows 7, 8, 10, and 11.
The first business-oriented Windows version, known as Windows NT 3.1, was introduced
in 1993. The next versions, Windows 3.5, 4/0, and Windows 2000, were released.
Microsoft created the various versions of Windows XP for home and the commercial
environment when it was released in 2001.
It was built using common x86 hardware, like AMD and Intel processors. Therefore, it may run
on different hardware, including HP, Dell, Sony systems, and custom-built PCs.
Advantages
1. The Windows platform is suitable for game and software developers. Because Windows
has a large user base, so designers want to create utilities, games, and programming for
the operating system.
2. Windows 10 is intended for use on both touch-screen devices and desktop systems.
Windows 10's user interface is meant to operate better with a Windows gadget.
3. As the Windows operating system is used by 95% of users, most equipment merchants
create drivers for Windows.
Disadvantages
1. Most of Windows's products are paid, such as design programming, games, download
chief, and another popular programming. Users must purchase these products or pay a
monthly charge to use them.
2. Linux operating system is open-source and free to use for anyone, but Windows requires
a purchased license and cannot be used for free. Windows operating system is also
expensive. You'll also need to purchase other Microsoft software, such as MS Office, to
do regular office work on the system.
3. Windows have a high amount of hacker attacks. Hackers may easily crack Windows
security. As a result, Windows users are relying on anti-virus software and must pay
monthly charges to firms to secure their data. In addition, Windows users must keep their
operating systems up to date in order to receive security fixes.
4. Windows operating system support is not ideal for most users. Only a few significant
enterprises may rely on the Windows team for assistance. Common users must look for
forums to fix their problems.
5. To install Windows, the computer will have plenty of RAM, lots of good hard drive
space, and a good graphics card. It is due to the features used in Windows. If you wish to
install graphics applications, such as Photoshop, you should have at least 16 GB of RAM.
What is a Shell?
Def: A shell is a type of computer program called a command-line interpreter that lets Linux and
Unix users control their operating systems with command-line interfaces. Shells allow users to
communicate efficiently and directly with their operating systems.
Def2: A shell is a special user program that provides an interface for the user to use operating
system services. Shell accepts human-readable commands from users and converts them into
something which the kernel can understand. It is a command language interpreter that executes
commands read from input devices such as keyboards or from files.
Korn Shell
Korn Shell, also known as ksh, is a Unix shell that was developed by David Korn in the early
1980s.
The commands can be combined using the pipeline (|) operator. For example, number of
users logged in can be obtained as.
who | wc -l
Filters
Filters are the central commands of the UNIX tool kit. It acts on data file where lines
are records, fields delimited by a character not used by the data (mostly |, default is white
space). The output is a set of records and the input file is unaltered by these commands.
Command Function
headʊused to display the first few records (10 records by default)
head stud Displays first 10 records by default
head -5 stud Displays first 5 records
head -1 stud | wc –c length of first record
tailʊused to display the last few records (10 records by default)
tail stud Displays last 10 records by default
tail -5 stud | tee last5 Last 5 records listed & stored in file last5 using
cutʊused to extract specific fields. The d option specifies the delimiter and
f for specifying the field list. The c option may be used if extraction is done
cut –d \| -f 1,3,4 stud Fields 1,3,4 listed
cut –d \| -f 2-4 stud Fields 2,3,4 listed
paste –d \| list1 list2 merges two cut files list1 and list2
sortʊreorders the file as per ASCII sequence. The t option is used to specify
sort stud Sorted on 1st column by default
sort –t \| +2 stud Sort as per 3rd column
sort –c stud Check if file is sorted using c option
sort –t \| +3 -4 +4 stud Sorting on secondary keys
sort -t \| -nr +4 stud Sort on numeric field using n option, r for
uniq stud Display unique entries in a sorted file
nlʊdisplay file content with lines numbered. The s option is used to specify
nl –s "|" stud Displays entries numbered with separator |
trʊtranslates characters. Can be used to change text case. It works with standard
tr '[a-z]' '[A-Z]' < stud Changes text to upper case
#!/bin/sh
val=`expr 2 + 2`
echo "Total value : $val"
Total value : 4
Arithmetic Operators
+ (Addition) Adds values on either side of the operator `expr $a + $b` will give 30
- (Subtraction) Subtracts right hand operand from left hand operand `expr $a - $b` will give -10
/ (Division) Divides left hand operand by right hand operand `expr $b / $a` will give 2
It is very important to understand that all the conditional expressions should be inside square
braces with spaces around them, for example [ $a == $b ] is correct whereas, [$a==$b] is
incorrect.
All the arithmetical calculations are done using long integers.
Relational Operators
Bourne Shell supports the following relational operators that are specific to numeric values.
These operators do not work for string values unless their value is numeric.
For example, following operators will work to check a relation between 10 and 20 as well as in
between "10" and "20" but not in between "ten" and "twenty".
Assume variable a holds 10 and variable b holds 20 then −
Operato
Description Example
r
It is very important to understand that all the conditional expressions should be placed inside
square braces with spaces around them. For example,
[ $a <= $b ] is correct whereas, [$a <= $b] is incorrect.
Boolean Operators
String Operators
if [ $a == $b ]
then
#If they are equal then print this
echo "a is equal to b"
else
#else print this
echo "a is not equal to b"
fi
Example 3:
Implementing switch statement
CARS="bmw"
case "$CARS" in
#case 1
"mercedes") echo "Headquarters - Affalterbach, Germany" ;;
#case 2
"audi") echo "Headquarters - Ingolstadt, Germany" ;;
#case 3
"bmw") echo "Headquarters - Chennai, Tamil Nadu, India" ;;
esac
The until loop is executed as many times as the condition/command evaluates to false. The
loop terminates when the condition/command becomes true.
Syntax:
until <condition>
do
<command 1>
<command 2>
<etc>
done
Example
a=0
until [ $a -gt 10 ]
do
echo $a
a=`expr $a + 1`
done
To alter the flow of loop statements, two commands are used they are,
1. break
2. continue