0% found this document useful (0 votes)
92 views

Introduction OS

The document provides an introduction to operating systems. It outlines the basic components of a computer system including the processor, memory, input/output modules, and system bus. It then discusses computer system architecture including the input, output, storage, CPU, ALU, and control units. Finally, it defines what an operating system is, provides examples, and explains how the operating system acts as an intermediary between the hardware and user programs by running in both kernel and user modes.

Uploaded by

UTSAV KHANDELWAL
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Introduction OS

The document provides an introduction to operating systems. It outlines the basic components of a computer system including the processor, memory, input/output modules, and system bus. It then discusses computer system architecture including the input, output, storage, CPU, ALU, and control units. Finally, it defines what an operating system is, provides examples, and explains how the operating system acts as an intermediary between the hardware and user programs by running in both kernel and user modes.

Uploaded by

UTSAV KHANDELWAL
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 100

Unit-1

Introduction to
Operating System
Looping
 Outline
• Computer system overview
• Computer system architecture
• What is Operating System (OS)
• Roles of Operating System (OS)
• Objectives / Goals of Operating System (OS)
• Generations of Operating Systems (OS)
• Operating Systems (OS) services
• Types of Operating Systems (OS)
• System calls
• Operating Systems (OS) structure
• Multiprogramming v/s Multiprocessing v/s Multitasking
• Time Sharing Operating System
• Parallel Processing Operating System
• Distributed Operating System
Section - 1
Basic elements of computer

I/O
Processor
Modules

System
Memory
Bus

Unit 1 – Introduction to Operating System 4


Processor

Referred to as the
Central Processing
Unit (CPU)

Arithmetic & Logic Unit Control Unit

Performs the data Controls the


processing operation of the
functions computer
Exercise Which two companies are famous for manufacturing computer processors?

Unit 1 – Introduction to Operating System 5


Memory
Memory is device
that is used to
store
data/information

Primary Memory Secondary Memory

• Volatile • Non-Volatile
• RAM & ROM • HDD, CD & DVD

Exercise Give the difference between primary memory and secondary memory.

Unit 1 – Introduction to Operating System 6


I/O Module (Input/Output Module)
 Input/output module is a device that acts as the connective bridge between a computer
system at one end and an I/O or peripheral device at the other, such as a printer, webcam or
scanner.
 An I/O module is a mediator
between the processor/memory
and an I/O devices.
 It controls the data exchange
between the external devices
and main memory or external
devices and CPU registers.

Unit 1 – Introduction to Operating System 7


System Bus
 Provides communication among processors, main memory, and I/O
devices.
 The system bus is a pathway composed of cables and connectors used to
carry data between a computer microprocessor and the main memory.
 Types of buses
 Address bus - carries memory addresses from the processor to other components
such as primary storage and input/output devices.
 Data bus - carries the data between the processor and other components.
 Control bus - carries control signals from the processor to other components.

Exercise What are the 3 types of buses?

Unit 1 – Introduction to Operating System 8


Section - 2
Computer system architecture

Unit 1 – Introduction to Operating System 10


Input unit
 It provides data and instructions to the
computer system.
 Commonly used input devices are
keyboard, mouse, magnetic tape etc.
 Input unit performs following tasks:
 Accept the data and instructions from the
outside environment.
 Convert it into machine language.
 Supply the converted data to computer
system.

Unit 1 – Introduction to Operating System 11


Output unit
 It connects the internal system of a
computer to the external environment.
 It provides the results of any computation,
or instructions to the outside world.
 Some output devices are printers, monitor
etc.

Unit 1 – Introduction to Operating System 12


Storage unit
 This unit holds the data and instructions.
 It also stores the intermediate results
before these are sent to the output
devices.
 It also stores the data for later use.
 The storage unit of a computer system
can be divided into two categories:
 Primary Storage
 Secondary Storage

Unit 1 – Introduction to Operating System 13


Primary storage (memory) vs Secondary storage (memory)
Primary storage Secondary storage
Examples: RAM, ROM, Cache memory, PROM, Examples: Hard Disk, Floppy Disk, Magnetic
EPROM, Registers, etc. Tapes, etc.
It is temporary and volatile. It is permanent and Non-volatile.
Primary memory is directly accessible by Secondary memory is not directly accessible by
Processor/CPU. the CPU.
Primary memory devices are expensive. Secondary memory devices are cheaper.
The memory devices used for primary memory The secondary memory devices are magnetic
are semiconductor memories. and optical memories.
Primary memory is also known as Main Secondary memory is also known as External
memory or Internal memory. memory or Auxiliary memory.

Unit 1 – Introduction to Operating System 14


CPU (Central Processing Unit)
 The Arithmetic Logical Unit and Control
Unit are together known as CPU.
 CPU is the brain of computer system.
 It performs following tasks:
 performs all operations.
 takes all decisions.
 controls all the units of computer.

