0% found this document useful (0 votes)
127 views180 pages

Os Book

Uploaded by

Yogyta Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views180 pages

Os Book

Uploaded by

Yogyta Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 180

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5
1
2
3
4
5
6
7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
1
2
3
4
5
6
7
8
9
10
11
12
Device Controllers
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.
Any device connected to the computer is connected by a plug and socket, and
the socket is connected to a device controller. 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.

Synchronous vs asynchronous I/O


• Synchronous I/O − In this scheme CPU execution waits while I/O
proceeds
• Asynchronous I/O − I/O proceeds concurrently with CPU execution

Communication to I/O Devices


The CPU must have a way to pass information to and from an I/O device.
There are three approaches available to communicate with the CPU and
Device.

• Special Instruction I/O


• Memory-mapped I/O
• Direct memory access (DMA)

Special Instruction I/O


This uses CPU instructions that are specifically made for controlling I/O
devices. These instructions typically allow data to be sent to an I/O device or
read from an I/O device.

Memory-mapped I/O
When using memory-mapped I/O, the same address space is shared by
memory and I/O devices. The device is connected directly to certain main
memory locations so that I/O device can transfer block of data to/from memory
without going through CPU.

While using memory mapped IO, OS allocates buffer in memory and informs
I/O device to use that buffer to send data to the CPU. I/O device operates
asynchronously with CPU, interrupts CPU when finished.
The advantage to this method is that every instruction which can access
memory can be used to manipulate an I/O device. Memory mapped IO is used
for most high-speed I/O devices like disks, communication interfaces.

Direct Memory Access (DMA)


Slow devices like keyboards will generate an interrupt to the main CPU after
each byte is transferred. If a fast device such as a disk generated an interrupt
for each byte, the operating system would spend most of its time handling
these interrupts. So a typical computer uses direct memory access (DMA)
hardware to reduce this overhead.
Direct Memory Access (DMA) means CPU grants I/O module authority to read
from or write to memory without involvement. DMA module itself controls
exchange of data between main memory and the I/O device. CPU is only
involved at the beginning and end of the transfer and interrupted only after
entire block has been transferred.
Direct Memory Access needs a special hardware called DMA controller
(DMAC) that manages the data transfers and arbitrates access to the system
bus. The controllers are programmed with source and destination pointers
(where to read/write the data), counters to track the number of transferred
bytes, and settings, which includes I/O and memory types, interrupts and
states for the CPU cycles.

The operating system uses the DMA hardware as follows −

Step Description

1 Device driver is instructed to transfer disk data to a buffer address X.

2 Device driver then instruct disk controller to transfer data to buffer.

3 Disk controller starts DMA transfer.

4 Disk controller sends each byte to DMA controller.


5 DMA controller transfers bytes to buffer, increases the memory address, decreases the
counter C until C becomes zero.

6 When C becomes zero, DMA interrupts CPU to signal transfer completion.

Polling vs Interrupts I/O


A computer must have a way of detecting the arrival of any type of input. There
are two ways that this can happen, known as polling and interrupts. Both of
these techniques allow the processor to deal with events that can happen at
any time and that are not related to the process it is currently running.

Polling I/O
Polling is the simplest way for an I/O device to communicate with the
processor. The process of periodically checking status of the device to see if
it is time for the next I/O operation, is called polling. The I/O device simply puts
the information in a Status register, and the processor must come and get the
information.
Most of the time, devices will not require attention and when one does it will
have to wait until it is next interrogated by the polling program. This is an
inefficient method and much of the processors time is wasted on unnecessary
polls.
Compare this method to a teacher continually asking every student in a class,
one after another, if they need help. Obviously the more efficient method would
be for a student to inform the teacher whenever they require assistance.

Interrupts I/O
An alternative scheme for dealing with I/O is the interrupt-driven method. An
interrupt is a signal to the microprocessor from a device that requires attention.
A device controller puts an interrupt signal on the bus when it needs CPU’s
attention when CPU receives an interrupt, It saves its current state and invokes
the appropriate interrupt handler using the interrupt vector (addresses of OS
routines to handle various events). When the interrupting device has been
dealt with, the CPU continues with its original task as if it had never been
interrupted.
I/O software is often organized in the following layers −
• User Level Libraries − This provides simple interface to the user
program to perform input and output. For example, stdio is a library
provided by C and C++ programming languages.
• Kernel Level Modules − This provides device driver to interact with the
device controller and device independent I/O modules used by the
device drivers.
• Hardware − This layer includes actual hardware and hardware
controller which interact with the device drivers and makes hardware
alive.
A key concept in the design of I/O software is that it should be device
independent where it should be possible to write programs that can access
any I/O device without having to specify the device in advance. For example,
a program that reads a file as input should be able to read a file on a floppy
disk, on a hard disk, or on a CD-ROM, without having to modify the program
for each different device.

