Chapter 1: Introduction
(OS Structure, Modes and Services)
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
An operating system is the one program that is running at all the
times on the computer- usually called the kernel.
Kernel is a program that (allow) let the hardware to recognize and
read the program/process.
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 solving 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”.
*[https://www.tutorialspoint.com/operating_system/os_types.htm]
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 CPU
always has one to execute
Multiprogramming assumes a single shared processor. One
job selected and run via job scheduling
Multiprogramming increases CPU utilization.
It is mixture of I/O bound and CPU bound processes
Multitasking/Timesharing OS
Timesharing (multitasking) when multiple jobs are
executed by the CPU simultaneously by switching
between them.
There is at least one program is executing in 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.
Multitasking/ Time Sharing
Types of Multitasking:
1. Preemptive: the operating system parcels CPU time slices to each
program.
2. Cooperative: each program can control the CPU for as long as it
needs it.
If a program is not using the CPU, however, it can allow another
program to use it temporarily.
In time sharing systems the prime focus is on minimizing the
response time, while in multiprogramming the prime focus is to
maximize the CPU usage.
Multiprocessing OS
A multiprocessor system consists of several
processors that share a common physical memory.
Multiprocessor system provides higher computing
power and speed.
In multiprocessor system all processors operate
under single operating system.
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 Events by using
system calls. Error or request by a software creates
exception or trap
E.g. Division by zero
To ensure proper execution of OS, we must
distinguish between execution of OS code and user
defined code.
Operating-System Operations
To protect OS, Dual-mode operations exist:
User mode (1) and kernel mode (0)
A Mode bit is added to hardware to indicate mode
Provides ability to distinguish when system is
running user mode or kernel mode
System call changes mode to kernel, return from
call resets it to user
Transition from User to Kernel Mode
Operating System Structure
Various ways to structure a system
Simple Structure -- MS-DOS
MS-DOS – written to
provide the most
functionality in the least
space
Not divided into modules
Although MS-DOS has
some structure, its
interfaces and levels of
functionality are not well
separated
Non Simple Structure -- UNIX
The UNIX OS consists of two parts:
System programs
The kernel
Consists of everything below the system-call
interface and above the physical hardware
Provides the file system, CPU scheduling, memory
management, and other operating-system functions;
a large number of functions for one level
Traditional UNIX System Structure
Layered Approach
The operating system is
divided into a number of
layers (levels), each built on
top of lower layers. The
bottom layer (layer 0), is the
hardware; the highest (layer
N) is the user interface.
With modularity, layers are
selected such that each
uses functions (operations)
and services of only lower-
level layers
Operating System 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.
Kernel
A kernel is a central component of an operating system.
It acts as an interface between the user applications and the hardware.
The sole aim of the kernel is to manage the communication between the
software (user level applications) and the hardware (CPU, disk memory
etc).
The main tasks of the kernel are :
Process management
Device management
Memory management
Interrupt handling
I/O communication
File system...etc..
Kernel
A kernel is the lowest level of software that interfaces
with the hardware in your computer.
It is responsible for interfacing all applications that are
running in “user mode” down to the physical hardware,
and allowing processes, to get information from each
other using inter-process communication (IPC).
Kernel Types
kernels fall into one of three types:
Monolithic
Microkernel
Hybrid
Monolithic Kernel
A monolithic kernel is an operating system architecture
where the entire operating system (which includes the device
drivers, file system, and the application IPC etc.) is working
in kernel space, in supervisor mode.
Monolithic kernels are able to dynamically load (and unload)
executable modules at runtime.
Examples of operating systems that use a monolithic kernel
are - Linux, Solaris, OS-9, DOS, Microsoft Windows
(95,98,Me) etc.
Monolithic Kernel
Monolithic Kernel
Monolithic Kernel
Pros:
More direct access to hardware for programs
Easier for processes to communicate between each other
If your device is supported, it should work with no additional
installations
Processes react faster because there isn’t a queue for
processor time.
Cons:
Large install footprint
Large memory is needed
Less secure because everything runs in supervisor mode
MicroKernel
In a Microkernel architecture, the core functionality is isolated
from system services and device drivers.
This architecture allows some basic services like device driver
management, file system etc. to run in user space.
This reduces the kernel code size and also increases the
security and stability of OS as we have minimum code running
in kernel.
Examples of operating systems that use a microkernel are -
QNX, Integrity, PikeOS, Symbian, L4Linux, Singularity, K42,
Mac OS X, HURD, Minix, and Coyotos.
MicroKernel
Types of Kernel
MicroKernel
Pros
Portability
Small install footprint
Small memory
Security
Cons
Hardware is more abstracted through drivers
Hardware may react slower because drivers are in user mode
Processes have to wait in a queue to get information
Processes can’t get access to other processes without waiting
HybridKernel
Hybrid kernels have the ability to pick and choose what they
want to run in user mode and what they want to run in
supervisor mode.
Device drivers and file system I/O will be run in user mode
while IPC and server calls will be kept in the supervisor
mode.
This require more work of the hardware manufacturer
because all of the driver responsibility is up to them.
Hybrid Kernel
Pros
Developer can pick and choose what runs in user mode and
what runs in supervisor mode
Smaller install than monolithic kernel
More flexible than other models
Cons
Processes have to wait in a queue to get information
Processes can’t get access to other processes without
waiting
Device drivers need to be managed by user
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)
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
Waiting of I/O may be accomplished in 2
ways:
Wait: it let the CPU wait till the next
interrupt.
Loop: Loop continues until interrupt is
active.
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
Accessing System Calls
System calls are accessed by programs via a high-level
Application Program Interface (API) (provides run time
environment)
System calls are implemented via API, API’s interact with kernel of
OS.
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
Types of System Calls
5 Categories
Process Control File Management
end, abort create file, delete file
load, execute open, close file
create process, read, write, reposition
terminate process get and set file
get process attributes, attributes
set process attributes
wait for time
wait event, signal event
allocate and free
memory
Types of System Calls (Cont.)
Device Management Communications
request device, release device create, delete
read, write, reposition communication
get device attributes, set device connection
attributes send, receive
logically attach or detach devices messages
transfer status
Information Maintenance
information
get time or date, set time or date attach and detach
get system data, set system data remote devices
get and set process, file, or
device attributes