0% found this document useful (0 votes)
35 views52 pages

1.2 OS Introduction

Uploaded by

080bct035
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)
35 views52 pages

1.2 OS Introduction

Uploaded by

080bct035
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/ 52

Tribhuvan University

Institute of Engineering
Pulchowk Campus
Department of Electronics and Computer Engineering

Operating System
Chapter One
Introduction

Santosh Giri
Asst. Professor, IOE, Pulchowk Campus.
Chapter One: Introduction

Course Outline: 5 hours, 10 Marks

1. Operating System and Function


2. Evolution of Operating System
3. Type of Operating System: Batch, Interactive, Multiprocessing, Time
Sharing and Real-Time System
4. Operating System Components
5. Operating System Structure: Monolithic, Layered, Micro-Kernel, Client-
Server, Virtual Machine
6. Operating System Services
6.1. System calls
6.2. Shell commands
6.3. Shell programming
7. Examples of O. S.: UNIX, Linux, MS-Windows, Handheld OS.
OS Basics
OS is…
 Software layer between hardware and applications

 The OS is ―all the code that you didn’t have to write‖ to


implement your application

4
OS is…
 OS acts as an intermediary between the
user and hardware, Provides a user
interface, Manages resources, etc.
 Most computers have two modes of
operation: kernel mode and user mode.
The operating system runs in kernel mode
(also called supervisor mode).
 In kernel mode, it has complete access to
all the hardware and can execute any
instruction the machine is capable of
executing.
 The rest of the software runs in user mode,
in which only a subset of the machine
instructions is available.
5
OS is…
 An important distinction between the
operating system and the normal (user-
mode) software is that if a user does
not like a particular email reader,
he/she is free to get a different one or
write his own if he so chooses.

 But he/she is not free to write his own


clock interrupt handler, which is part
of the operating system and is
protected by hardware against attempts
by users to modify it.

6
OS Components
OS Components
 Kernel
Core part of OS, Manages CPU, memory, devices
 Shell
- Interface between user and kernel
- CLI vs GUI
- Examples: Bash, PowerShell
 Utilities
- Disk cleanup, task manager
 Applications
Text editors, media players

9
Basic Operations:
Shell, System Calls, Boot, Partitions
Basic Operations
 System Calls
 Interface to request OS services
 Types: process control, file management, device handling
 Examples: fork(), exec(), read(), write()

 Shell Commands and Programming


 Shell command examples: ls, cd, mkdir, grep
 Basic shell script: variables, loops, conditionals

 Boot Process Overview


 Power On -> BIOS/UEFI -> Bootloader -> Kernel -> Init/Systemd

11
OS Components
 MBR vs GPT Partations (Basics)
 MBR: Up to 4 partitions, max 2 TB
 GPT: Modern, up to 128 partitions, larger disks

 UEFI vs Legacy Boot


 UEFI:
Faster, Secure Boot, modern interface
 Legacy :
Older, limited features

12
OS Functions
OS Functions
 Operating systems perform two essentially unrelated
functions:
Operating System as an Extended Machine
The Operating System as a Resource Manager

14
OS Functions As an Extended Machine
:

 The architecture (instruction set, memory organization,


I/O, and bus structure) of most computers at the machine-
language level is awkward to program, especially for
input/output.

 To make this point more concrete, consider modern SATA


(Serial ATA) hard disks used on most computers. A book
(Anderson & co.,2007) describing an early version of the
interface to the disk—what a programmer would have to
know to use the disk—ran over 450 pages.

 Since then, the interface has been revised multiple times


and is more complicated than it was in 2007. Clearly, no
programmer would want to deal with this disk at the
hardware level.

 Instead, a piece of software, called a disk driver, deals with


the hardware and provides an interface to read and write
disk blocks, without getting into the details & OS’s contain
many drivers for controlling I/O devices.

15
OS Functions As an Extended Machine
:

 But even this level is much too low for most


applications. For this reason, all operating systems
provide yet another layer of abstraction for using disks:
files.

 Using this abstraction, programs can create, write, and


read files, without having to deal with the messy details
of how the hardware actually works.

 Good abstractions turn a nearly impossible task into two


manageable ones. The first is defining and
implementing the abstractions. The second is using
these abstractions to solve the problem at hand.

 One abstraction that almost every computer user


understands is the file, as mentioned above.

 The job of the operating system is to create good