Device Driver in Operating System


Operating System takes help from device drivers to handle all I/O devices. A
device driver is a computer program that operates or controls a particular
device attached to a computer or automaton. A driver provides a software
interface to hardware devices, enabling operating systems and other computer
programs to access hardware functions without knowing precise details about
the hardware being used.

Device Drivers are important for a computer system to work properly. Without
a device driver, the particular hardware fails to work accordingly, which means
it fails in doing a particular action for which it has been created.
Drivers are hardware-dependent and operating-system-specific. They usually
provide the interrupt handling required for any necessary asynchronous time-
dependent hardware interface.

A driver communicates with the device through the computer bus or


communications subsystem to which the hardware connects. Once the device
sends data back to the driver, the driver may invoke routines in the original
calling program. When a calling program invokes a driver's routine, the driver
issues the commands to the device.

Purpose of a Device Driver


The main purpose of device drivers is to provide abstraction by acting as a
translator between a hardware device and the applications or operating systems
that use it. Programmers can write higher-level application code independently
of whatever specific hardware the end-user is using.

For example, a high-level application interacting with a serial port may have
"send data" and "receive data" functions. A device driver implementing these
functions would communicate to the particular serial port controller installed at
a lower level on a user's computer.

The commands needed to control a 16550 UART are different from those
needed to control an FTDI serial port converter. Still, each hardware-specific
device driver abstracts these details into the same or similar software interface.

How does Device Driver work?


When you get a peripheral device such as a 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 it.

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 connects the device with the computer. Device Drivers depend upon the
Operating System's instruction to access the device and performing any
particular action. After the action, they also show their reactions by delivering
output or message from the hardware device to the Operating system.
Device drivers work within the kernel layer of the operating system. The kernel
is the part of the operating system that directly interacts with the system's
physical structure. Instead of accessing a device directly, an operating system
loads the device drivers and calls the specific functions in the driver software to
execute specific tasks on the device. Each driver contains the device-specific
codes required to carry out the actions on the device.

Card reader, controller, modem, network card, sound card, printer, video card,
USB devices, RAM, Speakers etc., need Device Drivers to operate. For example,
a printer driver tells the printer which format to print after getting instructions
from OS. Similarly, A sound card driver is there because the 1's and 0's data of
an MP3 file is converted to audio signals, and you enjoy the music.

Types of Device Driver


For almost every device associated with the computer system, a Device Driver
exists for the particular hardware. But it can be broadly classified into the
following two types, such as:
1. Kernel-mode Device Driver

This Kernel-mode device driver includes some generic hardware that loads with
an operating system as part of the OS. These are BIOS, motherboard,
processor, and some other hardware that are part of kernel software. These
include the minimum system requirement device drivers for each operating
system.

o BIOS: BIOS (basic input/output system) is the most basic computer


driver in existence. It is designed to be the first program that boots when
a PC turns on. The BIOS is stored on memory built into the motherboard
and is designed to boot the hardware connected to the PC, including the
hard drives, video display output, keyboard and mouse.
o Motherboard Drivers: Motherboard drivers are small programs that are
read by either Windows or Linux and allow for basic computer functions
while inside the operating system. These drivers normally include
programs that allow broadband ports, USB ports and I/O ports for the
mouse and keyboard. Depending on the making of the motherboard,
the drivers may also have basic drivers for video and audio support.

2. User-mode Device Driver

Other than the devices brought by the kernel for working of the system, the
user also brings some devices for use during the using of a system that devices
need device drivers to functions those drivers fall under User mode device
driver. For example, the user needs any plug and play action that comes under
this.

Applications of Device Drivers


Because of the diversity of modern hardware and operating systems, drivers
operate in many different environments. Device drivers may interface with
Printers, Video adapters, Network cards, Sound cards, Local buses of various
sorts, Image scanners, Digital cameras, Digital terrestrial television tuners, IrDA
adapters, and Implementing support for different file systems. It also interfaces
with:

o Low-bandwidthI/O buses of various sorts for pointing devices such as


mice, keyboards, etc.
o Computer storagedevices such as hard disk, CD-ROM, and floppy disk
buses (ATA, SATA, SCSI, SAS)
o The radio-frequency communication transceiver adapters are used for
short-distance and low-rate wireless communication in home
automation, such as Bluetooth Low Energy (BLE), Thread, ZigBee, and Z-
Wave).

