You are on page 1of 97

Operating

Systems:
Internals Chapter 2
and Design
Principles Operating System
Overview
Ninth Edition, Global Edition
By William Stallings

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Operating System
nA program that controls the execution of
application programs
n An interface between applications and hardware
Main objectives of an OS:

• Convenience
• Efficiency
• Ability to evolve

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Application programs
Application
programming interface
Application Libraries/utilities Software
binary interface
Operating system
Instruction Set
Architecture
Execution hardware

Memory
System interconnect
translation Hardware
(bus)

I/O devices
Main
and
memory
networking

Figure 2.1 Computer Hardware and Software Structure


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Operating System Services

n Program development
n Program execution
n Access I/O devices
n Controlled access to files
n System access
n Error detection and response
n Accounting

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Key Interfaces

n Instruction set architecture (ISA)


n Application binary interface (ABI)
n Application programming interface (API)

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


The Operating System as
Resource Manager
n The OS is responsible for controlling
the use of a computer’s resources,
such as I/O, main and secondary
memory, and processor execution
time

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Operating System
as Resource Manager
n Functions in the same way as ordinary
computer software
n Program, or suite of programs, executed
by the processor
n Frequently relinquishes control and must
depend on the processor to allow it to
regain control
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Computer System
I/O Devices
Memory
Operating I/O Controller Printers,
System keyboards,
Software digital camera,
I/O Controller etc.

Programs
and Data

I/O Controller

Processor Processor

Storage
OS
Programs

Data

Figure 2.2 The Operating System as Resource Manager


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Evolution of Operating Systems

§ A major OS will evolve over time for a


number of reasons:

Hardware upgrades

New types of hardware

New services

Fixes

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Evolution of
Operating Systems
§ Stages include:

Time
Sharing
Multiprogrammed Systems
Batch Systems

Simple Batch
Systems

Serial
Processing

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Serial Processing
Earliest Computers: Problems:
n Scheduling:
n No operating system
n Most installations used a
n Programmers interacted
hardcopy sign-up sheet to
directly with the computer
hardware reserve computer time
n Time allocations could
n Computers ran from a console run short or long,
with display lights, toggle resulting in wasted
switches, some form of input computer time
device, and a printer
n Setup time
n Users have access to the
computer in “series” n A considerable amount of
time was spent on setting up
the program to run
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Simple Batch Systems

n Early computers were very expensive


n Important to maximize processor utilization

n Monitor
n User no longer has direct access to processor
n Job is submitted to computer operator who batches
them together and places them on an input device
n Program branches back to the monitor when finished

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Monitor Point of View
Interrupt
n Monitor controls the sequence Processing
Device
of events Monitor
Drivers
Job
Sequencing
n Resident Monitor is software Control Language

always in memory Boundary


Interpreter

n Monitor reads in job and gives


control User
Program
Area

n Job returns control to monitor

Figure 2.3 Memory Layout for a Resident Monitor

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Processor Point of View
n Processor executes instruction from the memory
containing the monitor
n Executes the instructions in the user program until it
encounters an ending or error condition
n “Control is passed to a job” means processor is fetching
and executing instructions in a user program
n “Control is returned to the monitor” means that the
processor is fetching and executing instructions from the
monitor program
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Job Control Language
(JCL)
Special type of programming
language used to provide
instructions to the monitor

What compiler to use

What data to use

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Desirable Hardware
Features
Memory protection

• While the user program is executing, it must not alter the memory area
containing the monitor

Timer

• Prevents a job from monopolizing the system

Privileged instructions

• Can only be executed by the monitor

Interrupts

• Gives OS more flexibility in controlling user programs

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Modes of Operation

User Mode Kernel Mode


• User program executes in • Monitor executes in kernel
user mode mode
• Certain areas of memory are • Privileged instructions may
protected from user access be executed
• Certain instructions may not • Protected areas of memory
be executed may be accessed

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Simple Batch System
Overhead
n Processor time alternates between execution of user
programs and execution of the monitor
n Sacrifices:
n Some main memory is now given over to the monitor
n Some processor time is consumed by the monitor

n Despite overhead, the simple batch system improves


utilization of the computer

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Multiprogrammed
Batch Systems

I/O devices
are slow
compared
to processor

Even with
automatic
job
sequencing

Processor is often
idle

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Read one record from file 15 µs
Execute 100 instructions 1 µs
Write one record to file 15 µs
TOTAL 31 µs

1
Percent CPU Utilization = = 0.032 = 3.2%
31

Figure 2.4 System Utilization Example

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Uniprogramming

Program A Run Wait Run Wait

Time
(a) Uniprogramming

The processor spends a certain amount of time executing, until


it reaches
Program A an I/O instruction;
Run Wait it must Run
then wait untilWait
that I/O
instruction concludes before proceeding
Program B Wait Run Wait Run Wait
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Program A Run Wait Run Wait