Unit 1 – Introduction to Operating System 15


ALU (Arithmetic Logical Unit)
 All the calculations are performed in ALU
of the computer system.
 The ALU can perform basic operations
such as addition, subtraction, division,
multiplication etc.
 Whenever calculations are required, the
control unit transfers the data from
storage unit to ALU.
 When the operations are done, the result
is transferred back to the storage unit.

Unit 1 – Introduction to Operating System 16


CU (Control Unit)
 It controls all other units of the computer.
 It controls the flow of data and
instructions to and from the storage unit
to ALU.
 Thus it is also known as central nervous
system of the computer.

Unit 1 – Introduction to Operating System 17


Section - 3
What is Operating System (OS)?
 A Computer System consists of various hardware's such as

Processor RAM Keyboard & Mouse

Hard Disk Monitor Printer

Who manages (controls) these hardwares??? Operating System


Unit 1 – Introduction to Operating System 19
Definition of Operating System (OS)
 An Operating System (OS) is a collection of software that
 manages hardware resources
 provides various service to the users

Unit 1 – Introduction to Operating System 20


Examples of Operating System (OS)

Examples
of
Operating
System

Unit 1 – Introduction to Operating System 21


Where OS lies? (Interaction of OS & Hardware)
 OS lies between hardware and user program.
 It acts as an intermediary between the user
and the hardware. Web E-mail Music
browser reader player
 Modes of operation of computer
1. Kernel Mode
 has complete access to all the hardware User
Mode
 can execute any instruction that a machine is Software User Program
capable of executing
 has high privileged (rights) Kernel
Operating System
Mode
2. User Mode
 has limited access to limited hardware Hardware
 can execute only subset (few) of the machine
instructions
 has less privileged (rights)

Unit 1 – Introduction to Operating System 22


Why and How switch occur?

Web E-mail Music


browser reader player  User is writing program in C.
 Once finish writing will execute it.

User user-mode program


Mode performs trap instruction
Software User Program

Kernel  To execute this program


Operating System
Mode 1. Load program into RAM
2. Program is executed by processor
Hardware

Unit 1 – Introduction to Operating System 23


Section - 4
OS as Extended Machine
 The architecture of a computer is difficult to program
 Architecture (instruction set, memory organization, I/O, bus
structure) of most of computer at the machine level language is
primitive and awkward to program.
 Example: If user want to read from floppy or hard disk:

Unit 1 – Introduction to Operating System 25


OS as Extended Machine
 Example: If user want to read from floppy or hard disk:

User has to write command and


address to the disk controller and
then initiate the I/O.
Disk Controller

Unit 1 – Introduction to Operating System 26


OS as Extended Machine

The disk controller will find the requested User has to check the status of disk
data in the disk and fetch it from disk to controller operation where it has
disk controller buffer. finished or not.

Unit 1 – Introduction to Operating System 27


OS as Extended Machine

If success, the data from disk controller


buffer should be moved to main memory (to
the application buffer).

Unit 1 – Introduction to Operating System 28


OS as Extended Machine
 If all the users will have to do these messy details:
 The program will be very difficult to write and quite long.
 The program will be hardware dependent.
 User don’t want to be involved in programming of storage devices.
 Therefore, an OS provides a set of basic commands or instructions to perform various
operations such as read, write, modify, save or close.
 Dealing with these command is easier than directly dealing with hardware.
 Operating system hides the complexity of hardware and present a beautiful interface to the
users.

Unit 1 – Introduction to Operating System 29


OS as Resource Manager
 There are lots of resources in computer system
 CPU (Processor)
 Memory
 I/O devices such as hard disk, mouse, keyboard, printer, scanner etc.
 If a computer system is used by multiple applications (or
users), then they will compete for these resources.

Unit 1 – Introduction to Operating System 30


OS as Resource Manager
 It is the job of OS to allocate these resources to the various applications so that:
 The resources are allocated fairly (equally)

P1 Wants to print 50 lines

After printing 10 lines of P1

P2 Wants to print 20 lines

After printing 20 lines of P1

P3 Wants to print 15 lines

P4 Wants to print 15 lines

Unit 1 – Introduction to Operating System 31


OS as Resource Manager
 It is the job of OS to allocate these resources to the various applications so that:
 The resources are protected from cross-access.

P1 Wants to print 50 lines

After printing 10 lines of P1

P2 Wants to print 20 lines

After printing 20 lines of P1

P3 Wants to print 15 lines

P4 Wants to print 15 lines

Unit 1 – Introduction to Operating System 32


OS as Resource Manager
 It is the job of OS to allocate these resources to the various applications so that:
 Access to the resources is synchronized so that operations are correct and consistent
 Example: If we write a program to calculate below in C language

7+9–6*4/2=4
20
P1 P2 P3 P4

3 4 1 2

Unit 1 – Introduction to Operating System 33