Choosing and installing the correct device drivers for given hardware is often a
key component of computer system configuration. Common levels of
abstraction for device drivers include:

1. For hardware:

o Interfacing directly
o Writing to or reading from a device control register
o Using some higher-level interface (e.g. Video BIOS)
o Using another lower-level device driver (e.g. file system drivers using disk
drivers)
o Simulating work with hardware while doing something entirely different.

2. For software:

o Allowing the operating system direct access to hardware resources


o Implementing only primitives
o Implementing an interface for non-driver software (e.g. TWAIN)
o Implementing a language, sometimes quite high-level (e.g. PostScript)
1
2
3
4
5
6
7
8
9
10
11
Case study on Linux
What is Linux?
Linux is a Unix-like, open source and community-developed operating system (OS) for

computers, servers, mainframes, mobile devices and embedded devices. It is supported on

almost every major computer platform, including x86, ARM and SPARC, making it one of

the most widely supported operating systems.

How is the Linux operating system used?


Every version of the Linux OS manages hardware resources, launches and handles

applications, and provides some form of user interface. The enormous community for

developers and wide range of distributions means that a Linux version is available for

almost any task, and Linux has penetrated many areas of computing. For example, Linux

has emerged as a popular OS for web servers such as Apache, as well as for network

operations, scientific computing tasks that require huge compute clusters, running

databases, desktop and endpoint computing, and running mobile devices with OS versions

like Android.

The Linux OS can be found in many different settings, supporting many different use

cases. Linux is used in the following ways:

• Server OS for web servers, database servers, file servers, email servers and

any other type of shared server. Designed to support high-volume and

multithreading applications, Linux is well-suited for all types of server

applications.

• Desktop OS for personal productivity computing. Linux is an open source and

freely available desktop environment for users who prefer it to commercial

OSes.
• Headless server OS for systems that do not require a graphical user interface

(GUI) or directly connected terminal and keyboard. Headless systems are

often used for remotely managed networking server and other devices.

• Embedded device or appliance OS for systems that require limited computing

function. Linux is used as an embedded OS for a variety of applications,

including household appliances, automotive entertainment systems and

network file system appliances.

• Network OS for routers, switches, domain name system servers, home

networking devices and more. For example, Cisco offers a version of the

Cisco Internetwork Operating System (IOS) that uses the Linux kernel.

• Software development OS for enterprise software development. Although

many development tools have been ported to Windows or other OSes, Linux

is home to some of the most widely used open source software development

tools. For example, git for distributed source control; vim and emacs for

source code editing; and compilers and interpreters for almost every

programming language.

• Cloud OS for cloud instances. Major cloud computing providers offer access

to cloud computing instances running Linux for cloud servers, desktops and

other services.

Linux is highly configurable and depends on a modular design that enables users to

customize their own versions of Linux. Depending on the application, Linux can be

optimized for different purposes such as:

• networking performance;

• computation performance;
• deployment on specific hardware platforms; and

• deployment on systems with limited memory, storage or computing

resources.

Users can choose different Linux distributions for specific applications or adapt a

specific distribution to incorporate custom kernel configurations.

Linux distributions
Since its initial development, Linux has adopted the copyleft stipulations of the Free Software

Foundation which originated the GNU GPL. The GPL says that anything taken for free and

modified must be distributed for free. In practice, if Linux or other GNU-licensed components

are developed or modified to create a new version of Linux, that new version must be distributed

for free. This prevents a developer or other groups from profiting unfairly from the freely

available work of others.

available.
specific
Hundreds goal,
Distributions
of philosophy,
different Linux
usually
function
versions,
distinguish
or target
also
market.
themselves
known asfrom
distributions
the pack by
or addressing
distros, area

There are distributions tailored for specific target functions, such as servers, desktops, gaming,

security, or embedded devices including Raspberry Pi systems. Most modern distributions are

precompiled and ready to use, while others like Gentoo Linux consist of source code that a user

can compile locally during initial installation to optimize their system configuration. Knoppix

Linux is one of many distros used to recover damaged hard drives and perform other technical

support tasks. Information security professionals use Kali Linux for penetration testing and

other security-related tasks.

Linux has become an important component of automaker entertainment systems. Many

automakers have joined Automotive Grade Linux (AGL), an open source project hosted by the
Linux Foundation. For example, Toyota and Lexus vehicles use AGL for their infotainment

systems.

Linux distributions may be community-developed, like Debian, Slackware and Gentoo. Other

distributions are commercial and intended for enterprise use, including Red Hat Enterprise