Multiprogramming Time
(a) Uniprogramming

Program A Run Wait Run Wait

Program B Wait Run Wait Run Wait

Run Run Run Run


Combined Wait Wait
A B A B
Time
(b) Multiprogramming with two programs

n There must be enough memory to hold the OS (resident monitor) and one user
Program A
program Run Wait Run Wait

n When one job needs to wait for I/O, the processor can switch to the other job, which is
likely not waiting
Program B for I/ORun
Wait Wait Run Wait
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Program B Wait Run Wait Run Wait

Run Run Run Run

Multiprogramming
Combined Wait Wait
A B A B
Time
(b) Multiprogramming with two programs

Program A Run Wait Run Wait

Program B Wait Run Wait Run Wait

Program C Wait Run Wait Run Wait

Run Run Run Run Run Run


Combined Wait Wait
A B C A B C
Time
(c) Multiprogramming with three programs

Figure 2.5 Multiprogramming Example


n Also known as multitasking
n Memory is expanded to hold three, four, or more programs and switch
among all of them
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Multiprogramming
Example

JOB1 JOB2 JOB3


Type of job Heavy compute Heavy I/O Heavy I/O
Duration 5 min 15 min 10 min
Memory required 50 M 100 M 75 M
Need disk? No No Yes
Need terminal? No Yes No
Need printer? No No Yes

Table 2.1 Sample Program Execution Attributes

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Uniprogramming Multiprogramming
Processor use 20% 40%
Memory use 33% 67%
Disk use 33% 67%
Printer use 33% 67%
Elapsed time 30 min 15 min
Throughput 6 jobs/hr 12 jobs/hr
Mean response time 18 min 10 min

Table 2.2 Effects of Multiprogramming on Resource Utilization

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


100% 100%

CPU CPU
0% 0%
100% 100%

Memory Memory
0% 0%
100% 100%

Disk Disk
0% 0%
100% 100%

Terminal Terminal
0% 0%
100% 100%

Printer Printer
0% 0%

Job History Job History JOB1


JOB1 JOB2 JOB3
JOB2
0 5 10 15 20 25 30
minutes JOB3

time 0 5 10 15
minutes
time
(a) Uniprogramming (b) Multiprogramming

Figure 2.6 Utilization Histograms


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Time-Sharing Systems
n Can be used to handle multiple interactive jobs
n Processor time is shared among multiple users
n Multiple users simultaneously access the system
through terminals, with the OS interleaving the
execution of each user program in a short burst or
quantum of computation

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Batch Multiprogramming Time Sharing
Principal objective Maximize processor use Minimize response time
Source of directives to Job control language Commands entered at the
operating system commands provided with the terminal
job

Table 2.3 Batch Multiprogramming versus Time Sharing

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Compatible Time-Sharing
System (CTSS)
n One of the first time-sharing operating systems
n Developed at MIT by a group known as Project MAC
n The system was first developed for the IBM 709 in 1961
n Ran on a computer with 32,000 36-bit words of main memory, with the resident
monitor consuming 5000 of that

n Utilized a technique known as time slicing


n System clock generated interrupts at a rate of approximately one every 0.2 seconds
n At each clock interrupt the OS regained control and could assign the processor to another user
n Thus, at regular time intervals the current user would be preempted and another user loaded in
n To preserve the old user program status for later resumption, the old user programs and data were
written out to disk before the new user programs and data were read in
n Old user program code and data were restored in main memory when that program was next
given a turn

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


0 0 0
Monitor Monitor Monitor
5000 5000 5000
JOB 3
10000
JOB 1
JOB 2
(JOB 2)
20000

Free 25000 25000


Free Free
32000 32000 32000
(a) (b) (c)

0 0 0
Monitor Monitor Monitor
5000 5000 5000
JOB 4
JOB 1
15000 JOB 2
(JOB 1)
20000 20000
(JOB 2) (JOB 2)
25000 25000 25000
Free Free Free
32000 32000 32000
(d) (e) (f)

Figure 2.7 CTSS Operation


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Major Achievements
n Operating Systems are among the most
complex pieces of software ever developed
n Major advances in development include:
n Processes
n Memory management
n Information protection and security
n Scheduling and resource management
n System structure

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Process
n Fundamental to the structure of operating systems

A process can be defined as:

A program in execution

An instance of a running program


The entity that can be assigned to, and executed on, a processor

A unit of activity characterized by a single sequential thread of execution, a