OS as Resource Manager
 It is the job of OS to proper allocate these resources to the various applications so that:
 Deadlock are detected, resolved and avoided.

Unit 1 – Introduction to Operating System 34


OS as Resource Manager
 Resource manager – sharing resources in two different ways:
1. In time sharing/multiplexing (i.e CPU)

Unit 1 – Introduction to Operating System 35


OS as Resource Manager
 Resource manager – sharing resources in two different ways
2. In space sharing/multiplexing. (i.e Memory)

Process Process Process Empty


1 2 3 Space

Main Memory

Unit 1 – Introduction to Operating System 36


Section - 5
Objectives / Goals of Operating System (OS)
 Make the computer system convenient to use in an efficient manner.
 Hide the details of the hardware resources from the users.
 Provide users a convenient interface to use the computer system.
 Act as an intermediary between the hardware and its users, making it easier for the users to
access and use other resources.
 Manage the resources of a computer system.
 Keep track of who is using which resource, granting resource requests, and mediating
conflicting requests from different programs and users.
 Provide efficient and fair sharing of resources among users and programs.

Unit 1 – Introduction to Operating System 38


Section - 6
Generations / History of OS (First generation)
 First generation (1945-1955)
 Vacuum tubes and plug-boards are used in these systems.

Vacuum tubes
Plug board

Unit 1 – Introduction to Operating System 40


Generations / History of OS (Second generation)
 Second generation (1955-1965)
 Transistors are used in these systems
 The machine that are produced are called mainframes.
 Batch systems was used for processing.

Programmers bring
1401 cards
reads to
batch
1401
Operator
of jobscarries
onto tape
input
7094tape
Operator
does
to computing
7094
carries output1401
tape prints
to 1401output

Unit 1 – Introduction to Operating System 41