Linux and SUSE Linux Enterprise Server. Many distributions use a combination of community-

and corporate-supported development, such as Red Hat's Fedora, openSUSE from SUSE and

Ubuntu from Canonical.

This chart highlights nine popular Linux distributions.


The GNU GPL does not prohibit intellectual ownership, and it is commonplace for creators of

Linux components to hold copyrights on the various components. The GNU GPL ensures that

those components remain free and freely distributed. While the software remains free, it is

common for some commercial distributions to charge for value-added services, such as support

or custom development services.

Linux components and terminology


The Linux OS system incorporates several different components, including:
• Bootloader. A bootloader is responsible for managing the boot process of the

computer and for starting the Linux kernel. It can also be used to manage systems

that boot more than one OS.

• Kernel. The core of the Linux system, the kernel handles network access,

schedules processes or applications, manages basic peripheral devices and

oversees all file system services. The Linux kernel is the software that interfaces

directly with the computer hardware.

• Init system. The first process to run once the kernel is loaded. A process is an

instance of a program running on a computer, and the init system initializes the

system to enable it to run other processes. Init is a daemon program that acts as

the parent process to all other processes running on the system. Init can be

configured to start specific processes at system initialization. For example, when

the system will be running a web server the init system can be configured to load

all necessary web server software.

• Daemons. This is a program that runs in the background, handling requests for a

service. A web server running on a Linux server depends on a daemon, usually

named httpd, to listen for web server requests.

• Graphical server. This is the software that controls how graphics are displayed on

a computer. Without a graphical server, users can only interact with the Linux

system through a command-line interface. The X Window System, also known as

X11 or X, is the most common graphical server for Linux, though not the only

one. X runs as a server daemon on the system and is called upon by applications

when graphical output is required.

• Desktop environment. This is the collection of applications and user interface

controls with which users interact when using Linux as a desktop platform.

Access to the desktop environment is usually controlled through the X Window

System or another graphical system. Each desktop environment defines its own

look, including the way graphical elements like windows, pull-down menus and
files are displayed and manipulated. The desktop environment will also include a

set of default applications for managing files and folders, text editing, running a

command-line session and other common tasks.

• Applications. This is the software that is installed during and after the initial

Linux installation. Most Linux distributions include thousands of different

applications, including both for a networked server and for desktop use.

The Linux kernel mediates interaction between applications and system hardware such
as CPU, memory and devices like storage or printers.

While these components are included in most Linux distributions, they are not necessarily part

of every deployed Linux system. For example, a Linux-based server may not require a graphical

server, desktop environment or applications.

But it is really the many outside developers and GNU projects that offer high-level functions

to the Linux kernel to provide a fully realized OS. For example, there are modules to provide a

command-line interface, implement a GUI, manage security, and offer video input or audio

services -- each of which can be modified and optimized to form unique distributions for

specific tasks.
Desktop environments can also vary widely with different approaches to GUI design and

default applications. The two most popular desktop environments are:

• The GNOME desktop environment, which is included in most popular Linux

distributions, is the default desktop for many. Designed to be easy to use and

reliable, GNOME spawned other desktop environment projects, including

MATE, Cinnamon and Unity.

• The KDE desktop environment is the primary alternative to GNOME. KDE is

also designed to be easy to use and reliable. It has spawned other projects,

including the Trinity Desktop Environment.

Package manager software typically adds, updates or removes software components under the

Linux OS. Package managers enable users to install additional software not included with their

distributions. Examples of software package managers include RPM Package Manager, dpkg,

OpenPKG and Zero Install.

How the Linux operating system works


The Linux OS follows a modular design that is the key to its many variations and distributions.

All Linux distributions are based on the Linux kernel, but they can differ depending on factors

such as:

• Kernel version. Distributions can be configured with more recent versions to

incorporate newer features or with older versions to be more stable.

• Kernel modules. This is software that can be loaded and unloaded into the kernel

to extend functionality without rebooting. Kernel modules are often used to

support:

o device drivers, which use code that controls how attached devices

operate;
o file system drivers, which use code that controls how the kernel

works with different file systems; and

o system calls, which use code that controls how programs request

services from the kernel.

• Configuration options. Linux kernels compiled with configuration options set to

include only device or file system drivers are used for some specialized

distributions; for example, compiling a kernel for a wireless device without any

wired network device drivers.

The Linux kernel is the one thing that all systems running Linux have in common. Linux works

by:

• Loading and booting a Linux kernel.

• Once booted, the kernel manages all system input and output. The system is

initialized, and processes can be started.

