Os Mid
Os Mid
Operating System Concepts – 10h Edition Silberschatz, Galvin and Gagne ©2018
Objectives
Operating System Concepts – 10th Edition 1.2 Silberschatz, Galvin and Gagne ©2018
Computer System Structure
Operating System Concepts – 10th Edition 1.3 Silberschatz, Galvin and Gagne ©2018
Computer System Components
2. Software
Operating system – controls and coordinates use of hardware
among various applications and users
Other system programs
Application programs – the system resources are used to solve
the computing problems of the users
– Word processors, web browsers, database systems, games
Operating System Concepts – 10th Edition 1.4 Silberschatz, Galvin and Gagne ©2018
Computer System Components
Operating System Concepts – 10th Edition 1.5 Silberschatz, Galvin and Gagne ©2018
UNIX Architecture
Operating System Concepts – 10th Edition 1.6 Silberschatz, Galvin and Gagne ©2018
What are operating systems? What they
do?
Operating System Concepts – 10th Edition 1.7 Silberschatz, Galvin and Gagne ©2018
What is an OS?
OS Goals:
Execute user programs and make solving user problems easier
Make the computer system convenient to use
Use the computer hardware in an efficient manner
Operating System Concepts – 10th Edition 1.8 Silberschatz, Galvin and Gagne ©2018
What OS’s do?
Operating System Concepts – 10th Edition 1.9 Silberschatz, Galvin and Gagne ©2018
OS Definition (System’s View)
OS is a resource allocator
Manages all resources
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
Operating System Concepts – 10th Edition 1.10 Silberschatz, Galvin and Gagne ©2018
OS Kernel
The part of OS that resides in memory at all times, and performs the
most essential system tasks, and has a hardware protection
Aka OS nucleus
Copied into RAM, usually from the hard disk drive, during the computer
boot-up (or startup)
Operating System Concepts – 10th Edition 1.11 Silberschatz, Galvin and Gagne ©2018
Computer Startup
3. Bootstrap Loader: The BIOS looks for a small program called the "bootstrap
loader" stored in ROM or EPROM, generally known as firmware. Its job is to
locate and start (load into memory) the main part of the operating system
(i.e., the kernel).
4. Operating System: Once the kernel is up and running, it loads the full
operating system (like Windows or macOS) into memory.
Operating System Concepts – 10th Edition 1.12 Silberschatz, Galvin and Gagne ©2018
Why do we study operating systems?
Operating System Concepts – 10th Edition 1.13 Silberschatz, Galvin and Gagne ©2018
Computer System Organization
Operating System Concepts – 10th Edition 1.14 Silberschatz, Galvin and Gagne ©2018
Computer System Organization
Operating System Concepts – 10th Edition 1.15 Silberschatz, Galvin and Gagne ©2018
Computer System Operation
Operating System Concepts – 10th Edition 1.16 Silberschatz, Galvin and Gagne ©2018
Common Functions of Interrupts
An OS is interrupt driven
Operating System Concepts – 10th Edition 1.17 Silberschatz, Galvin and Gagne ©2018
Interrupt Handling
The OS preserves the state of the CPU by storing registers and the
program counter
Operating System Concepts – 10th Edition 1.18 Silberschatz, Galvin and Gagne ©2018
Interrupt Timeline
Operating System Concepts – 10th Edition 1.19 Silberschatz, Galvin and Gagne ©2018
I/O Structure
After I/O starts, control returns to user program only upon I/O
completion
Wait instruction idles the CPU until the next interrupt
Wait loop (contention for memory access)
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 OS to allow user to wait for I/O
completion
Device-status table contains entry for each I/O device indicating
its type, address, and state
OS indexes into I/O device table to determine device status and to
modify table entry to include interrupt
Operating System Concepts – 10th Edition 1.20 Silberschatz, Galvin and Gagne ©2018
Storage Hierarchy
Operating System Concepts – 10th Edition 1.21 Silberschatz, Galvin and Gagne ©2018
Storage Device Hierarchy
Operating System Concepts – 10th Edition 1.22 Silberschatz, Galvin and Gagne ©2018
Caching
Operating System Concepts – 10th Edition 1.23 Silberschatz, Galvin and Gagne ©2018
Direct Memory Access (DMA) Structure
Only one interrupt is generated per block, rather than the one interrupt
per byte
Operating System Concepts – 10th Edition 1.24 Silberschatz, Galvin and Gagne ©2018
How modern computers work?
Operating System Concepts – 10th Edition 1.25 Silberschatz, Galvin and Gagne ©2018
Computer System Architecture
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
Operating System Concepts – 10th Edition 1.26 Silberschatz, Galvin and Gagne ©2018
Symmetric Multiprocessing
Operating System Concepts – 10th Edition 1.27 Silberschatz, Galvin and Gagne ©2018
A Dual-Core Design
Multi-chip and multicore
Operating System Concepts – 10th Edition 1.28 Silberschatz, Galvin and Gagne ©2018
CPU 1 CPU 2
CPU 3 CPU 4
Source: https://www.scaler.com/topics/images/muticore_and_multiprocessor.webp
Operating System Concepts – 10th Edition 1.29 Silberschatz, Galvin and Gagne ©2018
Clustered Systems
Operating System Concepts – 10th Edition 1.30 Silberschatz, Galvin and Gagne ©2018
Clustered Systems
Operating System Concepts – 10th Edition 1.31 Silberschatz, Galvin and Gagne ©2018
Operating System Structures
Operating System Concepts – 10th Edition 1.32 Silberschatz, Galvin and Gagne ©2018
OS Structures
Simple batch system
Operating System Concepts – 10th Edition 1.33 Silberschatz, Galvin and Gagne ©2018
Memory Layout for
Multiprogrammed System
Operating System Concepts – 10th Edition 1.34 Silberschatz, Galvin and Gagne ©2018
Operating System Operations
Operating System Concepts – 10th Edition 1.35 Silberschatz, Galvin and Gagne ©2018
OS Operations
Interrupt driven (hardware and software)
Operating System Concepts – 10th Edition 1.36 Silberschatz, Galvin and Gagne ©2018
OS Operations (Cont.)
Operating System Concepts – 10th Edition 1.37 Silberschatz, Galvin and Gagne ©2018
Transition from User to Kernel Mode
Timer to prevent infinite loop / process hogging resources
Timer is set to interrupt the computer after some time period
Keep a counter that is decremented by the physical clock
OS sets the counter (privileged instruction)
When counter = 0, generate an interrupt
Set up before scheduling process to regain control or terminate
program that exceeds allotted time
Operating System Concepts – 10th Edition 1.38 Silberschatz, Galvin and Gagne ©2018
Operating System Subsystem Managers
Operating System Concepts – 10th Edition 1.39 Silberschatz, Galvin and Gagne ©2018
Source: Textbook 2 (Understanding Operating Systems), Fig. 1.1
Operating System Concepts – 10th Edition 1.40 Silberschatz, Galvin and Gagne ©2018
What does each subsystem manager do?
Takes responsibility of its own tasks
Monitors its resource continuously
Enforces the polices that determine who gets what, when, and
how much
Allocates the resource (among users, programs, processors, …)
Deallocates the resource
Operating System Concepts – 10th Edition 1.41 Silberschatz, Galvin and Gagne ©2018
Example: A user chooses a menu option
to open a program
1. The DM receives the electrical impulse caused by a click of the mouse,
decodes the command by calculating the location of the cursor.
Immediately, it sends the command to the PM.
3. The PM determines whether the user request requires that a file (in this
case a program file) be retrieved from storage, or whether it is already
in memory.
Operating System Concepts – 10th Edition 1.42 Silberschatz, Galvin and Gagne ©2018
Example: A user chooses a menu option
to open a program (Cont.)
5. If necessary, the MM finds space for the program file in main memory
and records its exact location. Once the program file is in memory, the
MM keeps track of its location in memory.
6. When the CPU is ready to run it, the program begins execution via the
PM.
7. The PM reassigns the CPU to the next program waiting in line. If the
file was modified, the FM and DM cooperate to store the results in
secondary storage.
8. The MM releases the program’s space in main memory and gets ready
to make it available to the next program that requires memory.
9. Finally, the UI displays the results and gets ready to take the next
command.
Operating System Concepts – 10th Edition 1.43 Silberschatz, Galvin and Gagne ©2018
OS Architectures
User program …
User program area
area
Operating System Concepts – 10th Edition 1.44 Silberschatz, Galvin and Gagne ©2018
Process Management
A process is a program in execution. It is a unit of work within the
system. Program is a passive entity, process is an active entity.
Process needs resources to accomplish its task
CPU, memory, I/O, files
Initialization data
Process termination requires reclaim of any reusable resources
Single-threaded process has one program counter specifying location
of next instruction to execute
Process executes instructions sequentially, one at a time, until
completion
Multi-threaded process has one program counter per thread
Typically system has many processes, some user, some OS running
concurrently on one or more CPUs
Concurrency by multiplexing the CPUs among the processes /
threads
Operating System Concepts – 10th Edition 1.45 Silberschatz, Galvin and Gagne ©2018
Process Management Activities
Operating System Concepts – 10th Edition 1.46 Silberschatz, Galvin and Gagne ©2018
Memory Management
All (or part) of the data that is needed by the program must be in
memory
Operating System Concepts – 10th Edition 1.47 Silberschatz, Galvin and Gagne ©2018
File Management
OS provides uniform, logical view of information storage
Abstracts physical properties to logical storage unit - file
Each medium is controlled by a device (i.e., disk drive, tape drive)
Varying properties include access speed, capacity, data-transfer
rate, access method (sequential or random)
File-System management
Files usually organized into directories
Access control on most systems to determine who can access what
OS activities include
Creating and deleting files and directories
Primitives to manipulate files and directories
Mapping files onto secondary storage
Backup files onto stable (non-volatile) storage media
Operating System Concepts – 10th Edition 1.48 Silberschatz, Galvin and Gagne ©2018
Mass-Storage Management
Usually disks used to store data that does not fit in main memory or data
that must be kept for a “long” period of time
Proper management is of central importance
Entire speed of computer operation hinges on disk subsystem and its
algorithms
OS activities
Free-space management
Storage allocation
Disk scheduling
Some storage doesn’t need to be fast
Tertiary storage includes optical storage, magnetic tape
Still must be managed – by OS or applications
Varies between WORM (write-once, read-many-times) and RW
(read-write)
Operating System Concepts – 10th Edition 1.49 Silberschatz, Galvin and Gagne ©2018
Migration from Disk to Register
Operating System Concepts – 10th Edition 1.50 Silberschatz, Galvin and Gagne ©2018
I/O Subsystem
Operating System Concepts – 10th Edition 1.51 Silberschatz, Galvin and Gagne ©2018
Protection and Security
Operating System Concepts – 10th Edition 1.52 Silberschatz, Galvin and Gagne ©2018
Protection and Security
Operating System Concepts – 10th Edition 1.53 Silberschatz, Galvin and Gagne ©2018
Computing Environments
Operating System Concepts – 10th Edition 1.54 Silberschatz, Galvin and Gagne ©2018
Traditional Computing
Stand-alone general-purpose machines
But blurred as most systems interconnect with others (i.e., the Internet)
Portals provide web access to internal systems
Network computers (thin clients) are like Web terminals
Mobile computers interconnect via wireless networks
Networking becoming ubiquitous – even home systems use firewalls to
protect home computers from Internet attacks
Operating System Concepts – 10th Edition 1.55 Silberschatz, Galvin and Gagne ©2018
Mobile Computing
Handheld smartphones, tablets, etc
What is the functional difference between them and a “traditional”
laptop?
Extra feature – more OS features (GPS, gyroscope)
Allows new types of apps like augmented reality
Use IEEE 802.11 wireless, or cellular data networks for connectivity
Leaders are Apple iOS and Google Android
Operating System Concepts – 10th Edition 1.56 Silberschatz, Galvin and Gagne ©2018
Distributed Computing
Distributed computiing
Collection of separate, possibly heterogeneous, systems networked
together
Network is a communications path, TCP/IP most common
– Local Area Network (LAN)
– Wide Area Network (WAN)
– Metropolitan Area Network (MAN)
– Personal Area Network (PAN)
Network OS provides features between systems across network
Communication scheme allows systems to exchange messages
Illusion of a single system
Operating System Concepts – 10th Edition 1.57 Silberschatz, Galvin and Gagne ©2018
Client-Server Computing
Client-Server Computing
Dumb terminals supplanted by smart PCs
Many systems are now servers, responding to requests generated
by clients
Compute-server system provides an interface to client to
request services (i.e., database)
File-server system provides interface for clients to store and
retrieve files
Operating System Concepts – 10th Edition 1.58 Silberschatz, Galvin and Gagne ©2018
Peer-to-Peer Computing
Operating System Concepts – 10th Edition 1.59 Silberschatz, Galvin and Gagne ©2018
Virtualization
Emulation used when the source CPU type differs from the target type
(e.g., PowerPC to Intel x86)
Generally slowest method
When computer language not compiled to native code –
Interpretation
Operating System Concepts – 10th Edition 1.60 Silberschatz, Galvin and Gagne ©2018
Virtualization (Cont.)
Use cases involve laptops and desktops running multiple OS’s for
exploration or compatibility
Apple laptop running Mac OS X host, Windows as a guest
Developing apps for multiple OS’s without having multiple systems
QA testing applications without having multiple systems
Executing and managing compute environments within data centers
VMM can run natively, in which case they are also the host
There is no general-purpose host then (VMware ESX and Citrix
XenServer)
Operating System Concepts – 10th Edition 1.61 Silberschatz, Galvin and Gagne ©2018
Virtualization
Operating System Concepts – 10th Edition 1.62 Silberschatz, Galvin and Gagne ©2018
Cloud Computing
Delivers computing, storage, even apps as a service across a network
Many types
Public cloud – available via Internet to anyone willing to pay
Private cloud – run by a company for the company’s own use
Hybrid cloud – includes both public and private cloud components
Software as a Service (SaaS) – one or more applications available via
the Internet (i.e., word processor)
Platform as a Service (PaaS) – software stack ready for application use
via the Internet (i.e., a database server)
Infrastructure as a Service (IaaS) – servers or storage available over
Internet (i.e., storage available for backup use)
Operating System Concepts – 10th Edition 1.63 Silberschatz, Galvin and Gagne ©2018
Cloud Computing (Cont.)
Cloud computing environments composed of traditional OS’s,
plus VMMs, plus cloud management tools
Operating System Concepts – 10th Edition 1.64 Silberschatz, Galvin and Gagne ©2018
Real-Time Embedded Computing
Operating System Concepts – 10th Edition 1.65 Silberschatz, Galvin and Gagne ©2018
End of Chapter 1
Operating System Concepts – 10h Edition Silberschatz, Galvin and Gagne ©2018
Chapter 2: Operating System
Structures
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Objectives
To describe the services an OS provides to users, processes, and other
systems
To discuss the various ways of structuring an OS
To explain how OS’s are debugged
Operating System Concepts – 10th Edition 2.2 Silberschatz, Galvin and Gagne ©2018
Operating System Services
Operating System Concepts – 10th Edition 2.3 Silberschatz, Galvin and Gagne ©2018
OS Services
OS provides an environment for execution of programs and services to programs
and users
I/O operations - A running program may require I/O, which may involve a
file or an I/O device
Operating System Concepts – 10th Edition 2.4 Silberschatz, Galvin and Gagne ©2018
OS Services (Cont.)
File system manipulation - Programs need to read and write files and
directories, create and delete them, search them, list file Information,
permission management.
Operating System Concepts – 10th Edition 2.5 Silberschatz, Galvin and Gagne ©2018
OS Services (Cont.)
Another set of OS functions exists for ensuring the efficient operation of the
system itself via resource sharing
Accounting - To keep track of which users use how much and what kinds of
computer resources
Operating System Concepts – 10th Edition 2.6 Silberschatz, Galvin and Gagne ©2018
Overview of OS Services
Operating System Concepts – 10th Edition 2.7 Silberschatz, Galvin and Gagne ©2018
User Operating System Interface
Operating System Concepts – 10th Edition 2.8 Silberschatz, Galvin and Gagne ©2018
User OS Interface – CLI
Operating System Concepts – 10th Edition 2.9 Silberschatz, Galvin and Gagne ©2018
Bourne Shell Command Interpreter
Operating System Concepts – 10th Edition 2.10 Silberschatz, Galvin and Gagne ©2018
User OS 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
Operating System Concepts – 10th Edition 2.11 Silberschatz, Galvin and Gagne ©2018
Touchscreen Interfaces
Voice commands
Operating System Concepts – 10th Edition 2.12 Silberschatz, Galvin and Gagne ©2018
The Mac OS X GUI
Operating System Concepts – 10th Edition 2.13 Silberschatz, Galvin and Gagne ©2018
System Calls
Operating System Concepts – 10th Edition 2.14 Silberschatz, Galvin and Gagne ©2018
System Calls
Programming interface to the services provided by the OS
Operating System Concepts – 10th Edition 2.15 Silberschatz, Galvin and Gagne ©2018
Example of System Calls
System call sequence to copy the contents of one file to another file
Operating System Concepts – 10th Edition 2.16 Silberschatz, Galvin and Gagne ©2018
Example of Standard API
Operating System Concepts – 10th Edition 2.17 Silberschatz, Galvin and Gagne ©2018
System Call Implementation
The caller doesn’t need to know 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
Operating System Concepts – 10th Edition 2.18 Silberschatz, Galvin and Gagne ©2018
API – System Call – OS Relationship
Operating System Concepts – 10th Edition 2.19 Silberschatz, Galvin and Gagne ©2018
System Call Parameter Passing
Operating System Concepts – 10th Edition 2.20 Silberschatz, Galvin and Gagne ©2018
Parameter Passing via Table
Operating System Concepts – 10th Edition 2.21 Silberschatz, Galvin and Gagne ©2018
Types of System Calls
Process control
create process, terminate process
end, abort
load, execute
get process attributes, set process attributes
wait for time
wait event, signal event
allocate and free memory
Dump memory if error
Debugger for determining bugs, single step execution
Locks for managing access to shared data between processes
Operating System Concepts – 10th Edition 2.22 Silberschatz, Galvin and Gagne ©2018
Types of System Calls (Cont.)
File management
create file, delete file
open, close file
read, write, reposition
get and set file attributes
Device management
request device, release device
read, write, reposition
get device attributes, set device attributes
logically attach or detach devices
Operating System Concepts – 10th Edition 2.23 Silberschatz, Galvin and Gagne ©2018
Types of System Calls (Cont.)
Information maintenance
get time or date, set time or date
get system data, set system data
get and set process, file, or device attributes
Communications
create, delete communication connection
send, receive messages if message passing model to host name
or process name
From client to server
Shared-memory model create and gain access to memory regions
transfer status information
attach and detach remote devices
Operating System Concepts – 10th Edition 2.24 Silberschatz, Galvin and Gagne ©2018
Types of System Calls (Cont.)
Protection
Control access to resources
Get and set permissions
Allow and deny user access
Operating System Concepts – 10th Edition 2.25 Silberschatz, Galvin and Gagne ©2018
Examples: Windows and Unix
Operating System Concepts – 10th Edition 2.26 Silberschatz, Galvin and Gagne ©2018
Standard C Library Example
C program invoking printf() library call, which calls write() system call
Operating System Concepts – 10th Edition 2.27 Silberschatz, Galvin and Gagne ©2018
Example: MS-DOS
Single-tasking
Shell invoked when system
booted
Simple method to run
program
No process created
Single memory space
Loads program into memory,
overwriting all but the kernel
Program exit shell
reloaded
Operating System Concepts – 10th Edition 2.28 Silberschatz, Galvin and Gagne ©2018
Example: FreeBSD
Unix variant
Multitasking
User login invoke user’s choice of shell
Shell executes fork() system call to create
process
Executes exec() to load program into
process
Shell waits for process to terminate or
continues with user commands
exit(): Process exits with:
code = 0 – no error
code > 0 – error code
Operating System Concepts – 10th Edition 2.29 Silberschatz, Galvin and Gagne ©2018
System Programs
Operating System Concepts – 10th Edition 2.30 Silberschatz, Galvin and Gagne ©2018
System Programs
System programs provide a convenient environment for program
development and execution. They can be divided into:
File manipulation
Status information sometimes stored in a file modification
Programming language support
Program loading and execution
Communications
Background services
Operating System Concepts – 10th Edition 2.31 Silberschatz, Galvin and Gagne ©2018
System Programs (Cont.)
Provide a convenient environment for program development and
execution
Some of them are simply user interfaces to system calls; others are
considerably more complex
File management - Create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories
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
Operating System Concepts – 10th Edition 2.32 Silberschatz, Galvin and Gagne ©2018
System Programs (Cont.)
File modification
Text editors to create and modify files
Special commands to search contents of files or perform
transformations of the text
Operating System Concepts – 10th Edition 2.33 Silberschatz, Galvin and Gagne ©2018
System Programs (Cont.)
Background services
Launch at boot time
Some for system startup, then terminate
Some from system boot to shutdown
Provide facilities like disk checking, process scheduling, error
logging, printing
Run in user context not kernel context
Known as services, subsystems, daemons
Operating System Concepts – 10th Edition 2.34 Silberschatz, Galvin and Gagne ©2018
Operating System Design and
Implementation
Operating System Concepts – 10th Edition 2.35 Silberschatz, Galvin and Gagne ©2018
OS Design & Implementation
Internal structure of different OS’s can vary widely
Operating System Concepts – 10th Edition 2.36 Silberschatz, Galvin and Gagne ©2018
OS Design & Implementation (Cont.)
Important principle to separate
Policy: What will be done?
Mechanism: How to do it?
Mechanisms determine how to do something
Policies decide what will be done
Operating System Concepts – 10th Edition 2.37 Silberschatz, Galvin and Gagne ©2018
Implementation
Variations
Early OS’s programmed in assembly
language
Then system programming languages
like Algol, PL/1
Now C, C++
Android:
Operating System Concepts – 10th Edition 2.39 Silberschatz, Galvin and Gagne ©2018
OS Structure
General-purpose OS is a very large program
Operating System Concepts – 10th Edition 2.40 Silberschatz, Galvin and Gagne ©2018
Simple OS Structure – MS DOS
Operating System Concepts – 10th Edition 2.41 Silberschatz, Galvin and Gagne ©2018
Non-Simple OS Structure – UNIX
The UNIX OS consists of two separable parts
Systems 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
Operating System Concepts – 10th Edition 2.42 Silberschatz, Galvin and Gagne ©2018
Non-Simple OS Structure – UNIX
Beyond simple but not fully layered
Operating System Concepts – 10th Edition 2.43 Silberschatz, Galvin and Gagne ©2018
Layered Approach
Operating System Concepts – 10th Edition 2.44 Silberschatz, Galvin and Gagne ©2018
Architecture of macOS and iOS
Operating System Concepts – 10th Edition 2.45 Silberschatz, Galvin and Gagne ©2018
Mac OS X Structure
kernel environment
BSD
Mach
Operating System Concepts – 10th Edition 2.46 Silberschatz, Galvin and Gagne ©2018
iOS
Operating System Concepts – 10th Edition 2.47 Silberschatz, Galvin and Gagne ©2018
Android
Developed by Open Handset Alliance (mostly led by Google)
Open Source
Similar stack to iOS (layered)
Based on Linux kernel but modified
Provides process, memory, device-driver management
Adds power management
Runtime environment includes core set of libraries and Dalvik virtual
machine
Apps developed in Java plus Android API
Java class files compiled to Java bytecode then translated to
executable than runs in Dalvik VM
Libraries include frameworks for web browser (webkit), database
(SQLite), multimedia, smaller libc
Operating System Concepts – 10th Edition 2.48 Silberschatz, Galvin and Gagne ©2018
Android Architecture
Application Framework
surface media
Dalvik
manager framework
virtual machine
webkit libc
Operating System Concepts – 10th Edition 2.49 Silberschatz, Galvin and Gagne ©2018
Operating System Debugging
Operating System Concepts – 10th Edition 2.50 Silberschatz, Galvin and Gagne ©2018
OS Debugging
Operating System Concepts – 10th Edition 2.51 Silberschatz, Galvin and Gagne ©2018
End of Chapter 2
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Chapter 3: Processes
Maximize CPU use, quickly switch processes onto CPU for time
sharing
5 4
6 = process scheduler (or job 5 = initiated by a signal from the I/O device
manager, or the page fault handler
scheduler)
6 = termination (including releasing resources)
could be either natural or by force
P1 CPU scheduler P2
Interrupt
Running Save state P1 Ready
Select P2
Restore state P2
Ready Running
Interrupt
Save state P2
Select P1
Restore state P1
Running Ready
Examples:
Resource sharing options
Parent and children share all resources • Shell & user
programs
Children share subset of parent’s resources
Parent and child share no resources • Web browser
• Web server
Execution options
Parent and children execute concurrently (e.g., Web Server)
Parent waits until children terminate (e.g., Batch Processing)
i ni t
pi d = 1
l ogi n kt hr e add s s hd
pi d = 8415 pi d = 2 pi d = 3028
e mac s t cs ch
ps
pi d = 9204 pi d = 4005
pi d = 9298
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
Some OS’s 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 OS
Implementation issues:
How are links established?
Can a link be associated with more than two processes?
How many links can there be between every pair of
communicating processes?
What is the capacity of a link?
Is the size of a message that the link can accommodate fixed or
variable?
Is a link unidirectional or bi-directional?
Physical:
Shared memory
Hardware bus
Network
Logical:
Direct or indirect
Synchronous or asynchronous
Automatic or explicit buffering
Solutions
Allow a link to be associated with at most two processes
Allow only one process at a time to execute a receive operation
Allow the system to select arbitrarily the receiver. Sender is
notified who the receiver was.
Sockets
Remote Procedure Calls (RPC)
Pipes
All ports below 1024 are well known, used for standard services
The client-side stub locates the server and marshalls the parameters
Issues:
Is communication unidirectional or bidirectional?
In the case of two-way communication, is it half or full-duplex?
Must there exist a relationship (i.e., parent-child) between the
communicating processes?
Can the pipes be used over a network?
Ordinary pipes
$ Ls | grep “examples”
$ mkfifo named_pipe_example
$ cat named_pipe_example
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Objectives
To introduce the notion of a thread
To examine issues related to multithreaded programming
To cover operating system support for threads
Operating System Concepts – 10th Edition 4.2 Silberschatz, Galvin and Gagne ©2018
Concurrency and Parallelism
Operating System Concepts – 10th Edition 4.3 Silberschatz, Galvin and Gagne ©2018
Concurrency and Parallelism
Parallelism implies that a system can perform more than one task
simultaneously
Operating System Concepts – 10th Edition 4.4 Silberschatz, Galvin and Gagne ©2018
Concurrency vs. Parallelism
Concurrent execution on single-core system:
Operating System Concepts – 10th Edition 4.5 Silberschatz, Galvin and Gagne ©2018
Types of Parallelism
Data parallelism – distributes subsets of the same data across multiple
cores, same operation on each
Operating System Concepts – 10th Edition 4.6 Silberschatz, Galvin and Gagne ©2018
Amdahl’s Law
Identifies performance gains from adding additional cores to an
application that has both serial and parallel components
S is serial portion
N processing cores
Operating System Concepts – 10th Edition 4.7 Silberschatz, Galvin and Gagne ©2018
Introduction to Threads and
Multithreading
Operating System Concepts – 10th Edition 4.8 Silberschatz, Galvin and Gagne ©2018
What is a thread?
Traditional (single-threaded) process has a single thread of control.
The thread shares with other threads (belonging to the same process) its
code section, data section, and other OS resources, such as open files.
A process with multiple threads can do more than one task at a time.
What resources are used when a thread is created? How do they differ
from those used when a process is created?
Operating System Concepts – 10th Edition 4.10 Silberschatz, Galvin and Gagne ©2018
Examples of MT Applications
Web browser
Word processor
Web-server
Problem?
Two possible solutions
Suggest another application that would benefit from the use of threads,
and an application that would not.
Operating System Concepts – 10th Edition 4.11 Silberschatz, Galvin and Gagne ©2018
Multithreaded Server Architecture
Operating System Concepts – 10th Edition 4.12 Silberschatz, Galvin and Gagne ©2018
Benefits of MT Applications
Responsiveness – may allow continued execution if part of
process is blocked, especially important for user interfaces
Operating System Concepts – 10th Edition 4.13 Silberschatz, Galvin and Gagne ©2018
ST Example
def calculate_sum_single_thread(N):
total = 0
for i in range(1, N + 1):
total += i
return total
N = 10000
result = calculate_sum_single_thread(N)
print({result})
Operating System Concepts – 10th Edition 4.14 Silberschatz, Galvin and Gagne ©2018
MT Example
import threading
N = 10000
thread1_result = [ ]
thread2_result = [ ]
Operating System Concepts – 10th Edition 4.15 Silberschatz, Galvin and Gagne ©2018
MT Example (Cont.)
# Split the work into two threads
half_N = N / 2
thread1 = threading.Thread(target=calculate_sum_partial, args=(N,
1, half_N, thread1_result))
thread2 = threading.Thread(target=calculate_sum_partial, args=(N,
half_N + 1, N, thread2_result))
thread1.start()
thread2.start()
thread1.join()
thread2.join()
Operating System Concepts – 10th Edition 4.17 Silberschatz, Galvin and Gagne ©2018
User Threads
Implemented by a thread library at the user level (above the kernel)
The library provides support for thread creation, scheduling, and
management.
The programmer of the library writes code to synchronize threads and to
context switch them, and they all run in one process.
Kernel does not provide any support; it is unaware that user-level
threads are even running.
Fast to create and manage (i.e., high efficiency), mainly because the
kernel is not involved.
What if the kernel is single-threaded?
Three primary thread libraries: POSIX Pthreads, Windows threads, Java
threads
Operating System Concepts – 10th Edition 4.18 Silberschatz, Galvin and Gagne ©2018
Kernel Threads
Supported directly by the OS
The kernel performs thread creation, scheduling, and management
in kernel space.
Slower to create and manage than user threads and have more
overhead in the kernel.
If a thread performs a blocking system call, the kernel can schedule
another thread in the application for execution.
In a parallel environment, the kernel can schedule threads on different
processors.
Examples – virtually all general-purpose OS’s, including Windows,
Solaris, Linux, Mac OS X
Operating System Concepts – 10th Edition 4.19 Silberschatz, Galvin and Gagne ©2018
Multithreading Models
Operating System Concepts – 10th Edition 4.20 Silberschatz, Galvin and Gagne ©2018
MT Models
Many-to-One
One-to-One
Many-to-Many
Operating System Concepts – 10th Edition 4.21 Silberschatz, Galvin and Gagne ©2018
Many-to-One MT
Many user-level threads mapped to
single kernel thread
One thread blocking causes all to block
Multiple threads may not run in parallel
on muti-core system because only one
may be in kernel at a time
Used in systems that do not support
kernel threads
Few systems currently use this model
Examples:
Solaris Green Threads
GNU Portable Threads
Operating System Concepts – 10th Edition 4.22 Silberschatz, Galvin and Gagne ©2018
One-to-One MT
Each user-level thread maps to a kernel thread
Examples:
Windows
Linux
Solaris 9 and later
Operating System Concepts – 10th Edition 4.23 Silberschatz, Galvin and Gagne ©2018
Many-to-Many MT
Allows many user-level threads to be
mapped to many kernel threads
Examples:
Solaris prior to version 9
Windows with the ThreadFiber
package
Operating System Concepts – 10th Edition 4.24 Silberschatz, Galvin and Gagne ©2018
Two-Level MT
Similar to the many-to-many model, except that it allows a
user thread to be bound to kernel thread
Examples
IRIX
HP-UX
Tru64 UNIX
Solaris 8 and earlier
Operating System Concepts – 10th Edition 4.25 Silberschatz, Galvin and Gagne ©2018
MT Models: Summary
Many-to-one
The developer can create as many user threads as he wishes
But the true concurrency is not gained because the kernel can
schedule only one thread at a time
One-to-one
Greater concurrency than many-to-one
But the developer has to be careful (and in some instances be
limited) not to create too many threads within an application
Many-to-many
Does not suffer from the above shortcomings
Developers can create as many user threads as necessary, and the
corresponding kernel threads can run in parallel on a multiprocessor
Operating System Concepts – 10th Edition 4.26 Silberschatz, Galvin and Gagne ©2018
End of Chapter 4
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Chapter 5: CPU Scheduling
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Objectives
Operating System Concepts – 10th Edition 5.2 Silberschatz, Galvin and Gagne ©2018
Basic Concepts
Operating System Concepts – 10th Edition 5.3 Silberschatz, Galvin and Gagne ©2018
Basic Concepts
Operating System Concepts – 10th Edition 5.4 Silberschatz, Galvin and Gagne ©2018
Histogram of CPU-burst Times
Operating System Concepts – 10th Edition 5.5 Silberschatz, Galvin and Gagne ©2018
CPU Scheduler
***
3 1
Scheduling in 1 & 4 is non-preemptive
waiting
All other scheduling is preemptive
Operating System Concepts – 10th Edition 5.6 Silberschatz, Galvin and Gagne ©2018
Scheduling and Optimization Criteria
Operating System Concepts – 10th Edition 5.7 Silberschatz, Galvin and Gagne ©2018
Scheduling Criteria
Waiting time – amount of time a process has been waiting in the ready
queue
Operating System Concepts – 10th Edition 5.8 Silberschatz, Galvin and Gagne ©2018
Optimization Criteria
Maximize:
CPU utilization
Throughput
Minimize:
Turnaround time
Waiting time
Response time
Operating System Concepts – 10th Edition 5.9 Silberschatz, Galvin and Gagne ©2018
CPU Scheduling Algorithms
Operating System Concepts – 10th Edition 5.10 Silberschatz, Galvin and Gagne ©2018
CPU Scheduling Algorithms
Non-preemptive:
First-come, first-served (FCFS)
Shortest job first (SJF)
Priority
Preemptive:
Shortest remaining time first (SRTF)
Priority
Round robin
Operating System Concepts – 10th Edition 5.11 Silberschatz, Galvin and Gagne ©2018
First-Come, First-Served (FCFS)
P1 P2 P3
0 24 27 30
Operating System Concepts – 10th Edition 5.12 Silberschatz, Galvin and Gagne ©2018
FCFS (Cont.)
P2 P3 P1
0 3 6 30
Operating System Concepts – 10th Edition 5.13 Silberschatz, Galvin and Gagne ©2018
Shortest Job First (SJF)
Associate with each process the length of its next CPU burst
Use these lengths to schedule the process with the shortest
time
Operating System Concepts – 10th Edition 5.14 Silberschatz, Galvin and Gagne ©2018
Example of SJF
P4 P1 P3 P2
0 3 9 16 24
Operating System Concepts – 10th Edition 5.15 Silberschatz, Galvin and Gagne ©2018
Example of SJF
Operating System Concepts – 10th Edition 5.16 Silberschatz, Galvin and Gagne ©2018
Predicting the Next CPU Burst
Can only estimate the length – should be similar to the previous one
Then pick process with shortest predicted next CPU burst
Commonly, α set to ½
Operating System Concepts – 10th Edition 5.17 Silberschatz, Galvin and Gagne ©2018
Predicting the Next CPU Burst
Operating System Concepts – 10th Edition 5.18 Silberschatz, Galvin and Gagne ©2018
Shortest Remaining Time First (SRT)
P1 P2 P4 P1 P3
0 1 5 10 17 26
Operating System Concepts – 10th Edition 5.19 Silberschatz, Galvin and Gagne ©2018
Priority Scheduling
Operating System Concepts – 10th Edition 5.20 Silberschatz, Galvin and Gagne ©2018
Example of Priority Scheduling
Operating System Concepts – 10th Edition 5.21 Silberschatz, Galvin and Gagne ©2018
Example of Preemptive Priority
Scheduling
Operating System Concepts – 10th Edition 5.22 Silberschatz, Galvin and Gagne ©2018
Example of Preemptive Priority
Scheduling
Process AT
P1 1
P2 2
P3 7
P4 22
P5 23
Operating System Concepts – 10th Edition 5.23 Silberschatz, Galvin and Gagne ©2018
Round Robin (RR)
Each process gets a small unit of CPU time (time quantum q), usually
10-100 milliseconds. After this time has elapsed, the process is
preempted and added to the end of the ready queue.
If there are n processes in the ready queue and the time quantum is q,
then each process gets 1/n of the CPU time in chunks of at most q time
units at once. No process waits more than (n-1)q time units.
Performance
q large FIFO
q small q must be large with respect to context switch, otherwise
overhead is too high
Operating System Concepts – 10th Edition 5.24 Silberschatz, Galvin and Gagne ©2018
Example of RR with q = 4
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Operating System Concepts – 10th Edition 5.25 Silberschatz, Galvin and Gagne ©2018
“q” & Context Switch Time
Operating System Concepts – 10th Edition 5.26 Silberschatz, Galvin and Gagne ©2018
Turnaround Time Varies with “q”
Operating System Concepts – 10th Edition 5.27 Silberschatz, Galvin and Gagne ©2018
Multilevel Queue
Ready queue is partitioned into separate queues, e.g.:
foreground (interactive)
background (batch)
Operating System Concepts – 10th Edition 5.28 Silberschatz, Galvin and Gagne ©2018
Multilevel Queue
Operating System Concepts – 10th Edition 5.29 Silberschatz, Galvin and Gagne ©2018
Multilevel Feedback Queue
Operating System Concepts – 10th Edition 5.30 Silberschatz, Galvin and Gagne ©2018
Example of Multilevel Feedback Queue
Three queues:
Q0 – RR with time quantum 8
milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS
Scheduling
A new job enters queue Q0 which is
served FCFS
When it gains CPU, job receives 8
milliseconds
If it does not finish in 8
milliseconds, job is moved to
queue Q1
At Q1 job is again served FCFS and
receives 16 additional milliseconds
If it still does not complete, it is
preempted and moved to queue Q2
Operating System Concepts – 10th Edition 5.31 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 5.32 Silberschatz, Galvin and Gagne ©2018
Thread Scheduling
Operating System Concepts – 10th Edition 5.33 Silberschatz, Galvin and Gagne ©2018
Thread Scheduling
Operating System Concepts – 10th Edition 5.34 Silberschatz, Galvin and Gagne ©2018
Multiple-Processor Scheduling
Operating System Concepts – 10th Edition 5.35 Silberschatz, Galvin and Gagne ©2018
Multiple-Processor (MP) Scheduling
CPU scheduling is more complex when multiple CPUs are available
Homogeneous processors within a multiprocessor
Asymmetric multiprocessing – only one processor accesses the
system data structures, alleviating the need for data sharing
Symmetric multiprocessing (SMP) – each processor is self-
scheduling, all processes in common ready queue, or each has its own
private queue of ready processes
Currently, most common
Processor affinity – process has affinity for processor on which it is
currently running
soft affinity
hard affinity
Variations including processor sets
Operating System Concepts – 10th Edition 5.36 Silberschatz, Galvin and Gagne ©2018
MP Scheduling – Load Balancing
Pull migration – idle processors pulls waiting task from busy processor
Operating System Concepts – 10th Edition 5.37 Silberschatz, Galvin and Gagne ©2018
Multicore Processors
Operating System Concepts – 10th Edition 5.38 Silberschatz, Galvin and Gagne ©2018
Multithreaded Multicore System
Operating System Concepts – 10th Edition 5.39 Silberschatz, Galvin and Gagne ©2018
Real-Time CPU Scheduling
Operating System Concepts – 10th Edition 5.40 Silberschatz, Galvin and Gagne ©2018
Real-Time CPU Scheduling
Operating System Concepts – 10th Edition 5.41 Silberschatz, Galvin and Gagne ©2018
Real-Time CPU Scheduling (Cont.)
Rate-Montonic Scheduling
Operating System Concepts – 10th Edition 5.42 Silberschatz, Galvin and Gagne ©2018
Missed Deadlines with
Rate-Monotonic Scheduling
Operating System Concepts – 10th Edition 5.43 Silberschatz, Galvin and Gagne ©2018
Real-Time CPU Scheduling (Cont.)
Operating System Concepts – 10th Edition 5.44 Silberschatz, Galvin and Gagne ©2018
Real-Time CPU Scheduling (Cont.)
Operating System Concepts – 10th Edition 5.45 Silberschatz, Galvin and Gagne ©2018
Evaluation of Scheduling Algorithms
Operating System Concepts – 10th Edition 5.46 Silberschatz, Galvin and Gagne ©2018
Algorithm Evaluation
How to select CPU-scheduling algorithm for an OS?
Deterministic modeling
Type of analytic evaluation
Takes a particular predetermined workload and defines the
performance of each algorithm for that workload
Operating System Concepts – 10th Edition 5.47 Silberschatz, Galvin and Gagne ©2018
Deterministic Evaluation
FCS is 28ms:
RR is 23ms:
Operating System Concepts – 10th Edition 5.48 Silberschatz, Galvin and Gagne ©2018
Queueing Models
Operating System Concepts – 10th Edition 5.49 Silberschatz, Galvin and Gagne ©2018
Little’s Formula
Operating System Concepts – 10th Edition 5.50 Silberschatz, Galvin and Gagne ©2018
Simulations
Operating System Concepts – 10th Edition 5.51 Silberschatz, Galvin and Gagne ©2018
Simulations (Cont.)
Operating System Concepts – 10th Edition 5.52 Silberschatz, Galvin and Gagne ©2018
Implementation
Operating System Concepts – 10th Edition 5.53 Silberschatz, Galvin and Gagne ©2018
End of Chapter 5
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018