module 1
module 1
(18CS43)
Acknowledgment
Reference Books
1. Ann McHoes Ida M Fylnn, Understanding Operating System, Cengage Learning,
6th
Edition
2. D.M Dhamdhere, Operating Systems: A Concept Based Approach 3rd Ed,
McGraw-
Hill, 2013.
3. P.C.P. Bhatt, An Introduction to Operating Systems: Concepts and Practice 4th
Edition,
PHI(EEE), 2014.
4. William Stallings Operating Systems: Internals and Design Principles, 6th Edition,
Pearson.
Chapter 1: Introduction
Chapter 1: Introduction
1.1 What Operating Systems Do
1.2 Computer-System Organization
1.3 Computer-System Architecture
1.4 Operating-System Structure
1.5 Operating-System Operations
1.6 Process Management
1.7 Memory Management
1.8 Storage Management
1.9 Protection and Security
1.10 Distributed system
1.11 Special-purpose systems
1.12 Computing Environments
Objectives
o The hardware,
o The operating system,
o The application programs,
o The users
Four Components of a Computer System
Computer System Structure
Computer system can be divided into four components:
Hardware – provides basic computing resources
CPU, memory, I/O devices
Application programs – define the ways in which the
system resources are used to solve the computing
problems of the users
Word processors, compilers, web browsers, database
systems, video games
Operating system
Controls and coordinates use of hardware among
various applications and users
Users
People, machines, other computers
1.1.2 What Operating Systems Do
Depends on the point of view
Users View
Users want convenience, ease of use and good performance
Don’t care about resource utilization
But shared computer such as mainframe or minicomputer
must keep all users happy
Users of dedicate systems such as workstations have
dedicated resources but frequently use shared resources from
servers
Handheld computers are resource poor, optimized for usability
and battery life
Some computers have little or no user interface, such as
embedded computers in devices and automobiles
System View
OS is a resource allocator
OS is a control program
Instruction-execution cycle
Storage Structure
Main memory –
Main memory is usually too small to store all needed
programs and data permanently.
Typically volatile
Secondary storage – extension of main memory that provides
large nonvolatile storage capacity
Hard disks – rigid metal or glass platters covered with
magnetic recording material
Disk surface is logically divided into tracks, which are subdivided into
sectors
The disk controller determines the logical interaction between the
device and the computer
Solid-state disks – faster than hard disks, nonvolatile
Storage Hierarchy
Speed
Cost
Volatility
Storage-Device Hierarchy
1.2.3 I/O structure
CPUs and multiple device controllers
Only one interrupt is generated per block, rather than the one
interrupt per byte
How a Modern Computer Works
Multiprocessor systems
Clustered systems
1.3.1 Single-Processor Systems
On a single processor system, there is one main CPU capable
of executing a general-purpose instruction set, including
instructions from user processes
Almost all single processor systems have other special-
purpose processors as well such as disk, keyboard and so on
All of these special-purpose processors run a limited
instruction set and do not run user processes
Sometimes, they are managed by the operating system
For example, a disk-controller microprocessor receives a
sequence of requests from the main CPU and implements its
own disk queue and scheduling algorithm. This arrangement
relieves the main CPU of the overhead of disk scheduling
PCs contain a microprocessor in the keyboard to convert the
keystrokes into codes to be sent to the CPU
1.3.2 Multiprocessor systems
Multiprocessors systems growing in use and importance
Also known as parallel systems, tightly-coupled
systems
Advantages include:
1. Increased throughput
2. Economy of scale
3. Increased reliability – graceful degradation or fault
tolerance
Two types:
1. Asymmetric Multiprocessing – each processor is
assigned a specie task.
2. Symmetric Multiprocessing – each processor
performs all tasks
Symmetric Multiprocessing Architecture
A Dual-Core Design
Multi-chip and multicore
Systems containing all chips
Chassis containing multiple separate systems
1.3.3 Clustered Systems
Like multiprocessor systems, but multiple systems working
together
Usually sharing storage via a storage-area network (SAN)
Provides a high-availability service which survives failures
Asymmetric clustering has one machine in hot-standby
mode
Symmetric clustering has multiple nodes running
applications, monitoring each other
Some clusters are for high-performance computing (HPC)
Applications must be written to use parallelization
Some have distributed lock manager (DLM) to avoid
conflicting operations
Clustered Systems
1.4 Operating System Structure
Cache management
Cache size
Replacement policy
Performance of Various Levels of Storage
Another set of OS functions exists for ensuring the efficient operation of the
system itself via resource sharing
Resource allocation - When multiple users or multiple jobs running
concurrently, resources must be allocated to each of them
Many types of resources - CPU cycles, main memory, file storage,
I/O devices.
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
A View of Operating System Services
2.2.1 User Operating System Interface - CLI
CLI or command interpreter allows direct command entry
Sometimes implemented in kernel, sometimes by systems
program
Sometimes multiple flavors implemented – shells eg-
Bourne shell, C shell, Korn shell etc
Primarily fetches a command from user and executes it
Sometimes commands built-in, sometimes just names of
programs like rm file.txt
If the latter, adding new features doesn’t require shell
modification
2.2.2 User Operating System Interface - GUI
User-friendly desktop metaphor interface
Usually mouse, keyboard, and monitor
Icons represent files, programs, actions, etc
Various mouse buttons over objects in the interface cause
various actions (provide information, options, execute
function, open directory (known as a folder)
Invented at Xerox PARC
Many systems now include both CLI and GUI interfaces
Microsoft Windows is GUI with CLI “command” shell
Apple Mac OS X is “Aqua” GUI interface with UNIX kernel
underneath and shells available
Unix and Linux have CLI with optional GUI interfaces (CDE,
KDE, GNOME)
2.3 System Calls
The system call interface invokes the intended system call in OS kernel and
returns status of the system call and any return values
The caller need know nothing about how the system call is implemented
Just needs to obey API and understand what OS will do as a result call
Most details of OS interface hidden from programmer by API
Managed by run-time support library (set of functions built into
libraries included with compiler)
API – System Call – OS Relationship
System Call Parameter Passing
Often, more information is required than simply identity of
desired system call
Exact type and amount of information vary according to OS
and call
Three general methods used to pass parameters to the OS
Simplest: pass the parameters in registers
In some cases, may be more parameters than registers
Parameters stored in a block, or table, in memory, and
address of block passed as a parameter in a register
This approach taken by Linux and Solaris
Protection
Control access to resources
Get and set permissions
Allow and deny user access
Examples of Windows and Unix System Calls
2.5 System Programs
System programs provide a convenient environment for
program development and execution.
Most users’ view of the operation system is defined by
system programs, not the actual system calls
System Programs
Provide a convenient environment for program development and
execution
Some of them are simply user interfaces to system calls; others
are considerably more complex
1. File management - Create, delete, copy, rename, print, dump,
list, and generally manipulate files and directories
2. Status information
Some ask the system for info - date, time, amount of available
memory, disk space, number of users
Others provide detailed performance, logging, and debugging
information
Typically, these programs format and print the output to the
terminal or other output devices
Some systems implement a registry - used to store and
retrieve configuration information
System Programs (Cont.)
3. File modification
Text editors to create and modify files
Special commands to search contents of files or perform
transformations of the text
4. Programming-language support –
Compilers, assemblers, debuggers and interpreters sometimes
provided
5. Program loading and execution-
Absolute loaders, relocatable loaders, linkage editors, and overlay-
loaders, debugging systems for higher-level and machine language
6. Communications - Provide the mechanism for creating virtual
connections among processes, users, and computer systems
Allow users to send messages to one another’s screens, browse
web pages, send electronic-mail messages, log in remotely,
transfer files from one machine to another
2.6 Operating System Design and Implementation
messages messages
microkernel
hardware
2.7.4 Modules
Many modern operating systems implement loadable kernel modules
Uses object-oriented approach
Each core component is separate
Each talks to the others over known interfaces
Each is loadable as needed within the kernel
Overall, similar to layers but with more flexible
Linux, Solaris, etc
Solaris Modular Approach
2.7.4 Hybrid Systems
Most OSes today do not strictly adhere to one architecture, but are
hybrids of several.
Mac OS X
The Max OSX architecture relies on the Mach microkernel for basic
system management services, and the BSD kernel for additional
services.
Application services and dynamically loadable modules ( kernel
extensions ) provide the rest of the OS functionality:
2.8 Virtual Machines
To abstract the hardware of a single computer into several different
execution environment.
The concept of a virtual machine is to provide an interface that looks
like independent hardware, to multiple different OSes running
simultaneously on the same physical hardware.
Each OS believes that it has access to and control over its own CPU,
RAM, I/O devices, hard drives, etc.
One obvious use for this system is for the development and testing of
software that must run on multiple platforms and/or OSes.
One obvious difficulty involves the sharing of hard drives, which are
generally partitioned into separate smaller virtual disks(mini disk) for
each operating OS.
Virtual machines first appeared as the VM Operating System for IBM
mainframes in 1972.
2.8.1 Implementation
Implementation may be challenging, partially due to the
consequences of user versus kernel mode.
Each of the simultaneously running kernels needs to operate in
kernel mode at some point, but the virtual machine actually runs
in user mode.
So the kernel mode has to be simulated for each of the loaded
OSes, and kernel system calls passed through the virtual
machine into a true kernel mode for eventual HW access.
The virtual machines may run slower, due to the increased levels of
code between applications and the HW, or they may run faster, due
to the benefits of caching or spooling. ( And virtual devices may
also be faster than real devices, such as RAM disks which are
faster than physical disks. )
2.8.2 Benefits
Maximize CPU use, quickly switch processes onto CPU for time
sharing
Process scheduler selects among available processes for next
execution on CPU
Maintains scheduling queues of processes
Job queue – set of all processes in the system
Ready queue – set of all processes residing in main memory,
ready and waiting to execute
Device queues – set of processes waiting for an I/O device
Processes migrate among the various queues
Ready Queue And Various I/O Device Queues
Representation of Process Scheduling
init
pid = 1
emacs tcsch
ps
pid = 9204 pid = 4005
pid = 9298
Process Creation (Cont.)
Address space
Child duplicate of parent
Child has a program loaded into it
UNIX examples
fork() system call creates new process
exec() system call used after a fork() to replace the process’
memory space with a new program
C Program Forking Separate Process
Creating a Separate Process via Windows API
3.3.2 Process Termination
Some operating systems do not allow child to exists if its parent has
terminated. If a process terminates, then all its children must also be
terminated.
cascading termination. All children, grandchildren, etc. are
terminated.
The termination is initiated by the operating system.
The parent process may wait for termination of a child process by
using the wait()system call. The call returns status information and
the pid of the terminated process
pid = wait(&status);
If no parent waiting (did not invoke wait()) process is a zombie
If parent terminated without invoking wait , process is an orphan
3.4 Interprocess Communication
Processes within a system may be independent or cooperating
Independent - if it cannot affect or be affected by the other processes executing
in the system – do not share data with any
Cooperating process can affect or be affected by other processes, including
sharing data
Reasons for cooperating processes:
Information sharing
Computation speedup
Modularity
Convenience
Cooperating processes need interprocess communication (IPC)
Shared data
#define BUFFER_SIZE 10
typedef struct {
...
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
item next_produced;
while (true) {
/* produce an item in next produced */
while (((in + 1) % BUFFER_SIZE) == out)
; /* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
Bounded Buffer – Consumer
item next_consumed;
while (true) {
while (in == out)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
Network
Logical:
Direct or indirect
Synchronous or asynchronous
message next_produced;
while (true) {
/* produce an item in next produced */
send(next_produced);
}
message next_consumed;
while (true) {
receive(next_consumed);