abstractions and then implement and manage the
abstract objects thus created.
16
OS Functions As an Resource Manager :

 Scenario: Imagine what would happen if three programs running on some


computer all tried to print their output simultaneously on the same printer. The
first few lines of the printout might be from Program 1, the next few from
Program 2, then some from Program 3, and so forth. The result would be utter
chaos.

 Solution: The operating can bring order to the potential chaos by buffering all
the output destined for the printer on the disk. When one program is finished, the
operating system can then copy its output from the disk file where it has been
stored for the printer, while at the same time, the other program can continue
generating more output, oblivious to the fact that the output is not really going to
the printer (yet).

 In short, this view of the operating system holds that its primary task is to keep
track of which programs are using which resource, to grant resource requests, to
account for usage, and to mediate conflicting requests from different programs
and users.
17
OS Benefits to Applications
 Simpler

 Device-independent
• all disks look the same

 Portable
• The same program runs on Windows95/98/2000/XP/Vista/
Windows7/Windows 8/Windows 10

 Worry less about interference from other applications

18
OS History
A brief history of OS
The dark age (1945 – 55): no OS
Batch systems (1955 – 65)
Multiprogramming (1965 – 80)
PC (and mobile) era (1980 – present)

20
The dark age
 ENIAC (1946): the first computer

 Only a single group of people designed and used it


Protection and virtualization are not needed!

 How to Allocate and Reclaim computation time?


Sign-up sheet on the wall!

21
Batch systems (1955-65)
 Background:
At that time, computers are used only to ―compute‖ (instead
of entertainment, etc.)
Users write a program using a ―punch card‖
• Punch your program into cards
• Bring the cards to computer operators
• Come back after a day to get the result

22
Batch systems (1955-65)
 OS:
Read the first job from the tape
Run it
Write the output to another tape
Read the next job and repeat the process
Similar to the ―sign-up sheet on the wall‖, only now this
process is automated

23
Multiprogramming (1965-80)

 Problems with Batch systems?


Responsiveness
• Do you want to wait for a day just to find out your program doesn’t
compile?
Multiple users cannot concurrently access the computer
Efficiency
• CPU is idle while the computer is doing I/O

 Multiprogramming
Multiple tasks are performed during the same period of time, as
if they are executed concurrently
Now multiple users can use the same machine simultaneously

24
PC-era (1980-present)
 IBM introduces PC in 1981, using Intel
processors
 Looking for an OS for its PC

 At that time, an OS called CP/M is already


working on Intel CPUs
 Bill Gates initially suggested IBM to contract CP/M
 CP/M founder refused to meet with IBM
 IBM came back to Bill Gates, and he purchased an
