Chapter 1: Introduction
(OS Structure, Modes and Services)
By: Navjot Kaur
Topics Covered
-- Zero Lecture
Learning Outcome:
Topics to be Covered
Students will be able to
-- Introduction
understand OS Structure
-- OS Structure
and types of OS
-- Type of OS
OPERATING SYSTEM?
Abstract: To simplify
how hardware
actually looks like.
Arbitrate: To
manage , to oversee
the hardware use
What is an Operating System?
It is a layer of system software that:
directly has privileged access to
underlined hardware
hides hardware complexity
manages hardware on behalf of one
or more applications according to
policies.
What is an Operating System?
What is an Operating system?
A program that acts as an intermediate/
interface between a user of a computer and
the computer hardware.
Resource allocator (Managing the resources
efficiently)
Control Program
Operating system goals:
Execute user programs and make problem-
solving easier.
Make the computer system convenient to use
Efficiently use available resources
Computer System Structure
Computer system can be divided into four components:
Hardware – provides basic computing resources
CPU, memory, I/O devices
Operating system
Controls and coordinates use of resources among
various applications and users
System/Application programs – define the ways in
which the system resources are used to solve user
problems
Word processors, compilers, web browsers,
database systems, video games
Users
People, machines, other computers
Four Components of a Computer System
Computer System Organization
Computer-system operation
One or more CPUs, device controllers connect through
common bus providing access to shared memory
Concurrent execution of CPUs and devices competing for
memory cycles
TYPES OF OS
Batch Systems
“Batch operating system. The users of a batch operating system do
not interact with the computer directly.
Each user prepares his job on an off-line device like punch cards and
submits it to the computer operator.
To speed up processing, jobs with similar needs are batched together
and run as a group”.
TYPES OF OS: Batch Systems
To speed up processing, operators batched jobs with
similar needs together and ran them through the
computer as a group.
User Prepares a JOB (Program) using Punch Cards
Computer
Operator Wait for Output
TYPES OF OS: Batch Systems
Disadvantages:
No interaction between user and computer.
No mechanism to prioritize the processes
Multiprogrammed OS
Multiprogramming: When 2 or more processes reside
in memory at the same time
Single-user processes cannot keep CPU and I/O
devices busy at all times
Multiprogramming organizes jobs (code and data)
so the CPU always has one to execute
Multiprogramming assumes a single shared
processor.
Multiprogramming increases CPU utilization.
It is mixture of I/O bound and CPU bound processes
Multiprogrammed OS
If several jobs are ready to run at the same time,
then the system chooses which one to run
through the process of CPU Scheduling.
In Non-multiprogrammed system, there are
moments when CPU sits idle and does not do
any work.
Note:: In Multiprogramming system, CPU will
never be idle and keeps on processing.
Revision
Q. What is the objective of multiprogramming
operating systems?
a) Maximize CPU utilization
b) Switch the CPU among processes
c) Achieve multitasking
d) None of the above
Ans. a)
MCQ
Which of the following features will characterize an OS
as a multi-programmed OS?
1. More than one program may be loaded into the main
memory at the same time.
2. If a program waits for a certain event, another
program is immediately scheduled.
3. If the execution of a program terminates, another
program is immediately scheduled.
(a) Only
(b) (1) and (2) only
(c) (1) and (3) only
(d) (1), (2) and (3) only
MCQ
Which of the following features will characterize an OS
as a multi-programmed OS?
Ans. (d)
Q. Who controls the execution of programs
to prevent errors and improper use of
computer?
a) Resource allocator
b) Control Program
c) Hardware
d) None of the above
Q. In which type of operating system users do not
interact directly with the computer system?
a) Multiprogramming operating systems
b) Multiprocessing operating systems
c) Batch operating systems
d) Distributed operating systems
Ans ) c
Topics Covered
-- Types of OS
Learning Outcome:
Topics to be Covered
Students will be able to
-- OS Functions
understand OS modes and
-- OS Views
System call working
-- System Calls
Multitasking/Timesharing OS
Timesharing (multitasking) when multiple jobs
are executed by the CPU simultaneously by
switching between them.
There is at least one program executing in
the memory process
If several jobs ready to run at the same time
CPU scheduling
If processes don’t fit in memory, swapping
moves them in and out to run
Only one CPU is involved, but it switches
from one process to another so quickly that it
gives the appearance of executing all of the
processes at the same time.
Multiprocessing OS
A multiprocessor system consists of several processing units
that share a common physical memory.
Multiprocessor system provides higher computing power and
speed.
In a multiprocessor system all processors operate under a single
operating system.
Also known as parallel systems or tightly coupled systems
Such systems have more than one processor/processing cores
in close communication, sharing the computer bus, the clock,
and sometimes memory and peripheral devices.
Operating System Views
OS can be explored from 2 view points:
1. User view:
The goal of the Operating System is to
maximize the work and minimize the effort
of the user.
Operating System gives an effect to the
user as if the processor is dealing only with
the current task, but in background
processor is dealing with several processes.
Operating System Views
OS can be explored from 2 view points:
2. System View:
Operating System is a program involved with the
hardware.
OS is a resource allocator
Allocates and Manages all resources and their
sharing.
Decides between conflicting requests for
efficient and fair resource use
OS is a control program
Controls execution of programs to prevent
errors and improper use of the computer
It prevents improper usage, error and handle
deadlock conditions.
Operating-System Operations
OS’s are Interrupt driven. If no process, no I/o
devices, No users then OS will sit quietly
waiting for some event to occur.
Program or software send, Generate
interrupts/ events by using system calls. Error
or request by a software creates exception or
trap
E.g. Division by zero
Operating-System Operations
To protect OS, Dual-mode operations exist:
User mode (1) and kernel mode (0)
A Mode bit is added to the hardware to
indicate mode
Provides the ability to distinguish when
the system is running user mode or
kernel mode
System call changes mode to the kernel,
return from call resets it to user
User/Kernel Protection Boundary
Transition from User to Kernel Mode
The operating system switches
from user mode to kernel mode so
the mode bit will change from?
a) 0 to 1
b) 1 to 0
c) Remain constant
d) None
Which program provides the interface
between a process and the operating
system?
a) Interrupt
b) System calls
c)CPU
d)Device Controller
Which one or more of the following
options guarantee that a computer
system will transition from user mode to
kernel mode?
a) Function Call
b) malloc Call
c) Page Fault
d) System Call
System call routines of operating system
are mostly written in
a) C
b) C++
c) java
d) both a and b
Operating System Functions/Services
An operating system provides an environment for the
programs to run.
It provides certain services to programs
Operating System Services
Operating-system services provides functions
that are helpful to the user:
User interface - Almost all operating systems have a
user interface (UI)
Varies between Command-Line (CLI), Graphics User
Interface (GUI).
Program execution - The system must be able to load a
program into memory and to run that program, end
execution, either normally or abnormally (indicating
error)
I/O operations - A running program may require I/O,
which may involve a file or an I/O device.
File-system manipulation - read and write files and
directories, create and delete them, search them, list
file Information, permission management.
Operating System Services
Communications – Processes may exchange information, on
the same computer or between computers over a network
Communications may be via shared memory or through
message passing (packets moved by the OS)
Error detection – OS needs to be constantly aware of possible
errors
May occur in the CPU and memory hardware, in I/O devices,
in user program
For each type of error, OS should take the appropriate
action to ensure correct and consistent computing
Debugging facilities can greatly enhance the user’s and
programmer’s abilities to efficiently use the system.
Resource allocation – OS must ensure allocation of resources
to all programs running.
Many types of resources - such as CPU cycle time, main
memory, and file storage, I/O devices
Operating System Services
Accounting - To keep track of which users use how much and what
kinds of
computer resources.
Protection and security - The owners of information stored in a
multiuser or networked computer system may want to control use
of that information, concurrent processes should not interfere
with each other
Protection involves ensuring that all access to system
resources is controlled
Security of the system from outsiders requires user
authentication, extends to defending external I/O devices from
invalid access attempts
If a system is to be protected and secure, precautions must be
instituted throughout it.
A chain is only as strong as its weakest link.
Interrupts
An interrupt is a signal from a device attached
to a computer or from a program within the
computer that causes the main program that
operates the computer (the operating system)
to stop and figure out what to do next.
Interrupts can be of following type:
Generated by Hardware (Hardware Interrupt)
Generated by Software (Software Interrupt)
Hardware Interrupt
1. Hardware interrupts are used by devices to
communicate that they require attention from
the operating system.
2. Hardware interrupts by sending signal to CPU
via system bus.
3. Hardware interrupts are referenced by
an interrupt number.
4. These numbers are mapped with hardware
that created the interrupt. This enables the
system to monitor/understand which device
created the interrupt and when it occurred.
Software Interrupt/ Trap
Interrupt generated by executing a
instruction.
Software interrupts by a special
operation called a System Call or
Monitor Call.
Exp: 1. cout in C++ is a kind of interrupt
because it would make a system to
print something.
2. division by zero
I/O Interrupt
Once the I/O is started, 2 kind of
interrupts may arise:
Synchronous interrupt (I/O): The control is
transferred to the user process when I/O
completes.
Asynchronous interrupt (I/O): Returns
control to user process without waiting
for I/O to complete.
(a) Synchronous (b) Asynchronous
System Calls
Allow user-level processes to request services of the
operating system.
It provides a way in which program talks to the
operating system.
Why system calls are required?
It is a request to the operating system to perform
some activity.
It is a call to the kernel in order to execute a specific
function that controls a device or executes a
instruction.
A system call looks like a procedure call
Example of System Calls
System call sequence to copy the
contents of one file to another file
API – System Call – OS
Relationship
Standard C Library Example
C program invoking printf() library call,
which calls write() system call
System Call Parameter Passing
Passing Parameters to System Calls:
Information required for a system call vary
according to OS and call.
Three general methods used to pass
parameters to the OS
1. Pass the parameters in registers
When parameters are < 6.
2. Parameters stored in a block, or table, in memory, and
address of block passed as a parameter in a register.
(6 or more)
This approach taken by Linux and Solaris
3. Parameters placed, or pushed, onto the stack by the
program and popped off the stack by the operating
system.
Types of System Calls
5 Categories
Process Control File Management
end, abort create file, delete
load, execute file
create process, open, close file
terminate process
read, write,
get process reposition
attributes, set
process attributes get and set file
wait for time
attributes
wait event, signal
event
allocate and free
Types of System Calls (Cont.)
Device Management Communications
request device, release create, delete
device
communication
read, write, reposition connection
get device attributes, set send, receive
device attributes messages
logically attach or detach transfer status
devices information
Information Maintenance attach and detach
get time or date, set time or remote devices
date
get system data, set system
data
get and set process, file, or
device attributes
System Call Implementation
When we execute a C program, CPU
runs in ____ mode.
a) user
b) kernel
c) supervisory
d) system
Who signalled for the occurrence of
an event either from the hardware
or the software?
a) Bootstrap program
b) Interrupt
c) Disk Controller
d) CPU
Ans b