current state, and an associated set of system resources

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Causes of Errors
n Improper synchronization n Nondeterminate program
n It is often the case that a operation
routine must be suspended n When programs share memory,
awaiting an event elsewhere in and their execution is
the system interleaved by the processor,
n Improper design of the they may interfere with each
signaling mechanism can result other by overwriting common
in loss or duplication memory areas in unpredictable
ways
n The order in which programs
n Failed mutual exclusion are scheduled may affect the
n More than one user or program outcome of any particular
attempts to make use of a shared program
resource at the same time
n There must be some sort of mutual
exclusion mechanism that permits only
n Deadlocks
one routine at a time to perform an n It is possible for two or more
update against the file programs to be hung up
waiting for each other

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Components of
a Process
n A process contains n Theexecution context is
three components: essential:
n It is the internal data by which
n An executable program the OS is able to supervise and
n The associated data control the process
needed by the program n Includes the contents of the
(variables, work space, various process registers
buffers, etc.) n Includes information such as
the priority of the process and
n The execution context whether the process is waiting
(or “process state”) of for the completion of a
the program particular I/O event

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Main Processor
Memory Registers
Process index i

PC

Process
i
Process Base b
list Limit h
j

Management Other
registers

Context
Process
§ The entire state of the A
Data

Program
process at any instant is (code)
contained in its context
b

§ New features can be Process


Context

Data
designed and incorporated B h
Program
into the OS by expanding (code)
the context to include any
new information needed to
support the feature
Figure 2.8 Typical Process Implementation
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Memory Management
n The OS has five principal storage
management responsibilities:

Automatic
Support of Protection
Process allocation Long-term
and modular and access
isolation programming control storage
management

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Virtual Memory
nA facility that allows programs to address
memory from a logical point of view, without
regard to the amount of main memory
physically available
n Conceived to meet the requirement of having
multiple user jobs reside in main memory
concurrently

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Paging
n Allows processes to be comprised of a number of fixed-
size blocks, called pages
n Program references a word by means of a virtual address,
consisting of a page number and an offset within the page
n Each page of a process may be located anywhere in main
memory

n The paging system provides for a dynamic mapping


between the virtual address used in the program and a
real address (or physical address) in main memory
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
A.1
A.0 A.2
0 0
A.5
1 1
2 2
B.0 B.1 B.2 B.3
3 3
4 4
5 5
6 6
A.7
7 User
A.9
8 program
B
9
A.8
10

User
program
A
B.5 B.6

Main Memory Disk


Main memory consists of a Secondary memory (disk) can
number of fixed-length frames, hold many fixed-length pages. A
each equal to the size of a page. user program consists of some
For a program to execute, some number of pages. Pages for all
or all of its pages must be in programs plus the operating system
main memory. are on disk, as are files.

Figure 2.9 Virtual Memory Concepts


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Real
Memory Address
Processor Management
Virtual Unit
Address Main
Memory

Disk
Address

Secondary
Memory

Figure 2.10 Virtual Memory Addressing


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Information Protection
and Security
n The nature of the
threat that concerns
an organization will Main
vary greatly issues Availability
depending on the
circumstances
n The problem involves
controlling access to Authenticity Confidentiality
computer systems
and the information
Data
stored in them integrity

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Scheduling and
Resource Management
n Key responsibility of
an OS is managing
Fairness
resources Efficiency

n Resource allocation
policies must Differential
consider: responsiveness

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Operating System
Service Call Service
from Process Call
Handler (code)

Long- Short- I/O


Interrupt
Term Term Queues
from Process Interrupt
Queue Queue
Interrupt Handler (code)
from I/O
Short-Term
Scheduler
(code)

Pass Control
to Process

Figure 2.11 Key Elements of an Operating System for Multiprogramming


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Different Architectural
Approaches
n Demands on operating systems require new
ways of organizing the OS

Different approaches and design elements have been tried:

• Microkernel architecture
• Multithreading
• Symmetric multiprocessing
• Distributed operating systems
• Object-oriented design

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Microkernel Architecture
n Assigns only a few essential functions to the
kernel:
Address Interprocess
space communication Basic
scheduling
management (IPC)

n The approach:

Well suited to a
Simplifies Provides distributed
implementation flexibility
environment

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Multithreading
Thread Process
n Technique in
which a process,
executing an Dispatchable unit of work
A collection of one or more
threads and associated
application, is system resources

divided into
threads that can By breaking a single

run concurrently
application into multiple
Includes a processor context threads, a programmer has
and its own data area for a greater control over the
stack modularity of the
application and the timing
of application-related events

Executes sequentially and is


interruptible

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Symmetric
Multiprocessing (SMP)
n Term that refers to a computer hardware architecture and also
to the OS behavior that exploits that architecture
n The OS of an SMP schedules processes or threads across all
of the processors

n The OS must provide tools and functions to exploit the


parallelism in an SMP system

n Multithreading and SMP are often discussed together, but the


two are independent facilities

n An attractive feature of an SMP is that the existence of


multiple processors is transparent to the user
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
SMP Advantages
More than one process can be
Performance running simultaneously, each on a
different processor

Failure of a single process does not


Availability halt the system

Incremental Performance of a system can be


enhanced by adding an
Growth additional processor

Vendors can offer a range of products


Scaling based on the number of processors
configured in the system
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Time

Process 1

Process 2

Process 3