Generations / History of OS (Third generation)
 Third generation (1965-1980)
 Integrated circuits (IC's) are used in place of transistors in these computers.
 It provides multiprogramming (the ability to have several programs in memory at once, each in its own
memory partition).

Unit 1 – Introduction to Operating System 42


Generations / History of OS (Forth generation)
 Fourth generation (1980-present)
 Personal Computers (PC)
 LSI (Large Scale Integration) circuits, chips containing thousands of transistors are used in these systems.

Unit 1 – Introduction to Operating System 43


Section - 7
Services / Functions / Tasks of Operating System (OS)

Definition of Operating System


 An Operating System (OS) is a collection of software that
 manages hardware resources
 provides various service to the users

Unit 1 – Introduction to Operating System 45


Services / Functions / Tasks of Operating System (OS)
1. Program development
 It provides editors and debuggers to assist (help) the programmer in creating programs.

Exercise Give the name of any five code editor for windows?
Unit 1 – Introduction to Operating System 46
Services / Functions / Tasks of Operating System (OS)
2. Program execution
 Following tasks need to be perform to execute a program:
 Instructions and data must be loaded into main memory.
 I/O devices and files must be initialized.
 The OS handles all these duties for the user.

Unit 1 – Introduction to Operating System 47


Services / Functions / Tasks of Operating System (OS)
3. Access to I/O devices (Resource allocation)
 A running program may require I/O, which may involve file
or an I/O device.
 For efficiency and protection, users cannot control I/O
devices directly.
 Therefore, the OS controls these I/O devices and provides
to program as per requirement.

Unit 1 – Introduction to Operating System 48


Services / Functions / Tasks of Operating System (OS)
4. Memory management
 OS manages memory hierarchy.
 OS keeps the track of which part of memory area in use and free memory.
 It allocates memory to program when they need it.
 It de-allocate the memory when the program finish execution.

P1

P2

Unit 1 – Introduction to Operating System 49


Services / Functions / Tasks of Operating System (OS)
5. Controlled access to file
 In case of file access, OS provides a directory hierarchy for easy
access and management of file.
 OS provides various file handling commands using which user can
easily read, write and modify file.

Unit 1 – Introduction to Operating System 50


Services / Functions / Tasks of Operating System (OS)
6. Communication
 In multitasking environment, the processes need to communicate with each other and to exchange their
information.
 Operating system performs the communication among various types of processes in the form of shared
memory.

Unit 1 – Introduction to Operating System 51


Services / Functions / Tasks of Operating System (OS)
7. Error detection and response
 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.

Unit 1 – Introduction to Operating System 52


Services / Functions / Tasks of Operating System (OS)
8. Accounting
 Keeping a track of which users are using how much and what kinds of computer resources can be used for
accounting or simply for accumulating usage statistics.
 Usage statistics is used to reconfigure the system to improve computing services.

Unit 1 – Introduction to Operating System 53


Services / Functions / Tasks of Operating System (OS)
9. Protection & Security
 Protection involves ensuring that all accesses to system resources is controlled.
 protection deals with the access to the system resources. It determines that what files can be accessed or
permeated by a special user.
 To make a system secure, the user needs to authenticate himself or herself to the system.
 The security systems covers the safety of their system resources (saved data, memory, disks, etc) across malignant
alteration, illegal access, and disparity or inconsistency.

Unit 1 – Introduction to Operating System 54


Operating System Zoo
Types of Operating Systems
Some widely used operating systems are as follows:
Batch Operating System
Multiprogramming Operating System
Multiprocessing Operating System
Multitasking Operating System
Network Operating System
Real Time Operating System
Time-Sharing Operating System
Distributed Operating System

Unit 1 – Introduction to Operating System 56


1. Batch Operating System
 This type of operating system does not interact with the computer directly.
 There is an operator which takes similar jobs having the same requirement and group them into
batches. It is the responsibility of the operator to sort jobs with similar needs.
 Firstly, user prepares his job using punch cards.
 Then, he submits the job to the computer operator.
 Operator collects the jobs from different users and sort the jobs into batches with similar needs.
 Then, operator submits the batches to the processor one by one.
 All the jobs of one batch are executed together.

Unit 1 – Introduction to Operating System 57


Advantage/Disadvantage
 Advantage:
 Multiple users can share the batch systems
 The idle time for the batch system is very less
 No manual intervention is needed
 Disadvantage:
 Priority can not be set for the jobs
 All the jobs of a batch are executed sequentially one after the other.
 The output is obtained only after all the jobs are executed.
 Batch operating system may lead to starvation
 The jobs of a particular batch might take long time for their execution. This might lead to starvation to other jobs in other batches.
 CPU may remain idle for a long time
 If the jobs of a batch require some I/O operation, then CPU must wait till the I/O operation gets completed.
 Since I/O devices are very slow, CPU remains idle for a long time. CPU can not take any other job and execute it.
 There is a lack of interaction between a user and his job.
 Once a batch is submitted for execution, the user is not able to interact with any of his jobs

Unit 1 – Introduction to Operating System 58


2. Multiprogramming Operating System
 Multiprogramming is an extension to batch processing where multiple programs are in the
main memory & CPU is always kept busy. Each process needs two types of system time: CPU
time and IO time.
 In a multiprogramming environment, when a process does its I/O, The CPU can start the
execution of other processes. Therefore, multiprogramming improves the efficiency of the
system.

Advantages of Multiprogramming OS
• Throughout the system, it increased as the CPU always had one
program to execute.
• Response time can also be reduced.
Disadvantages of Multiprogramming OS
• Multiprogramming systems provide an environment in which various
systems resources are used efficiently, but they do not provide any
user interaction with the computer system.

Unit 1 – Introduction to Operating System 59


3. Multiprocessing Operating System
 In Multiprocessing, Parallel computing is achieved. There are more than one processors
present in the system which can execute more than one process at the same time. This will
increase the throughput of the system.

Advantages:
• Increased reliability: Due to the multiprocessing system, processing tasks can
be distributed among several processors. This increases reliability as if one
processor fails, the task can be given to another processor for completion.
• Increased throughout: As several processors increase, more work can be done
in less.
Disadvantages:
• Multiprocessing operating system is more complex and sophisticated as it
takes care of multiple CPUs simultaneously.

Unit 1 – Introduction to Operating System 60


4. Multitasking Operating System
 The multitasking operating system is a logical extension of a multiprogramming system that
enables multiple programs simultaneously. It allows a user to perform more than one computer
task at the same time.

Advantages
• Timesharing
• Responsive
• Handle multiple users
• Protected memory
Disadvantages
• doing multitasking, the processor becomes busy all the time and CPU
heats up. To solve this problem you have to attach the cooling system
to your CPU.

Unit 1 – Introduction to Operating System 61


5. Network Operating System
 An Operating system, which includes software and associated protocols to communicate with
other computers via a network conveniently and cost-effectively, is called Network Operating
System.
 Peer to Peer
 Client Server System

Advantages
• In this type of operating system, network traffic reduces due to the
division between clients and the server.
• This type of system is less expensive to set up and maintain.
Disadvantages
• In this type of operating system, the failure of any node in a system
affects the whole system.
• Security and performance are important issues. So trained network
administrators are required for network administration.

Unit 1 – Introduction to Operating System 62


6. Real Time Operating System
 In Real-Time Systems, each job carries a certain deadline within which the job is supposed to be completed,
otherwise, the huge loss will be there, or even if the result is produced, it will be completely useless.
 The Application of a Real-Time system exists in the case of military applications, if you want to drop a missile,
then the missile is supposed to be dropped with a certain precision.
 Hard real time – missing an occasional deadline can cause any permanent damage. Many of these are found in industrial process
control, car engine control system.
 Soft real time – missing an occasional deadline does not cause any permanent damage. Used in digital audio, multimedia system.

Advantages of Real-time operating system:


• Easy to layout, develop and execute real-time applications under the real-
time operating system.
• In a Real-time operating system, the maximum utilization of devices and
systems.
Disadvantages of Real-time operating system:
• Real-time operating systems are very costly to develop.
• Real-time operating systems are very complex and can consume critical CPU
cycles.

Unit 1 – Introduction to Operating System 63


7. Time-Sharing Operating System
 In the Time Sharing operating system, computer resources are allocated in a time-dependent fashion to several programs simultaneously.
 Thus it helps to provide a large number of user's direct access to the main computer. It is a logical extension of multiprogramming. In time-
sharing, the CPU is switched among multiple programs given by different users on a scheduled basis.
 A time-sharing operating system allows many users to be served simultaneously, so sophisticated CPU scheduling schemes and Input/output
management are required.
 Time-sharing operating systems are very difficult and expensive to build.

Advantages of Time Sharing Operating System


• The time-sharing operating system provides effective utilization and sharing of
resources.
• This system reduces CPU idle and response time.
Disadvantages of Time Sharing Operating System
• Data transmission rates are very high in comparison to other methods.
• Security and integrity of user programs loaded in memory and data need to be
maintained as many users access the system at the same time.

Unit 1 – Introduction to Operating System 64


8. Distributed Operating System
 The Distributed Operating system is not installed on a single machine, it is divided into parts, and these parts are
loaded on different machines.
 A part of the distributed Operating system is installed on each machine to make their communication possible.
 Distributed Operating systems are much more complex, large, and sophisticated than Network operating systems
because they also have to take care of varying networking protocols

Advantages
• The distributed operating system provides sharing of resources.
• This type of system is fault-tolerant.
Disadvantages
• Protocol overhead can dominate computation cost.

Unit 1 – Introduction to Operating System 65


Handhelds computer operating systems
 A handheld computer or PDA (Personal Digital Assistant) is small computer that fit in a Pocket and perform
small number of functions such as electronic address book, memo pad.
 The OS runs on these devices are handheld OS.
 These OS also provides ability to handle telephony, digital photography and other functions.
 Examples: Symbian OS, Palm OS.

Unit 1 – Introduction to Operating System 66


Embedded operating systems
 This OS is installed in ATMs, printers, calculators and washing machine.
 It runs on the computer that control devices.
 It neither allow to download new software nor accept user installed software. So there is no need for
protection.
 Examples: QNX, VxWorks.

Unit 1 – Introduction to Operating System 67


Sensor node operating systems
 Network of tiny sensor nodes are being developed for numerous purpose.
 Each nodes are tiny computers with a CPU, RAM, ROM and one or more environmental sensors.
 The OS installed in these nodes are sensor node OS.
 They communicate with each other and with base station using wireless communication.
 These sensor network are used to protect area of building, detect fires in forest, measure temperature.
 Examples: TinyOS.

Unit 1 – Introduction to Operating System 68


Smart card operating systems
 Smallest OS run on smart cards which are credit card sized devices containing CPU chip.
 These OS are installed on electronic payments cards such as debit card, credit card etc.
 They have limited processing power.
 Some smart cards are Java oriented. ROM on smart card holds an interpreter for the JVM – small program.

Unit 1 – Introduction to Operating System 69


Computer Hardware Review
 The CPU, memory, and I/O devices are all connected by a system bus and communicate with
one another over it. Modern personal computers have a more complicated structure, involving
multiple buses.

Unit 1 – Introduction to Operating System 70


1. Processor
It fetches instructions from memory and executes them. The basic cycle of every CPU is to fetch
the first instruction from memory, decode it to determine its type and operands, execute it, and
then fetch, decode, and execute subsequent instructions. The cycle is repeated until the program
finishes. In this way, programs are carried out.
 Each CPU has a specific set of instructions that it can execute. Thus an x86 processor cannot
execute ARM programs and an ARM processor cannot execute x86 programs.
 general registers used to hold variables and temporary results:
 Program counter: which contains the memory address of the next instruction to be fetched. After that
instruction has been fetched, the program counter is updated to point to its successor.
 stack pointer: which points to the top of the current stack in memory.
 PSW (Program Status Word): This register contains the condition code bits, which are set by comparison
instructions, the CPU priority, the mode (user or kernel), and various other control bits. The PSW plays an
important role in system calls and I/O.
 The operating system will often stop the running program to (re)start another one. Every time it
stops a running program, the operating system must save all the registers so they can be
restored when the program runs later.
Unit 1 – Introduction to Operating System 71
 To improve performance, CPU might have separate fetch, decode, and execute units, so that
while it is executing instruction n, it could also be decoding instruction n + 1 and fetching
instruction n + 2. Such an organization is called a pipeline.
 This pipelining create complexities for developers of OS and Compilers.

 (a) A three-stage pipeline. (b) A superscalar CPU

Unit 1 – Introduction to Operating System 72


 Multithreading: thread is a kind of lightweight process, which, in turn, is a running program. For
example, if one of the processes needs to read a word from memory (which takes many clock cycles), a
multithreaded CPU can just switch to another thread. Multithreading does not offer true parallelism.
Only one process at a time is running, but thread-switching time is reduced to the order of a
nanosecond.
 The multicore chips: (a) A quad-core chip with a shared L2 cache. (b) A quad-core chip with separate L2 caches.

• GPU is a processor with, literally, thousands of tiny cores.


• They are very good for many small computations done in parallel, like
rendering polygons in graphics applications

Unit 1 – Introduction to Operating System 73


2. Memory

 The storage capacity available in them is typically 32 × 32 bits on a 32-bit CPU and 64 × 64 bits on a 64-bit
CPU
 Cache miss
 Cache hit
 L1, L2, L3 Cache

Unit 1 – Introduction to Operating System 74


3. Disk
 A disk consists of one or more metal platters that rotate at 5400, 7200, 10,800 RPM or more. A
mechanical arm pivots over the platters from the corner.
 At any given arm position, each of the heads can read an annular region called a track.
Together, all the tracks for a given arm position form a cylinder

Unit 1 – Introduction to Operating System 75


4. I/O Devices
 The controller is a chip or a set of chips that physically controls the device. It accepts commands from the operating
system, for example, to read data from the device, and carries them out.
 The software that talks to a controller, giving it commands and accepting responses, is called a device driver. Each
controller manufacturer has to supply a driver for each operating system it supports.
 Input and output can be done in three different ways:
 Busy waiting: In the simplest method, a user program issues a system call, which the kernel then translates into a procedure call to the appropriate
driver. The driver then starts the I/O and sits in a tight loop continuously polling the device to see if it is done (usually there is some bit that indicates
that the device is still busy). When the I/O has completed, the driver puts the data (if any) where they are needed and returns.
 Interrupt: Driver start the device and ask it to give an interrupt when it is finished. hen the controller detects the end of the transfer, it generates an
interrupt to signal completion.
 DMA: DMA chip that can control the flow of bits between memory and some controller without constant CPU intervention.

(a) The steps in starting an I/O device and getting an interrupt.


(b) Interrupt processing involves taking the interrupt, running the
interrupt handler, and returning to the user program.

Unit 1 – Introduction to Operating System 76


Booting a computer
 Step 1: Once the computer system is turned on, BIOS (Basic Input /Output System) performs a series of activities or functionality tests on programs stored in ROM,
called on POST (Power-on Self Test) that checks to see whether peripherals in the system are in perfect order or not.
 Step 2: After the BIOS is done with pre-boot activities or functionality test, it read bootable sequence from CMOS (Common Metal Oxide Semiconductor) and looks
for master boot record in the first physical sector of the bootable disk as per boot device sequence specified in CMOS. For example, if the boot device sequence is:
Floppy Disk, Hard Disk, CDROM
 Step 3: After this, the master boot record will search first in a floppy disk drive. If not found, then the hard disk drive will search for the master boot record. But if
the master boot record is not even present on the hard disk, then the CDROM drive will search. If the system cannot read the master boot record from any of these
sources, ROM displays "No Boot device found" and halted the system. On finding the master boot record from a particular bootable disk drive, the operating system
loader, also called Bootstrap loader, is loaded from the boot sector of that bootable drive· into memory. A bootstrap loader is a special program that is present in
the boot sector of a bootable drive.
 Step 4: The bootstrap loader first loads the IO.SYS file. After this, MSDOS.SYS file is loaded, which is the core file of the DOS operating system.
 Step 5: After this, MSDOS.SYS file searches to find Command Interpreter in CONFIG.SYS file, and when it finds, it loads into memory. If no Command Interpreter is
specified in the CONFIG.SYS file, the COMMAND.COM file is loaded as the default Command Interpreter of the DOS operating system.
 Step 6: The last file is to be loaded and executed is the AUTOEXEC.BAT file that contains a sequence of DOS commands. After this, the prompt is displayed. We
can see the drive letter of bootable drive displayed on the computer system, which indicates that the operating system has been successfully on the system from
that drive.

Unit 1 – Introduction to Operating System 77


Section - 9
What is System calls?
 A system call is a way for programs to interact with the operating system.
 A system call is a mechanism that provides the interface between a process and the operating
system.
 A computer program makes a system call when it makes a request to the operating system's
kernel.
 It is a programmatic method in which a computer program requests a service from the kernel
of the OS.
 System call provides the services of the operating system to the user programs via
Application Program Interface(API).
 System calls are the only entry points for the kernel system.

Unit 1 – Introduction to Operating System 79


Types of system calls
 Process Control: This system calls perform the task of process creation, process termination,
etc.
 Functions:
 End and abort
 Load and execute
 Create process and terminate process
 Wait and signed event
 Allocate and free memory
 File Management: File management system calls handle file manipulation jobs like creating a
file, reading, and writing, etc.
 Functions:
 Create a file
 Delete file
 Open and close file
 Read, write and reposition
 Get and set file attributes

Unit 1 – Introduction to Operating System 80


Types of system calls
 Device Management: Device management does the job of device manipulation like reading
from device buffers, writing into device buffers, etc.
 Functions
 Request and release device
 Logically attach/ detach devices
 Get and Set device attributes
 Information Maintenance: It handles information and its transfer between the OS and user
program.
 Functions:
 Get or set time and date
 Get process and device attributes

Unit 1 – Introduction to Operating System 81


Types of system calls
 Communication: These types of system calls are specially used for interprocess
communications (IPC).
 Functions:
 Create, delete communications connections
 Send, receive message
 Help OS to transfer status information
 Attach or detach remote devices

Unit 1 – Introduction to Operating System 82


Example of system calls (Read system call)
 Example: In Unix Read system call is
 count = read(fd, buffer, nbytes)
Return to caller
 fd is a file descriptor. Library
• When a file is opened, permissions are
Trap to the kernel procedure
checked. 5 Put code for read in register read
• If access is allowed, a number (fd) is
returned. 6 10
Call to library proc
• Then file can be read/written. User 4
 nbytes is number of bytes to read Increment SP
space 11
 buffer is where read deposits (stores) the
data
Call read User
3 Push fd program
Push parameter 2 Push &buffer calling read
onto stack 9
1 Push nbytes

Kernel 7 8 Sys call


Dispatch
space handler

Unit 1 – Introduction to Operating System 83


Steps involved in making a system call (Read system call)
 Steps involved in making a system call
 In steps 1-3, the calling program pushes the parameters onto the stack. The first and third parameters are
called by value, but the second one is called by its address as denoted by the & symbol.
 In step 4, the actual call to the library procedure is made. This instruction is the normal procedure call
instruction used to call all procedures.
 In step 5, the library procedure places the system call number in a place where the operating system expects
it, such as a register.
 In step 6, the library procedure executes a TRAP instruction to switch from user mode to kernel mode and
start execution at a fixed address within the kernel.
 In step 7, the kernel examines the system call number and then dispatches it to the correct system call
handler. This correct number is given in the table of system call handlers by pointers referenced at the
system call number.
 In step 8, the system call handler runs.
 In step 9, the operation is completed, and the user is given back control once the TRAP instruction is set.
 In step 10, this procedure returns to the user program, like how all normal library procedures do.
 In step 11, the operating system has to clear the stack, so it increments it enough so that it is empty.

Unit 1 – Introduction to Operating System 84


System calls

Unit 1 – Introduction to Operating System 85


System calls

Unit 1 – Introduction to Operating System 86


a. System Call for process management
 Fork system call is used for creating a new process, which is called child process, which runs concurrently with the
process that makes the fork() call (parent process).
 After a new child process is created, both processes will execute the next instruction following the fork() system
call. A child process uses the same pc(program counter), same CPU registers, same open files which use in the
parent process.
 It takes no parameters and returns an integer value. Below are different values returned by fork().
 Negative Value: creation of a child process was unsuccessful.
 Zero: Returned to the newly created child process.
 Positive value: Returned to parent or caller. The value contains process ID of newly created child process.

Unit 1 – Introduction to Operating System 87


Total Number of Processes = 2n, where n is number of
fork system calls. So here n = 3, 23 = 8

The main process: P0


Processes created by the 1st fork: P1
Processes created by the 2nd fork: P2, P3
Processes created by the 3rd fork: P4, P5, P6, P7

Here, two outputs are possible because the parent process and child
process are running concurrently. So we don’t know whether the OS will
first give control to the parent process or the child process.

Unit 1 – Introduction to Operating System 88


 In most cases, after a fork, the child will need to execute different code from the parent. Consider the case of the
shell. It reads a command from the terminal, forks off a child process, waits for the child to execute the command,
and then reads the next command when the child terminates.
 To wait for the child to finish, the parent executes a waitpid system call, which just waits until the child terminates
(any child if more than one exists).
 The fork system call creates a new process. The new process created by fork() is a copy of the current process
except for the returned value. The exec() system call replaces the current process with a new program.

Unit 1 – Introduction to Operating System 89


b. System Call for directory management
 To read or write a file, it must first be opened. This call specifies the file name to be opened,
either as an absolute path name or relative to the working directory, as well as a code of
O_RDONLY, O_WRONLY, or O_RDWR, meaning open for reading, writing, or both. To create a
new file, the O_CREAT parameter is used.
 The file descriptor returned can then be used for reading or writing. Afterward, the file can be
closed by close, which makes the file descriptor available for reuse on a subsequent open.
 The most heavily used calls are undoubtedly read and write. We saw read earlier. Write has the
same parameters.
 Lseek has three parameters: the first is the file descriptor for the file, the second is a file position, and the
third tells whether the file position is relative to the beginning of the file, the current position, or the end of
the file. The value returned by lseek is the absolute position in the file (in bytes) after changing the pointer.

Unit 1 – Introduction to Operating System 90


c. System Calls for Directory Management
 The first two calls, mkdir and rmdir, create and remove empty directories, respectively.
 The next call is link. Its purpose is to allow the same file to appear under two or more names, often in different directories. A
typical use is to allow several members of the same programming team to share a common file, with each of them having the
file appear in his own directory, possibly under different names.
 Sharing a file is not the same as giving every team member a private copy; having a shared file means that changes that any
member of the team makes are instantly visible to the other members—there is only one file. When copies are made of a file,
subsequent changes made to one copy do not affect the others.

 If ast now executes a program containing the system call


link("/usr/jim/memo", "/usr/ast/note");
 the file memo in jim’s directory is now entered into ast’s directory
under the name note.
 Thereafter, /usr/jim/memo and /usr/ast/note refer to the same
file. As an aside, whether user directories are kept in /usr, /user,
/home, or somewhere else is simply a decision made by the local
system administrator.

Every file in UNIX has a unique number, its i-number, that identifies it. This i-number is an index into a table of i-nodes, one per file,
telling who owns the file, where its disk blocks are, and so on. A directory is simply a file containing a set of (i-number, ASCII name)
pairs.
Unit 1 – Introduction to Operating System 91
 By executing the mount system call, the USB file system can be attached to the root file system
mount("/dev/sdb0", "/mnt", 0);

where the first parameter is the name of a block special file for USB drive 0, the second parameter is the place in the
tree where it is to be mounted, and the third parameter tells whether the file system is to be mounted read-write or
read-only.

After the mount call, a file on drive 0 can be accessed by just using its path from the root directory or the working directory, without
regard to which drive it is on.

Unit 1 – Introduction to Operating System 92


d. Miscellaneous System Calls
 The chdir call changes the current working directory. After the call
chdir("/usr/ast/test");

 chmod("file", 0644);

Unit 1 – Introduction to Operating System 93


Basic concepts of OS
 1. Process: A process is basically a program in execution. Associated with each process is its
address space, a list of memory locations from 0 to some maximum, which the process can
read and write.
 The address space contains the executable program, the program’s data, and its stack. Also associated with
each process is a set of resources, commonly including registers (including the program counter and stack
pointer), a list of open files, outstanding alarms, lists of related processes, and all the other information
needed to run the program. A process is fundamentally a container that holds all the information needed to
run a program.

In many operating systems, all the information about each process, other than the contents of its own address
space, is stored in an operating system table called the process table, which is an array of structures, one for
each process currently in existence.
Thus, a (suspended) process consists of its address space, usually called the core image (in honor of the
magnetic core memories used in days of yore), and its process table entry, which contains the contents of its
registers and many other items needed to restart the process later.

Unit 1 – Introduction to Operating System 94


2. Address Space:
 Every computer has some main memory that it uses to hold executing programs. In a very simple operating
system, only one program at a time is in memory. To run a second program, the first one has to be removed and
the second one placed in memory.
 More sophisticated operating systems allow multiple programs to be in memory at the same time. To keep them
from interfering with one another (and with the operating system), some kind of protection mechanism is needed.
While this mechanism has to be in the hardware, it is controlled by the operating system.
 Normally, each process has some set of addresses it can use, typically running from 0 up to some maximum. In
the simplest case, the maximum amount of address space a process has is less than the main memory. In this
way, a process can fill up its address space and there will be enough room in main memory to hold it all.
 However, on many computers addresses are 32 or 64 bits, giving an address space of 232 or 264 bytes,
respectively.

Unit 1 – Introduction to Operating System 95


 3. Files: To provide a place to keep files, most PC operating systems have the concept of a directory as a way of grouping
files together

A file system for a university department


Unit 1 – Introduction to Operating System 96
Section - 11
Multiprogramming v/s Multiprocessing v/s Multitasking

Multiprogramming Multiprocessing Multitasking

Unit 1 – Introduction to Operating System 98


Multiprogramming v/s Multiprocessing v/s Multitasking
Multiprogramming Multiprocessing Multitasking
The concurrent residency of The availability of more than The execution of more than
more than one program in one processor per system, one task simultaneously is
the main memory is called which can execute several set called as multitasking.
as multiprogramming. of instructions in parallel is
called as multiprocessing
Number of processor: one Number of processor: more Number of processor: one
than one
One process is executed at More than one process can be One by one job is being
a time. executed at a time. executed at a time.
Multitasking is a logical extension of multi programming. The major way in which
multitasking differs from multi programming is that multi programming works solely
on the concept of context switching whereas multitasking is based on time sharing
alongside the concept of context switching.
Unit 1 – Introduction to Operating System 99
Database Management Systems (DBMS)
GTU # 3130703

Thank
You

You might also like