OS named DOS (Disk Operating System created
by Tim Paterson, modified it, and renamed it MS-
DOS

28
Graphical User Interface (GUI)
 The interface of the early OSes is command-line

 Researchers in Xerox-PARC built the first OS with a


graphic user interface
Steve Jobs visited PARC, saw the GUI, and used it in
Apple’s Lisa (1983), later Macintosh (1984)
Microsoft introduced Windows in 1985

29
Summary
 The First Generation (1940's to early 1950's)
 No Operating System
 All programming was done in absolute machine language, often by wiring up plug-boards
to control the machine’s basic functions.

 The Second Generation (1955-1965)


 First operating system was introduced in the early 1950's.It was called GMOS
 Created by General Motors for IBM's machine the 701.
 Single-stream batch processing systems

 The Third Generation (1965-1980)


 Introduction of multiprogramming
 Development of Minicomputer

 The Fourth Generation (1980-Present Day)


 Development of PCs
 Birth of Windows/MaC OS
Starting an Operating System(Booting)

 Power On Switch sends electricity to the motherboard  BIOS will then look for a small sector at the very beginning of your
on a wire called the Voltage Good line. primary hard disk called MBR.
 If the power supply is good, then the BIOS (Basic  The MBR contains a list, or map, of all of the partitions on your
Input/Output System) chip takes over. computer‘s hard disk (or disks).
 In Real Mode, CPU is only capable of using  After the MBR is found the Bootstrap Loader follows basic
approximately 1 MB of memory built into the instructions for starting up the rest of the computer, including the
motherboard. operating system.
 The BIOS will do a Power-On Self Test (POST) to  In Early Kernel Initialization stage, a smaller core of the Kernel is
ensure all hardware works. activated.
 This core includes the device drivers needed to use computer‘s RAM
chips.
Functions of the
Operating System
Functions of Operating
System
Process
Management

User Interface Memory


Management

OS functions
File
Security & Management
Protection

I/O
Management
Types of
Operating System
Types of Operating Systems
1. Batch Operating System

2. Multiprogramming Operating System


3. Time-Sharing OS
4. Multiprocessing OS

5. Distributed OS
6. Network OS
7. Real Time OS

8. Embedded OS
1. Batch Operating System
 The users of this type of operating system do not interact with the computer
directly.
 Each user prepares his job on an off-line device like punch card and submits it to the
computer operator
 There is an operator which takes similar jobs having the same requirement and
groups them into batches.

Examples of Batch based Operating Systems:

IBM's MVS
2. Multiprogramming Operating System:

 This type of OS is used to execute more than one jobs simultaneously by a single
processor.

 It increases CPU utilization by organizing jobs so that the CPU always has one job to
execute.

 Multiprogramming operating systems use the mechanism of job scheduling and CPU
scheduling.
3. Time-Sharing Operating Systems

 Each task is given some time to execute so that all the tasks work smoothly.
 These systems are also known as Multi-tasking Systems.
 The task can be from a single user or different users also.
 The time that each task gets to execute is called quantum.
 After this time interval is over OS switches over to the next task.
 Examples of Time-Sharing OS
 Multics
4. Multiprocessor operating systems

 Multiprocessor operating systems are also known as parallel OS or tightly


coupled OS.

 Such operating systems have more than one processor in close


communication, sharing the computer bus, the clock, and sometimes memory
and peripheral devices.

 It executes multiple jobs at the same time and makes the processing faster.

 It supports large physical address space and larger virtual address space.

 If one processor fails then the other processor should retrieve the interrupted
process state so the execution of the process can continue.

 Example: Windows NT, Digital UNIX, OS/2


5. Distributed Operating
System
 Various autonomous interconnected computers communicate with each other using a
shared communication network.

 Independent systems possess their own memory unit and CPU.

 These are referred to as loosely coupled systems.

 Examples:- Locus, DYSEAC


7. Real-Time Operating System

 These types of OSs serve real-time systems.

 The time interval required to process and respond to inputs is very


small.

 This time interval is called response time.

 Real-time systems are used when there are time requirements that are
very strict like
 missile systems,
 air traffic control systems,
 robots, etc.
8. Embedded Operating System

 An embedded operating system is one that is built into the circuitry of an electronic
device.

 Embedded operating systems are now found in automobiles, bar-code scanners, cell
phones, medical equipment, and personal digital assistants.

 The most popular embedded operating systems for consumer products, such as
PDAs, include the following:
 Windows XP Embedded
 Windows CE .NET:- it supports wireless communications, multimedia and Web
browsing. It also allows for the use of smaller versions of Microsoft Word,
Excel, and Outlook.
 Palm OS:- It is the standard operating system for Palm-brand PDAs as well as
other proprietary handheld devices.
 Symbian:- OS found in ― smart‖ cell phones from Nokia and Sony Ericsson
Popular types of OS
 Desktop Class
 Windows
 OS X
 Unix/Linux
 Chrome OS

 Server Class
 Windows Server
 Mac OS X Server
 Unix/Linux

 Mobile Class
 Android
 iOS
 Windows Phone
Operating System
Structure
1. Simple Structure
 MS-DOS is an example of such a system.

 In MS-DOS, the interfaces and levels of


functionality are not well separated i.e. no
User vs Kernel mode.

 Another example of limited structuring is


the original UNIX operating system.

 There was no CPU Execution Mode (user


and kernel), so errors in applications
could cause the whole system to crash.

In MS-DOS, applications may


bypass the operating system.
60
2. Monolithic Structure
 In this structure entire OS runs as a single
program in kernel mode i.e. All the services
of OS is contained within the kernel.

 Each procedure in the system is free to call


any other one, Being able to call any
procedure you want is very efficient.

 However, having thousands of procedures


that can call each other without restriction
may also lead to a system that is unwieldy
and difficult to understand.

 Also, a crash in any of these procedures will


take down the entire operating system.

 Example: CP/M

61
3. Layered Architecture of
Operating System
 In this approach, OS is split into various layers
such that all the layers perform different
functionalities.
 Each layer can interact with the one just above
it and the one just below it.
 The lowermost layer which directly deals with
the bare hardware is mainly meant to perform
the functionality of I/O communication and
the uppermost layer which is directly
connected to the application program acts as
an interface between the user and operating
system.
 Example: THE system

62
4. Microkernel Architecture

 The basic idea behind micro kernels is to remove all non-essential services from
the kernel, and implement them as system applications instead, thereby making
the kernel as small and efficient as possible.
 Example: Mach was the first and most widely known microkernel, and now
forms a major component of Mac OSX, QNX, a real-time OS for embedded
systems.

63
5. Hybrid Architecture of
Operating System
 Most OSes today do not strictly adhere to one architecture, but are
hybrids of several.
5.1. Mac OS X

 The Max OSX architecture relies on the Mach microkernel for basic system management
services, and the BSD (Berkeley Software Distribution) kernel for additional services.

 Application services and dynamically loadable modules ( kernel extensions ) provide the rest
of the OS functionality.

64
5. Hybrid Architecture of
Operating System
5.2. Android OS

 The Android OS was developed for Android smartphones and tablets by the Open Handset
Alliance, primarily Google.

 Android is an open-source OS, as opposed to iOS, which has lead to its popularity.

 Android includes versions of Linux and a Java virtual machine both optimized for small
platforms.

66
6. Client/Server Architecture

 A slight variation of the microkernel, the idea is to distinguish two classes of


processes, the servers, each of which provides some service, and the clients, which
use these services. This model is known as the client-server model.

 Communication between clients and servers is often by message passing. To obtain a


service, a client process constructs a message saying what it wants and sends it to
the appropriate service. The service then does the work and sends back the answer.

 Much of the Web operates this way. A PC sends a request for a Web page to the
server and the Web page comes back. This is a typical use of the client-server model
in a network.

67
OS Services: System Call
 When a program in user mode requires access to RAM or a hardware resource, it must ask the
kernel to provide access to that resource. This is done via something called a system call.
System calls are the only entry points for the kernel system.

 When a program makes a system call, the mode is switched from user mode to kernel mode.
This is called a context switch. Then the kernel provides the resource which the program
requests. After that, another context switch happens, resulting in a change of mode from
kernel mode back to user mode.

 But for accessing any functionalities or hardware resources we have to be in Kernel Mode.
Hence, for shifting from User Mode to Kernel Mode, we need System Call.

 To understand system calls, first one needs to understand the difference between kernel
mode and user mode of a CPU. Every modern operating system supports these two modes.

68
OS Services: System Call
Example (copy the contents of one file into another in C)
 Declare two file pointers and file names (source and destination) as:
FILE *sfp,*dfp;
char ch,sfilename[20],dfilename[20];
 Take source and destination file names from the user
printf("Enter source and destination file name:");
scanf("%s%s",sfilename, dfilename,);
 Open the sourceFile in read mode and destinationFile in write mode
sfp=fopen(sfilename,"r");
dfp=fopen(dfilename,"w");
 Copy all the contents from sourceFile to destinationFile
while(1)
{
ch=fgetc(sfp);
if(ch==EOF) break;
else fputc(ch,dfp);
}
 Close both files using file pointers
fclose(dfp);
fclose(sfp);

70
OS Services: System Call
How does System Call Work?

 Whenever we use an application at that time by


default we are in user mode. And All the core
functionalities and drivers work in kernel mode.

 The process gets switched between two modes


i.e. user mode and kernel mode.

 Suppose we are writing a C program, and in


that program you have to read a file and have to
write something in that file.

 As the file is stored in Hard Disk and the hard


disk is a hardware and all the hardware is in
control of the kernel. So a user cannot directly
access the hardware it has to take the help of
the kernel.

71
OS Services: System Call
How does System Call Work?

 To read that file we have to use a system call. A


system call is a way by which we can access the
kernel. We will use read() system call, it means
that we want to read some data from any file.

 After it, the process gets shifted from user mode


to kernel mode.

 Now, we will read the file as we are now in the


kernel mode. All the operations of read and
write will be completed here.

 After that, the process will get shifted to user


mode again. The process has to shift to user
mode because we the user are working in user
mode.

72
Assignment I
Q1. Describe types of System Calls

Q2. Write short notes on:


Shell Commands
Shell Programming

Q3. Virtual Machine

73

You might also like