(a) Interleaving (multiprogramming, one processor)

Process 1

Process 2

Process 3

(b) Interleaving and overlapping (multiprocessing; two processors)

Blocked Running

Figure 2.12 Multiprogramming and Multiprocessing


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
OS Design
Distributed Operating Object-Oriented
System Design
n Provides the illusion of a single n Lends discipline to the process
of adding modular extensions to
main memory space and a single
a small kernel
secondary memory space plus
other unified access facilities, such n Enables programmers to
as a distributed file system customize an operating system
without disrupting system
n State of the art for distributed integrity
operating systems lags that of
uniprocessor and SMP operating n Also eases the development of
systems distributed tools and full-blown
distributed operating systems

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Fault Tolerance
n Refers to the ability of a system or component to continue
normal operation despite the presence of hardware or software
faults

n Typically involves some degree of redundancy

n Intended to increase the reliability of a system


n Typically comes with a cost in financial terms or performance

n The extent adoption of fault tolerance measures must be


determined by how critical the resource is

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Fundamental Concepts
n The basic measures are:
n Reliability
n R(t)
n Defined as the probability of its correct operation up to time t given that the
system was operating correctly at time t=o
n Mean time to failure (MTTF)
n Mean time to repair (MTTR) is the average time it takes to repair or replace
a faulty element
n Availability
n Defined as the fraction of time the system is available to service users’
requests

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


B1 B2 B3
Up

Down
A1 A2 A3

B1 B2 B3 A1 A2 A3
MTTF MTTR
3 3

Figure 2.13 System Operational States

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Class Availability Annual Downtime
Continuous 1.0 0
Fault Tolerant 0.99999 5 minutes
Fault Resilient 0.9999 53 minutes
High Availability 0.999 8.3 hours
Normal Availability 0.99 - 0.995 44-87 hours

Table 2.4 Availability Classes

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Faults
n Are defined by the IEEE Standards Dictionary as an erroneous
hardware or software state resulting from:
n Component failure
n Operator error
n Physical interference from the environment
n Design error
n Program error
n Data structure error

n The standard also states that a fault manifests itself as:


n A defect in a hardware device or component
n An incorrect step, process, or data definition in a computer program

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Fault Categories

n Permanent
• A fault that, after it occurs, is always present
• The fault persists until the faulty component is replaced or repaired

n Temporary
• A fault that is not present all the time for all operating conditions
• Can be classified as
n Transient – a fault that occurs only once
n Intermittent – a fault that occurs at multiple, unpredictable times

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Methods of Redundancy
Spatial
Temporal Information
(physical)
redundancy redundancy
redundancy
Involves the use of Involves repeating a
multiple components function or operation
that either perform when an error is Provides fault
the same function detected tolerance by
simultaneously or are replicating or coding
configured so that one data in such a way
component is that bit errors can be
available as a backup Is effective with both detected and
in case of the failure temporary faults but corrected
of another not useful for
component permanent faults

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Operating System
Mechanisms

n A number of techniques can be incorporated


into OS software to support fault tolerance:
n Process isolation
n Concurrency controls
n Virtual machines
n Checkpoints and rollbacks

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Symmetric Multiprocessor
OS Considerations
n A multiprocessor OS must provide all the functionality of a multiprogramming
system plus additional features to accommodate multiple processors

n Key design issues:

Simultaneous Synchronization Reliability


concurrent Scheduling Memory and fault
processes or management tolerance
threads Any With multiple
Kernel processor active processes
routines need may perform having potential The reuse The OS
to be reentrant scheduling, access to shared of should
to allow which address spaces or physical provide
several complicates shared I/O pages is graceful
processors to the task of resources, care the biggest degradation
execute the enforcing a must be taken to problem in the face
same kernel scheduling provide effective of of processor
code policy synchronization concern failure
simultaneously
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Multicore OS
Considerations
n The design challenge for a
many-core multicore system is
to efficiently harness the Hardware parallelism within
multicore processing power each core processor, known as
instruction level parallelism
and intelligently manage the
substantial on-chip resources
efficiently Potential for multiprogramming
and multithreaded execution
n Potential for parallelism exists within each processor
at three levels:
Potential for a single application
to execute in concurrent
processes or threads across
multiple cores

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Grand Central Dispatch
(GCD)
n Is a multicore support capability
n Once a developer has identified something that can be split off
into a separate task, GCD makes it as easy and noninvasive as
possible to actually do so

n In essence, GCD is a thread pool mechanism, in which the OS


maps tasks onto threads representing an available degree of
concurrency
n Provides the extension to programming languages to allow
anonymous functions, called blocks, as a way of specifying
tasks
n Makes it easy to break off the entire unit of work while
maintaining the existing order and dependencies between
subtasks
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Virtual Machine Approach
n Allows one or more cores to be dedicated to a
particular process and then leave the processor
alone to devote its efforts to that process
n Multicore OS could then act as a hypervisor that
makes a high-level decision to allocate cores to
applications but does little in the way of resource
allocation beyond that

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Service processes
System support Applications
processes
Service control
SVChost.exe Environment
manager
Task manager subsystems
Lsass Winmgmt.exe Windows
Winlogon Spooler Explorer POSIX
User
Session Services.exe application
manager Win32
Subsytem DLLs