• As system processes are started, the system can be used for processes that include

network server functions, commands entered interactively via command line,

desktop applications or any application or program.

While the kernel may be almost identical -- with some divergence for configuration and

compilation differences -- the user experience can vary widely, depending on how the Linux

system is being used. For example, some Linux use cases with widely different user experiences

include:

• Desktop productivity systems, such as those used by software developers or other

professionals. Software development workstations may be optimized for


performance, while desktops for administrative professionals may be optimized

for use of desktop productivity tools.

• Network servers may not even include a terminal for direct access. These

headless servers are managed remotely through network terminal or Windows

sessions. Servers may be used by many but should be directly accessed only by

authorized system admins.

• Thin clients enable users to access a rich desktop environment from a lightweight

device. This includes Raspberry Pi single-card computers and Google

Chromebooks.

When using Linux with a desktop environment as a GUI, Linux works much the same as any

GUI-based OS. Applications and other resources can be opened by clicking on icons, and files

can be moved, copied or deleted using a mouse or trackpad.

Likewise, using the Linux command line is similar to any modern OS command line:

This example shows the default command prompt in the Windows Subsystem for Linux. The

prompt displays, from left to right, userID@hostname, and the full path of the current directory

followed by the "$" symbol.

Experience Linux on Windows 10 (or later) desktop by running the Windows Subsystem
for Linux.
The pros and cons of using Linux
Some advantages of using Linux include:

• Open source software. The Linux kernel is released under the GNU GPL

open source software license. Most distros include hundreds of applications, with

many options in almost every category. Many distributions also include

proprietary software, such as device drivers provided by manufacturers, to

support their hardware.

• Licensing costs. Unlike Microsoft Windows or Apple macOS, Linux has no

explicit licensing fees. While system support is available for a fee from many

Linux vendors, the OS itself is free to copy and use. Some IT organizations have

increased their savings by switching their server software from a commercial OS

to Linux.

• Reliability. Linux is considered a reliable OS and is well-supported with

security patches. Linux is also considered to be stable, meaning it can run in most

circumstances. Linux also copes with errors when running software and

unexpected input.

• Backward compatibility. Linux and other open source software tend to be

updated frequently for security and functional patches, while retaining core

functionality. Configurations and shell scripts are likely to work unchanged even

when software updates are applied. Unlike commercial software vendors that roll

out new versions of their OSes along with new ways to work, Linux and open

source applications generally don't change their modes of operation with new

releases.

• Many choices. Between the hundreds of available distributions, thousands

of applications and almost infinite options for configuring, compiling and

running Linux on almost any hardware platform, it is possible to optimize Linux

for almost any application.


Some disadvantages of using Linux include:

• Lack of established standard. There is no standard version of Linux, which may

be good for optimizing Linux for particular applications, but less so for deploying

standardized server or desktop images. The wide range of options can complicate

support as a result.

• Support costs. While an organization can acquire Linux freely without licensing

fees, support is not free. Most enterprise Linux distributors like SUSE and Red

Hat offer support contracts. Depending on the circumstances, these license fees

can reduce savings significantly.

• Proprietary software. Desktop productivity software like Microsoft Office cannot

be used on Linux desktops, and other proprietary software may be unavailable for

Linux platforms.

• Unsupported hardware. While many hardware manufacturers make Linux device

drivers available for their products, many do not.

• Steep learning curve. Many users struggle to learn to use the Linux desktop or

Linux-based applications.

In some cases, the same Linux attribute can be either an advantage or disadvantage. For

example, having many options for customizing the Linux OS is advantageous for manufacturers

looking for an embedded OS, but it is a disadvantage for enterprises that want a desktop OS

that can be used by a wide range of end users.

History of Linux
Linus Torvalds started working on Linux as a replacement to the Minix OS while at the

University of Helsinki in Finland. Torvalds recognized the work done on the GNU Project in

1983, which intended to create a complete, Unix-compatible OS comprised entirely of free

software, and noted the GNU as a model for distribution. However, the work on GNU had not
been finished by the time Torvalds sought a Minix replacement, prompting him to develop an

alternate OS kernel dubbed Linux -- a contraction of Linus' Unix -- and adopt the GNU GPL.

Torvalds released the Linux kernel in September 1991. A community of developers worked to

integrate GNU components with Torvalds' kernel to create a complete, free OS known

collectively as Linux. Torvalds continues to develop the Linux kernel and a vast developer

community continues to create and integrate a wide range of components. While Linux still

lags Windows and macOS on the desktop, it continues to challenge the proprietary OS vendors

on servers and embedded systems.

You might also like