Operating System
Operating System
1 Introduction
2 Functions of Operating Systems
3 Process Management
4 CPU Scheduling
5 File Management
6 Memory Management
7 Memory Management (Advanced)
2 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Introduction
Module 1
Duration: 1 hr
4 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Conceptual View of System Components
5 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Computer System Components
Hardware
– provides basic computing resources (CPU, memory, I/O devices)
Operating system
– controls and manage the use of hardware among the various application
programs for the various users
• Applications programs
– define the ways in which the system resources are used to solve the computing
problems of the users (video games ,compilers, database systems,, business
programs)
6 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Goals of Operating System
7 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Functions of Operating Systems
Resource allocator
– manages and allocates resources
Control program
– controls the execution of user programs and operations of I/O devices
Kernel
– the one program running at all times (all else being application programs)
8 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Types of OS
9 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Time-Sharing Systems –Interactive Computing
The CPU is multiplexed among several jobs that are kept in memory and
on disk.
10 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Desktop Systems
Personal computers
– computer system dedicated to a single user
Input/output devices
– keyboards, display screens, printers
May run several different types of operating systems (Windows, Mac OS,
UNIX, Linux)
11 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Real-Time Systems
12 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Real-Time Systems (Contd.).
Hard real-time
– Secondary storage maybe absent or limited, data stored in short term memory,
or read-only memory (ROM)
– Conflicts with time-sharing systems, and not supported by general-purpose
operating systems
Soft real-time
– Limited utility in industrial control of robotics
– Useful in applications (multimedia, virtual reality) requiring advanced operating-
system features
13 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Handheld Systems
Cellular telephones
Issues:
– Limited memory
– Slow processors
– Small display screens
14 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Other OS types
Mainframe
Parallel processor
Distributed systems
15 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Summary
16 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Functions of Operating System
Module 2
Duration: 2 hrs
18 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Operating System Functionalities
19 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File Management
20 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Main-Memory Management
Major task of OS
– keep track of which part of memory are currently being used and by which
program
– decide which process are loaded into memory when memory space becomes
available
– Allocate and reallocated memory space as needed
21 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Process Management
22 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
I/O Management - structure
After I/O starts, control returns to user program only upon I/O completion.
– Wait instruction idles the CPU until the occurrence of next interrupt
– Wait loop (memory access contention)
– At most one I/O request is outstanding at a time, no simultaneous I/O
processing
After I/O starts, control returns to user program without waiting for I/O
completion
– System call – request to the operating system to allow user to wait for
completion of I/O
– Device-status table maintains a details of each I/O device such as device type,
its address, and state
– Operating system looks into I/O device table to find device status such that to
modify table entry to include interrupt
23 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
I/ O Management - Operations
User desires that the I/O has been performed without any details.
Hides the user the details of underlying H/W for the I/O.
24 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Security Management & User management
Login
User name
Password
Environment variables
Profile files
25 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Security Management (Contd.).
User Management:
All users will have unique identifier typically, user name in the system
26 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Computer System Operation
27 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Interrupts
Common Functions :
28 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Interrupt Handling
29 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Storage Structure
Main memory
Secondary storage
Magnetic disks
30 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Moving-Head Disk Mechanism
31 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Direct Memory Access Structure
Only on interrupt is generated per block, rather than the one interrupt
per byte
32 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Storage Hierarchy
33 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Caching
Caching requires data that is concurrently stored in more than one level
and when it need to be consistent
34 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Memory & I/O Protection
35 ©
35
© 2011
2011 Wipro
Wipro Ltd
Ltd
CPU Protection
36 ©
36
© 2011
2011 Wipro
Wipro Ltd
Ltd
Booting a system
Loading the operating system into memory is called booting the system
37 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Summary
38 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Process Management
Module 3
Duration: 3 hrs
40 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Process Management
41 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Processes
Operating system need to keep track of the process itself and managing
system resources along with other processes in the system fairly
42 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Process Execution
Process mode:
In case of UNIX, the computer hardware must provide two modes of execution
kernel mode
user mode
However, some computers will take more than two execution modes
Each process has virtual address space , references to virtual memory are
translated to physical memory locations using set of address translation
maps
43 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Process Life cycle
– Ready
– Running
– Wait
– stopped
– zombie
44 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Process Life cycle (Contd.).
User
Running
switch
Ready
to wakeup asleep
run
45 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Times and Timers
The kernel keeps track of a processes creation time as well as the CPU
time that it consumes during its lifetime
Each clock tick, the kernel updates the amount of time that the current
process has spent in system and in user mode
46 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Process Scheduling
All processes run partially in user mode and partially in system mode
User mode has far less privileges than system mode. Each time a process
makes a system call it swaps from user mode to system mode and
continues execution
The program that selects the most justifiable process to execute of all of
the executable processes in the system is known as Scheduler.
47 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Process Creation
Resource sharing
• Parent and derived one will share all resources
• Derived one will share subset of parent’s resources
• Parent and Derived one will share no resources
Execution
• Parent and derived process run concurrently
• Parent waits until derived process terminate
Address space
• Derived process duplicate of parent.
• Derived process has a program loaded into it
48 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Process & Thread
Process:
Thread:
The Thread that share global data and address space with other threads
running in the same process
49 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Thread
• What is a thread?
50 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Multiple Threads:
51 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Single and Multithreaded Processes
thread
52 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Threads - Benefits
Responsiveness
Resource Sharing
Utilization of MP Architectures
Economy
53 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Types of Thread
User Thread
Kernel Threads
PThreads
54 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
User Threads
Examples:
55 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Kernel Threads
56 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Pthreads
57 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Process Management : Hands-on (1 hour)
58 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Summary
59 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
CPU Scheduling
Module 4
Duration: 2 hrs
61 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
CPU Utilization
62 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
CPU Scheduling
Scheduler selects from among the processes in memory that are ready to
execute, and allocates the CPU to one of them
63 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Scheduling Criteria - Optimization
CPU utilization
– keep the CPU as busy as possible
Throughput
– # of processes that complete their execution per time unit
Turnaround time
– amount of time to execute a particular process
Waiting time
– amount of time a process has been waiting in the ready queue
Response time
– amount of time it takes from when a request was submitted until the first response
is produced, not output (for time-sharing environment)
64 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Optimization Criteria
Max throughput
65 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Scheduling Algorithm
Priority Scheduling
Real-Time Scheduling
66 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
First-Come, First-Served (FCFS) Scheduling
Process Burst Time
PI 24.0
PII 3.0
PIII 3.0
PI PII PIII
0 24 27 30
67 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
FCFS Scheduling (Contd.).
PII PIII PI
0 3 6 30
68 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Shortest-Job-First (SJF) Scheduling
Associate with each process the length of its next CPU burst. Use these
lengths to schedule the process with the shortest time
Two schemes:
– Non-preemptive
– preemptive
SJF is optimal
69 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Example of Non-Preemptive SJF
SJF (non-preemptive)
0 3 7 8 12 16
70 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Example of Preemptive SJF
SJF (pre-emptive)
PI PII PIII PII PIV PI
0 2 4 5 7 11 16
71 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Priority Scheduling
72 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Round Robin (RR) Scheduling
On the principle that CPU must be shared between each ready process.
73 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Summary
CPU Scheduling
Scheduling Criteria
Range of Scheduling Algorithms
74 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File Management
Module 5
Duration: 4 hrs
76 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File System
77 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File Types
Data
Program
Documents
78 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File Name & Extension
79 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File Properties
Name
Type
Location
Size
Protection
80 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File Operations
81 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Open Files
– File pointer
– File-open count:
– Access rights
82 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Directory Organization - Goals
Grouping
– Logical grouping of files by properties (eg: all Pascal programs, all games…)
83 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Directory Structure
Directory
Files FD
FA FB
FC
Fn
84 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Directory Structure (Contd.).
– File Name
– File Type
– Address or Location
– Current Length
– Maximum Length
– Date created
– Date last updated (may be to dump)
– Date last accessed (may be to perform archival)
– Owner ID and
– Protection information
85 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Directory Structure Example
Tree-Structured Directories :
Efficient searching
Grouping Capability
Easy maintenance
86 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Directory - Operations
87 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Access Methods
88 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File Sharing
89 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File Sharing – Multiple Users
90 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File Sharing – Remote File Systems
Client-server model allows clients to mount remote file systems from servers
• Server can serve multiple clients
• Client and user-on-client identification is insecure or complicated
• NFS is standard UNIX client-server file sharing protocol
• CIFS is standard Windows protocol
• Remote calls are translated by standard operating system file calls
91 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File Sharing – Failure Modes
Remote file systems add new failure modes, due to network failure, server
failure
Recovery from failure can involve state information about status of each
remote request
92 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Protection
Types of access
– Read
– Write
– Execute
– Append
– Delete
– List
93 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File System - Unix
Single path name length must not be more than 1023 chars
94 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Example (Contd.).
– mount
• mount /dev/hda4 /usr
– umount
• Detaching will fail if the file system is busy
95 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Example – (Contd.).
Types of Files
Regular Files
– binary
• GIF, JPEG, Executable etc
– text
• scripts, program source code, documentation
– Supports sequential access and random access
Device File
– Allows programs to interact with hardware
– Kernel unit handles device management
Directory
– Can contain any type of files
– Think about “.” and “..”??
96 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Example – (Contd.).
File Permissions:-
97 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
File System: Hands-on (2 hours)
98 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Summary
99 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Memory Management
Module 6
Duration: 2 hrs
101 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Memory Management - why?
Input queue
– collection of processes on the disk waiting to be brought into memory
to run the program
102 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Memory Management Why?(Contd.).
The user program deals with logical addresses; it does not see the real
physical addresses.
103 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Memory Management - How?
Logical versus Physical Address
Logical address
– address generated by CPU; also known as virtual address
Physical address
– address seen by the memory unit
Logical and physical addresses are the same in compile-time and load-time
address-binding schemes; logical (virtual) and physical addresses differ in
execution-time address-binding scheme
104 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Memory Management Operations
Relocation
register
15000 Physical
Logical Address
cpu + Memory
Address
15350
350
Memory management
unit
105 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Memory Management operations (Contd.).
106 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Dynamic Linking
107 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Overlays
Maintains in memory only those statements and data required at any given
time.
108 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Swapping
Major part of swap time is transfer time; total transfer time is directly
proportional to the amount of memory swapped
109 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Swapping - Schematic View
Swap
out Swap
in
PI pII
disk
110 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Relocation and Limit Registers - Hardware Support
111 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Contiguous Allocation
– Resident operating system, usually held in low memory with interrupt vector.
– User processes then held in high memory Single- partition allocation
– Relocation-register scheme used to protect user processes from each other, and
from changing operating-system code and data.
– Relocation register contains value of smallest physical address; limit register
contains range of logical addresses – each logical address must be less than the
limit register
112 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Contiguous Allocation (Contd.).
Multiple-partition allocation
– Hole – block of available memory; holes of various size are scattered throughout
memory
– When a process arrives, it is allocated memory from a hole large enough to
accommodate it
– Operating system maintains information about:
– a) allocated partitions b) free partitions (hole)
113 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Dynamic Storage-Allocation Problem
Best-fit: Allocate the smallest hole that is big enough; to search entire
list, unless ordered by size. Produces the smallest leftover hole
Worst-fit: Allocate the largest hole; to search entire list. Produces the
largest leftover hole
[
114 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Summary
Dynamic Loading
Dynamic Linking and swapping
115 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Memory Management (Advanced)
Module 7
• Define fragmentation
• Explain technique used to implement fragmentation
• List various Inter process communications methods
• Explain Pipe technique to implement IPC
• Define Semaphore
Duration: 2 hrs
117 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Fragmentation
– Mix up memory contents to place all free memory together in one large block
– Compaction is possible only if relocation is dynamic, and is done at execution time
– I/O problem
• Latch job in memory while it is involved in I/O
• Do I/O only into Operating System buffers
118 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Paging
To run a program of size n pages, need to find n free frames and load
program
119 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Paging - Address Translation Scheme
• Page offset (d) – combined with base address to define the physical memory
address that is sent to the memory unit
Physical
Logical
address F0000
address ….00
cpu P d f d
F1111
p F ….11
Physical memory
Page table
120 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Implementation of Page Table
Page table is kept in main memory
The two memory access problem can be solved by the use of a special
fast-lookup hardware cache called associative memory or translation look-
aside buffers (TLBs)
121 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Paging Hardware With TLB
Tlb hit
TLB
F1111….11
F
Physical memory
Page table
122 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Inter Process Communication
123 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Inter Process Communications - Methods
Pipe
FIFO
Message queues
Shared memory
Semaphores
124 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
PIPE Definition
125 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
PIPE : Example
Client - Server
Standard
input Path Name
Machine Machine
126 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
FIFO - Introduction
Problem with pipes - Used only between processes that have a common
ancestor (ie., a parent-child relationship). however, fixed with the
introduction of named pipes or FIFOs
127 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
FIFO Basic concepts
Named pipe works similar to a regular pipe, but have certain differences
When all I/O is done by sharing processes, the named pipe remains in
the file system for later use
128 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
What is Shared Memory ?
Shared memory, as the name implies, allows two or more processes, which
have the appropriate permissions, to read and/or write to the same area
of memory
129 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Why go for Shared Memory
Data need not be copied to a kernel buffer and back again. Accessing
shared memory takes as much time as a normal memory access
Using shared memory is quite easy. After a shared memory segment is set
up, it is manipulated exactly like any other memory area
130 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Shared Memory (Contd.).
Shared memory is also much more flexible than other System V IPC
mechanisms. Its use is not limited to sending limited-length messages
(message queues) or monitoring a counter (semaphores)
131 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Shared Memory (Contd.).
132 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Semaphore
133 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Semaphore (Contd.).
134 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Summary
135 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
References
1. Silberschatz,Abraham. Baer,Peter,Galvin and Gagne,Greg(1999):Operating System
Principles 7th Edition. Retrieved on April 11. 2011, from
http://www.csc.gatech.edu/%7Ecopeland/305500/pdf/ch02_computer_struct_notes.pdf
2. Rusling A David(1996-1999 ) File translated from TEX by TTH, version 1.0. Retrieved on
April 11. 2011, from http://www.tldp.org/LDP/tlk/kernel/processes.html
5. Siberschatz and Galvin (2011) Memory Management . Retrieved on April 11. 2011, from
http://www.cse.buffalo.edu/%7Ebina/cse421/fall2002/memoryOct15.ppt
136 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
References
137 ©
© 2011
2011 Wipro
Wipro Ltd
Ltd
Thank You