Ntdll.dll
System
threads User mode

Kernel mode
System service dispatcher
(Kernel-mode callable interfaces)
Win32 USER,
I/O manager

manager (registry)
GDI

Security reference
File system cache

Local procedure
Object manager

Virtual memory
Power manager

Configuration
Processes and
Plug and play
manager

monitor

threads

call
Device
and file Graphics
system drivers
drivers
Kernel
Hardware abstraction layer (HAL)

Lsass = local security authentication server Colored area indicates Executive


POSIX = portable operating system interface
GDI = graphics device interface
DLL = dynamic link libraries

Figure 2.14 Windows Architecture


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Kernel-Mode Components
of Windows
n Executive
n Contains the core OS services, such as memory management, process and thread management,
security, I/O, and interprocess communication

n Kernel
n Controls execution of the processors. The Kernel manages thread scheduling, process switching,
exception and interrupt handling, and multiprocessor synchronization

n Hardware Abstraction Layer (HAL)


n Maps between generic hardware commands and responses and those unique to a specific
platform and isolates the OS from platform-specific hardware differences

n Device Drivers
n Dynamic libraries that extend the functionality of the Executive. These include hardware device
drivers that translate user I/O function calls into specific hardware device I/O requests and
software components for implementing file systems, network protocols, and any other system
extensions that need to run in kernel mode

n Windowing and Graphics System


n Implements the GUI functions, such as dealing with windows, user interface controls, and
drawing
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Windows Executive

I/O manager Cache manager Object manager Plug-and-play Power manager


•Provides a •Improves the •Creates, manages, manager •Coordinates power
framework through performance of file- and deletes Windows •Determines which management among
which I/O devices based I/O by causing Executive objects drivers are required devices
are accessible to recently referenced that are used to to support a
applications, and is file data to reside in represent resources particular device and
responsible for main memory for such as processes, loads those drivers
dispatching to the quick access, and by threads, and
appropriate device deferring disk writes synchronization
drivers for further by holding the objects and enforces
processing updates in memory uniform rules for
for a short time retaining, naming,
before sending them and setting the
to the disk in more security of objects
efficient batches

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Windows Executive

Security reference Virtual memory Process/thread Configuration Advanced local


monitor manager manager manager procedure call
•Enforces access- •Manages virtual •Creates, manages, •Responsible for (ALPC) facility
validation and audit- addresses, physical and deletes process implementing and •Implements an
generation rules memory, and the and thread objects managing the system efficient cross-process
paging files on disk registry, which is the procedure call
and controls the repository for both mechanism for
memory system-wide and per- communication
management user settings of between local
hardware and data various parameters processes
structures which map implementing
virtual addresses in services and
the process’s address subsystems
space to physical
pages in the
computer’s memory

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


User-Mode Processes
n Windows supports four basic types of user-mode
processes:
Special System • User-mode services needed to manage the system
Processes
• The printer spooler, event logger, and user-mode components that
Service Processes cooperate with device drivers, and various network services

Environment • Provide different OS personalities (environments)


Subsystems
• Executables (EXEs) and DLLs that provide the functionality users
User Applications run to make use of the system

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Client/Server Model
n Windows OS services, n Advantages:
environmental subsystems, and
applications are all structured n It simplifies the Executive
using the client/server model n It improves reliability
n Common in distributed n It provides a uniform means
systems, but can be used for applications to
internal to a single system communicate with services
via RPCs without restricting
n Processes communicate via flexibility
RPC
n It provides a suitable base
for distributed computing

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Threads and SMP
n Two important characteristics of Windows are its support for
threads and for symmetric multiprocessing (SMP)
n OS routines can run on any available processor, and different routines can
execute simultaneously on different processors

n Windows supports the use of multiple threads of execution within a single


process. Multiple threads within the same process may execute on different
processors simultaneously

n Server processes may use multiple threads to process requests from more
than one client simultaneously

n Windows provides mechanisms for sharing data and resources between


processes and flexible interprocess communication capabilities
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Windows Objects
n Windows draws heavily on the concepts of object-
oriented design
n Key object-oriented concepts used by Windows
are:
Inheritance
Encapsulation

Object class and Polymorphism


instance

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Asynchronous Procedure Call Used to break into the execution of a specified thread and to
cause a procedure to be called in a specified processor mode.

Deferred Procedure Call Used to postpone interrupt processing to avoid delaying


hardware interrupts. Also used to implement timers and inter-
processor communication

Interrupt Used to connect an interrupt source to an interrupt service


routine by means of an entry in an Interrupt Dispatch Table
(IDT). Each processor has an IDT that is used to dispatch
interrupts that occur on that processor.

Process Represents the virtual address space and control information


necessary for the execution of a set of thread objects. A process
contains a pointer to an address map, a list of ready threads
containing thread objects, a list of threads belonging to the
process, the total accumulated time for all threads executing
within the process, and a base priority.

Thread Represents thread objects, including scheduling priority and


quantum, and which processors the thread may run on.

Profile Used to measure the distribution of run time within a block of


code. Both user and system code can be profiled.

Table 2.5 Windows Kernel Control Objects

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Traditional UNIX Systems
n Developed at Bell Labs and became operational on a PDP-7 in 1970

n The first notable milestone was porting the UNIX system from the PDP-7 to the
PDP-11
n First showed that UNIX would be an OS for all computers

n Next milestone was rewriting UNIX in the programming language C


n Demonstrated the advantages of using a high-level language for system code

n Was described in a technical journal for the first time in 1974

n First widely available version outside Bell Labs was Version 6 in 1976

n Version 7, released in 1978, is the ancestor of most modern UNIX systems

n Most important of the non-AT&T systems was UNIX BSD (Berkeley Software
Distribution), running first on PDP and then on VAX computers

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


User Programs

Trap
Libraries
User Level

System Call Interface

Inter-process
communication
File Subsystem
Process
Control Scheduler
Subsystem
Memory
Buffer Cache
management

character block
Device Drivers Kernel Level

Hardware Control

Hardware Level

Figure 2.15 Traditional UNIX Kernel

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


coff
a.out elf

exec
switch
NFS
file mappings
FFS
virtual
device memory vnode/vfs
mappings framework interface
s5fs

anonymous RFS
mappings

Common
Facilities

disk driver time-sharing


block processes
device scheduler
switch framework

tape driver system


processes
STREAMS

network tty
driver driver

FigureFigure
2.17 2.16 Modern
Modern UNIXUNIX Kernel
Kernel [VAHA96]
Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
FreeBSD 11.0
BSD NetBSD 7.0
Family
OpenBSD 6.0
BSD (Berkeley Software Distribution) 4.4
SunOS 4.1.4

NextStep 3.3 OS X (now macOS) 10.12

Xenix OS

GNU
Linux 4.7

Research Unix (Bell Labs) 10.5

Commercial Unix (AT&T) UnixWare (Univel/SCO)


Solaris (Sun/Oracle) 11.3
System V HP-UX 11iv3
Family
AIX (IBM) 7.2

1970 1980 1990 2000 2010 2016

Figure 2.17 Unix Family Tree

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


System V Release 4
(SVR4)
n Developed jointly by AT&T and Sun Microsystems

n Combines features from SVR3, 4.3BSD, Microsoft Xenix System V, and


SunOS

n New features in the release include:


n Real-time processing support
n Process scheduling classes
n Dynamically allocated data structures
n Virtual memory management
n Virtual file system
n Preemptive kernel

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


BSD
n Berkeley Software Distribution

n 4.xBSD is widely used in academic installations and has served as the basis of a
number of commercial UNIX products

n 4.4BSD was the final version of BSD to be released by Berkeley

n There are several widely used, open-source versions of BSD


n FreeBSD
n Popular for Internet-based servers and firewalls
n Used in a number of embedded systems
n NetBSD
n Available for many platforms
n Often used in embedded systems
n OpenBSD
n An open-source OS that places special emphasis on security

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Solaris 11
n Oracle’s SVR4-based UNIX release
n Provides all of the features of SVR4 plus a number of
more advanced features such as:
n A fully preemptable, multithreaded kernel
n Full support for SMP
n An object-oriented interface to file systems

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


LINUX Overview
n Started out as a UNIX variant for the IBM PC
n Linus Torvalds, a Finnish student of computer science, wrote the initial
version
n Linux was first posted on the Internet in 1991
n Today it is a full-featured UNIX system that runs on virtually all platforms
n Is free and the source code is available
n Key to the success of Linux has been the availability of free software
packages under the auspices of the Free Software Foundation (FSF)
n Highly modular and easily configured

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Modular Structure
Loadable Modules
n Linux development is global and
done by a loosely associated n Relatively independent blocks
group of independent developers
n A module is an object file whose
n Although Linux does not use a code can be linked to and unlinked
microkernel approach, it from the kernel at runtime
achieves many of the potential
advantages of the approach by n A module is executed in kernel
means of its particular modular mode on behalf of the current
architecture process
n Linux is structured as a n Have two important
collection of modules, a number characteristics:
of which can be automatically
loaded and unloaded on demand n Dynamic linking
n Stackable modules

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


module module
*next *next
*name *name
version version
srcversion srcversion
num_gpl_syms num_gpl_syms
num_syms num_syms
num_exentries num_exentries VFAT
FAT
*syms *syms
state state
extable extable
kernel_symbol symbol_table
value value
*name *name
value value
*name *name

value value
*name *name

Figure 2.18 Example List of Linux Kernel Modules

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


user level
processes

signals system calls

processes
& scheduler
file network
systems protocols

kernel
virtual
memory
char device block device network de-
drivers drivers vice drivers

traps & physical


interrupts
faults memory

hardware
system network inter-
CPU terminal disk
memory face controller

Figure 2.19 Linux Kernel Components


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Linux Signals

SIGHUP Terminal hangup SIGCONT Continue


SIGQUIT Keyboard quit SIGTSTP Keyboard stop
SIGTRAP Trace trap SIGTTOU Terminal write
SIGBUS Bus error SIGXCPU CPU limit exceeded
SIGKILL Kill signal SIGVTALRM Virtual alarm clock
SIGSEGV Segmentation violation SIGWINCH Window size unchanged
SIGPIPT Broken pipe SIGPWR Power failure
SIGTERM Termination SIGRTMIN First real-time signal
SIGCHLD Child status unchanged SIGRTMAX Last real-time signal

Table 2.6 Some Linux Signals

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Filesystem related
close Close a file descriptor.
link Make a new name for a file.
open Open and possibly create a file or device.
read Read from file descriptor.
write Write to file descriptor
Process related
execve Execute program.
exit Terminate the calling process.
getpid Get process identification.
setuid Set user identity of the current process.
ptrace Provides a means by which a parent process my observe and control
the execution of another process, and examine and change its core
image and registers.
Scheduling related
sched_getparam Sets the scheduling parameters associated with the scheduling policy
for the process identified by pid.
sched_get_priority_max Returns the maximum priority value that can be used with the
scheduling algorithm identified by policy.
sched_setscheduler Sets both the scheduling policy (e.g., FIFO) and the associated
parameters for the process pid.
sched_rr_get_interval Writes into the timespec structure pointed to by the parameter tp the
round robin time quantum for the process pid.
sched_yield A process can relinquish the processor voluntarily without blocking
via this system call. The process will then be moved to the end of the
queue for its static priority and a new process gets to run.

Table 2.7 Some Linux System Calls (page 1 of 2)


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Interprocess Communication (IPC) related
msgrcv A message buffer structure is allocated to receive a
message. The system call then reads a message from the
message queue specified by msqid into the newly created
message buffer.
semctl Performs the control operation specified by cmd on the
semaphore set semid.
semop Performs operations on selected members of the semaphore
set semid.
shmat Attaches the shared memory segment identified by shmid
to the data segment of the calling process.
shmctl Allows the user to receive information on a shared
memory segment, set the owner, group, and permissions of
a shared memory segment, or destroy a segment.
Socket (networking) related
bind Assigns the local IP address and port for a socket.
Returns 0 for success and –1 for error.
connect Establishes a connection between the given socket and
the remote socket associated with sockaddr.
gethostname Returns local host name.
send Send the bytes contained in buffer pointed to by *msg
over the given socket.
setsockopt Sets the options on a socket
Miscellaneous
fsync Copies all in-core parts of a file to disk, and waits
until the device reports that all parts are on stable
storage.
time Returns the time in seconds since January 1, 1970.
vhangup Simulates a hangup on the current terminal. This call
arranges for other users to have a "clean" tty at login
time.

Table 2.7 Some Linux System Calls (page 2 of 2)


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Android Operating
System
n A Linux-based system originally n Most recent version is Android
designed for mobile phones 7.0 (Nougat)

n The most popular mobile OS n Android has an active


community of developers and
n Development was done by enthusiasts who use the Android
Android Inc., which was bought Open Source Project (AOSP)
by Google in 2005 source code to develop and
distribute their own modified
n 1st commercial version (Android versions of the operating system
1.0) was released in 2008
n The open-source nature of
Android has been the key to its
success

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Applications
Home Dialer SMS/MMS IM Browser Camera Alarm Calculator

Contacts Voice Dial Email Calendar Media Albums Clock


Player

Application Framework
Activity Manager Windows Content Providers View System Notification
Manager Manager

Package Manager Telephony Resource Manager Location Manager XMPP Service


Manager

System Libraries Android Runtime


Surface Manager Media Framework SQLite Core Libraries

OpenGL/ES FreeType LibWebCore Dalvik Virtual Machine

SGL SSL Libc

Linux Kernel
Display Driver Camera Driver Bluetooth Driver Flash Memory Binder (IPC)
Driver Driver

USB Driver Keypad Driver WiFi Driver Audio Drivers Power


Management

Implementation:
Applications, Application Framework: Java

System Libraries, Android Runtime: C and C++

Linux Kernel: C

Figure 2.20 Android Software Architecture


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Application Framework
n Provides high-level building blocks accessible through standardized API’s
that programmers use to create new apps
n Architecture is designed to simplify the reuse of components

n Key components:

Activity Window Package Telephony


Manager Manager Manager Manager
Java abstraction of
Manages lifecycle of the underlying
applications
Surface Manager
Allows interaction
Installs and removes with phone, SMS,
applications
Responsible for Allows applications and MMS services
starting, stopping, to declare their client
and resuming the area and use features
various applications like the status bar

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Application Framework
(cont.)

Content Resource View Location Notification


Providers Manager System Manager Manager XMPP

These Allows
functions developers to
encapsulate Manages tap into
application application Provides the location- Provides
user interface Manages standardized
data that resources, based events, such
need to be such as (UI) services, messaging
primitives as as arriving functions
shared localized whether by messages and
between strings and well as UI GPS, cell between
Events appointments applications
applications bitmaps tower IDs, or
such as local Wi-Fi
contacts databases

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


System Libraries
n Collection of useful system functions written in C or C++ and used by various
components of the Android system
n Called from the application framework and applications through a Java interface

n Exposed to developers through the Android application framework

n Some of the key system libraries include:


n Surface Manager
n OpenGL
n Media Framework
n SQL Database
n Browser Engine
n Bionic LibC

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


n Most Android software is mapped
into a bytecode format which is then
transformed into native instructions
on the device itself

Earlier releases of Android used a


Android n
scheme known as Dalvik, however
Dalvik has a number of limitations
in terms of scaling up to larger
Runtime memories and multicore
architectures

n More recent releases of Android rely


on a scheme known as Android
runtime (ART)
n ART is fully compatible with
Dalvik’s existing bytecode format so
application developers do not need to
change their coding to be executable
under ART

n Each Android application runs in its


own process, with its own instance of
the Dalvik VM

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Resources &
Native Code

package
zip
Source Dex File APK

install
Resources &
Native Code
Dex File

dexopt dex2oat dex & native code


quickened dex
Odex install
ELF File
Dalvik File ART
Libraries

Dalvik Native ART Native

Figure 2.21 The Life Cycle of an APK


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Advantages and Disadvantages
of Using ART
Advantages Disadvantages
n Reduces startup time of n Because the conversion from bytecode
applications as native code is to native code is done at install time,
directly executed application installation takes more time

n Improves battery life because n On the first fresh boot or first boot after
processor usage for JIT is avoided factory reset, all applications installed
on a device are compiled to native code
n Lesser RAM footprint is required using dex2opt, therefore the first boot
for the application to run as there can take significantly longer to reach
is no storage required for JIT Home Screen compared to Dalvik
cache
n The native code thus generated is
n There are a number of Garbage stored on internal storage that requires
Collection optimizations and a significant amount of additional
debug enhancements that went internal storage space
into ART

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Applications and Framework

Binder IPC

Android System Services

Media Server System Server


Power
AudioFlinger MediaPlayer Window
Manager
Service Manager
Service

Camera Activity
Other Media
Service Manager Other Services
Services

Android Runtime/Dalvik

Hardware Abstraction Layer (HAL)

Camera HAL Audio HAL Graphics HAL


Other HALs

Linux Kernel
Audio Driver
Camera Driver Display Drivers
(ALSA, OSS, etc) Other Drivers

Figure 2.22 Android System Architecture


Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.
Activities
An activity is a single visual user interface
component, including things such as menu
selections, icons, and checkboxes

Every screen in an application is an extension


of the Activity class

Activities use Views to form graphical user


interfaces that display information and
respond to user actions

Copyright © 2018 Pearson Education, Ltd. All Rights


Reserved.
Power Management
Alarms Wakelocks
n Implemented in the Linux kernel n Prevents an Android system from
and is visible to the app developer entering into sleep mode
through the AlarmManager in the
RunTime core libraries n These locks are requested through
the API whenever an application
n Is implemented in the kernel so requires one of the managed
that an alarm can trigger even if peripherals to remain powered on
the system is in sleep mode
n This allows the system to go n An application can hold one of
into sleep mode, saving the following wakelocks:
power, even though there is n Full_Wake_Lock
a process that requires a n Partial_Wake_Lock
wake up
n Screen_Dim_Wake_Lock
n Screen_Bright_Wake_Lock

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.


Summary
n OS design considerations for
n Operating system objectives and
multiprocessor and multicore
functions n Microsoft Windows overview
n User/computer interface
n Traditional Unix systems
n Resource manager
n History/description
n Evolution of operating systems n Modern Unix systems
n Serial processing n System V Release 4 (SVR4)
n Simple/multiprogrammed/time- n BSD
sharing batch systems
n Solaris 10
n Major achievements n Linux
n Developments leading to modern n History
operating systems n Modular structure
n Fault tolerance n Kernel components
n Fundamental concepts n Android
n Faults n Software/system architecture
n OS mechanisms n Activities
n Power management

Copyright © 2018 Pearson Education, Ltd. All Rights Reserved.

You might also like