0% found this document useful (0 votes)
31 views

Introduction

The document provides an overview of operating systems and their functions. It discusses how operating systems act as an interface between the user and computer hardware by managing resources, executing programs, and making the system convenient to use. It also describes how operating systems provide facilities for program creation and execution, access to I/O devices and files, and system access while resolving conflicts over resources.

Uploaded by

saarimsalim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Introduction

The document provides an overview of operating systems and their functions. It discusses how operating systems act as an interface between the user and computer hardware by managing resources, executing programs, and making the system convenient to use. It also describes how operating systems provide facilities for program creation and execution, access to I/O devices and files, and system access while resolving conflicts over resources.

Uploaded by

saarimsalim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 163

What is an Operating System (1)?

• A modern computer consists of:


One or more processors
Main memory
Disks
Printers
Various input/output devices.
• Managing all these varied components
requires a layer of software – the
Operating System (OS).
What is an Operating System (2)?
• An Operating System is a program that
acts as an intermediary/interface between
a user of a computer and the computer
hardware.
• OS goals:
– Control/execute user/application programs.
– Make the computer system convenient to use.
– Ease the solving of user problems.
– Use the computer hardware in an efficient
manner.
Services provided by an OS
• Facilities for program creation
– editors, compilers, linkers, debuggers, etc.
• Program execution
– loading in memory, I/O and file initialization.
• Access to I/O and files
– deals with the specifics of I/O and file formats.
• System access
– resolves conflicts for resource contention.
– protection in access to resources and data.
What Operating Systems Do
• Depends on the point of view.
• Users want convenience, ease of use and good
performance
– Don’t care about resource utilization.
• But a shared computer such as mainframe or
minicomputer must keep all users happy.
• Users of dedicate systems such as workstations have
dedicated resources but frequently use shared
resources from servers.
• Handheld computers are resource poor, optimized for
usability and battery life.
• Some computers have little or no user interface, such
as embedded computers in devices and automobiles.
A. Frank - P. Weisberg
Static View of System Components
Computer System Organization
• Computer-system operation
– One or more CPUs, device controllers connect through
common bus providing access to shared memory
– Concurrent execution of CPUs and devices competing
for memory cycles
• To ensure orderly access to the shared memory, a
memory controller synchronizes access to the
memory.
Computer-system operation
• When a computer powered up or rebooted—it needs to
have an initial program to run.
• This initial program, or bootstrap program, tends to
be simple.
• Typically, it is stored within the computer hardware in
read-only memory (ROM) or electrically erasable
programmable read-only memory (EEPROM), known
by the general term firmware.
• It initializes all aspects of the system, from CPU
registers to device controllers to memory contents.
• The bootstrap program must know how to load the
operating system and how to start executing that
system.
Kernel
• Several resources are managed by the OS.
• A portion of the OS resides in the main
memory.
– This includes the kernel, which contains the
most frequently used functions in the OS and, at
a given time, other portions of the OS currently
in use.
– The remainder of main memory contains user
and utility programs and data.
• The OS and the memory management
hardware in the processor jointly control the
allocation of main memory
Computer-system operation …
• Once the kernel is loaded and executing, it can start
providing services to the system and its users.
• Some services are provided outside of the kernel, by
system programs that are loaded into memory at boot
time to become system processes, or system
daemons that run the entire time the kernel is
running.
• On UNIX, the first system process is “init,” and it starts
many other daemons.
• Once this phase is complete, the system is fully
booted, and the system waits for some event to occur.
• An operating system is interrupt driven.
Computer-system operation …
• The occurrence of an event is usually
signaled by an interrupt from either the
hardware or the software.
• Hardware may trigger an interrupt at any time
by sending a signal to the CPU, usually by
way of the system bus.
• Software may trigger an interrupt by
executing a special operation called a
system call (also called a monitor call).
Common Functions of Interrupts
• Interrupt transfers control to the interrupt
service routine generally, through the
interrupt vector, which contains the
addresses of all the service routines
• Interrupt architecture must save the address
of the interrupted instruction
• A trap or exception is a software-generated
interrupt caused either by an error or a user
request
Interrupt Mechanism
• When the CPU is interrupted, it stops what it is
doing and immediately transfers execution to a fixed
location.
• The fixed location usually contains the starting
address where the service routine for the interrupt is
located.
• The interrupt service routine executes; on
completion, the CPU resumes the interrupted
computation.
• The interrupt must transfer control to the appropriate
interrupt service routine.
• However, interrupts must be handled quickly.
Interrupt Mechanism
• Generally, the table of pointers is stored in low
memory (the first hundred or so locations).
• These locations hold the addresses of the
interrupt service routines for the various
devices.
• This array, or interrupt vector, of addresses
is then indexed by a unique device
number, given with the interrupt request, to
provide the address of the interrupt service
routine for the interrupting device.
Interrupt Mechanism
• The interrupt architecture must also save the
address of the interrupted instruction.
• After the interrupt is serviced, the saved
return address is loaded into the program
counter, and the interrupted computation
resumes as though the interrupt had not
occurred.
Interrupt Timeline
Computer-System Operation
• I/O devices and the CPU can execute
concurrently
• Each device controller is in charge of a
particular device type
• Each device controller has a local buffer
• CPU moves data from/to main memory
to/from local buffers
• I/O is from the device to local buffer of
controller
• Device controller informs CPU that it has
finished its operation by causing an interrupt
I/O by Interrupts

Generate an interrupt when I/O is finished.


e.g. When character is finished being printed, interrupt CPU.
Allows CPU to do something else while character is
being printed
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Operating System Timeline
• First generation: 1945 – 1955
– Vacuum tubes
– Plug boards
• Second generation: 1955 – 1965
– Transistors
– Batch systems
• Third generation: 1965 – 1980
– Integrated circuits
– Multiprogramming
• Fourth generation: 1980 – present
– Large scale integration
– Personal computers
• Next generation: ???
– Systems connected by high-speed networks?
– Wide area resource management?
First generation: direct input
• Run one job at a time
– Enter it into the computer (might require rewiring!)
– Run it
– Record the results
• Problem: lots of wasted computer time!
– Computer was idle during first and last steps
– Computers were very expensive!
• Goal: make better use of an expensive
commodity: computer time

CS 1550, cs.pitt.edu
(originaly modified by Ethan
L. Miller and Scott A. Brandt)
Second generation: batch systems

• Bring cards to 1401


• Read cards onto input tape
• Put input tape on 7094
• Perform the computation, writing results to output
tape
• Put output tape on 1401, which prints output
Chapter 1
Spooling
• Original batch systems used tape drives
• Later batch systems used disks for buffering
– Operator read cards onto disk attached to the computer
– Computer read jobs from disk
– Computer wrote job results to disk
– Operator directed that job results be printed from disk
• Disks enabled simultaneous peripheral
operation on-line (spooling)
– Computer overlapped I/O of one job with execution of
another
– Better utilization of the expensive CPU
– Still only one job active at any given time

CS 1550, cs.pitt.edu
(originaly modified by Ethan
L. Miller and Scott A. Brandt)
Third generation: multiprogramming
• Multiple jobs in memory
– Protected from one another
Job 3 • Operating system
protected from each job
as well
Job 2
• Resources (time,
Memory hardware) split between
partitions Job 1
jobs
• Still not interactive
Operating – User submits job
system – Computer runs it
– User gets results minutes
(hours, days) later
Timesharing
• Multiprogramming allowed several jobs to be
active at one time
– Initially used for batch systems
– Cheaper hardware terminals -> interactive use
• Computer use got much cheaper and easier
– No more “priesthood”
– Quick turnaround meant quick fixes for problems
Views of an Operating System
• There are three classical views (in
literature):
1. Resource Manager – manages and allocates
resources.
2. Control program – controls the execution of
user programs and operations of I/O devices.
3. Command Executer – Provides an
environment for running user commands.
• But one more modern view: Operating
System as a Virtual Machine.
A. Frank - P. Weisberg
Operating System as a Resource
Manager
∙ Allow multiple programs to run at the same time
∙ Manage and protect memory, I/O devices, and other
resources
✔ Manages and protects multiple computer
resources: CPU, Processes, Internal/External
memory, Tasks, Applications, Users,
Communication channels, etc…
✔ Handles and allocates resources to multiple users
or multiple programs running at the same time
and space (e.g., processor time, memory, I/O
devices).
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Resource Manager oriented OS
names
• DEC RSX – Resource Sharing eXecutive
• MIT Multics – MULTiplexed Information and
Computing Services
• IBM MFT/MVT – Multiple Fixed/Variable Tasks
• IBM MVS – Multiple Virtual Storage
• DEC VMS – Virtual Memory System
• MVS TSO – Time Sharing Option
• CTSS – Compatible Time Sharing System
• IBM VM – Virtual machine

A. Frank - P. Weisberg
2. Control Program
• Control Program:
– Manages all the components of a complex
computer system in an integrated manner.
– Controls the execution of user programs and I/O
devices to prevent errors and improper use of
computer resources.
– Looks over and protects the computer: Monitor,
Supervisor, Executive, Controller, Master,
Coordinator ….
Control program oriented OS
names
• Unisys MCP – Master Control Program
• DR CP/M – Control
Program/Microcomputer
• IBM VM/CP – VM Control Program
• IBM AIX – Advanced Interactive eXecutive
• DEC RSX – Resource Sharing eXecutive

A. Frank - P. Weisberg
3. Command Executer
• Command Executer:
– Interfaces between the users and machine.
– Supplies services/utilities to users.
– Provides the users with a convenient CLI
(Command Language Interface), also called a
Shell (in UNIX), for entering the user commands.

A. Frank - P. Weisberg
Command Executer oriented OS names

• IBM AIX – Advanced Interactive Executive


• IBM VM/CMS – Conversational monitor
System

A. Frank - P. Weisberg
UNIX System Layout

A. Frank - P. Weisberg
Storage Structure
• Ideally, we want the programs and data to reside in
main memory permanently.
• This arrangement usually is not possible for the
following two reasons:
1. Main memory is usually too small to store all
needed programs and data permanently.
2. Main memory is a volatile storage device that
loses its contents when power is turned off or
otherwise lost.
Various Storage Systems
• The main differences among the
various storage systems lie in
speed, cost, size, and volatility.
• The wide variety of storage
systems can be organized in a
hierarchy according to speed
and cost.
• The higher levels are expensive,
but they are fast.
• As we move down the hierarchy,
the cost per bit generally
decreases, whereas the access
time generally increases.
Storage pyramid

Capacity Access latency


< 1 KB Registers 1 ns Better

1 MB Cache (SRAM) 2–5 ns


256 MB Main memory (DRAM) 50 ns
40 GB Magnetic disk 5 ms
Better > 1 TB Magnetic tape 50 sec

Goal: really large memory with very low latency


Latencies are smaller at the top of the hierarchy
Capacities are larger at the bottom of the hierarchy
Solution: move data between levels to create illusion of
large memory with low latency
Performance of Various Levels of
Storage

Movement between levels of storage hierarchy can be explicit or implicit


Memory

Addres Addres
0x2ffff User 0x2ffff
s program s
0x2d000
User data
0x2b000 and data 0x2bfff Limit2
User data
0x27fff User Limit 0x29000 Base
program 0x24fff User 2
Limit 1
0x23000 and data Bas 0x23000 program Base
e 1
0x1dfff
Operati 0x1dfff
Operati
ng ng
0 system 0 system
Single base/limit pair: set for each process
Two base/limit registers: one for program, one for data
The 4 Cache Questions
• When to put a new item into the cache?
• Which cache line to put the new item in?
• Which item to remove from the cache when a slot
is needed?
• Where to put a newly evicted item in main
memory?

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
OPERATING SYSTEM OVERVIEW:
Characteristics
• Time Sharing - multiprogramming
environment that's also interactive.
• Multiprocessing - Tightly coupled
systems that communicate via
shared memory. Used for scientific
applications. Used for speed
improvement by putting together a
number of off-the-shelf processors.
• Distributed Systems - Loosely
coupled systems that communicate
via message passing. Advantages
include resource sharing, speed up,
reliability, communication.
• Real Time Systems - Rapid
response time is main characteristic.
Used in control of applications
where rapid response to a stimulus
is essential.
Multiprocessor Systems
• Multiprocessor systems first appeared
prominently appeared in servers and have
since migrated to desktop and laptop
systems.
• Recently, multiple processors have
appeared on mobile devices such as
smartphones and tablet computers.
Multiprocessor System: Advantages
1. Increased throughput. By increasing the
number of processors, we expect to get more
work done in less time.
2. Economy of scale. Multiprocessor systems can
cost less than equivalent multiple
single-processor systems, because they can
share peripherals, mass storage, and power
supplies.
3. Increased reliability. If functions can be
distributed properly among several processors,
then the failure of one processor will not halt the
system, only slow it down.
Features
• Increased reliability of a computer system is crucial in
many applications.
• The ability to continue providing service proportional to
the level of surviving hardware is called graceful
degradation.
• Some systems go beyond graceful degradation and
are called fault tolerant, because they can suffer a
failure of any single component and still continue
operation.
• Fault tolerance requires a mechanism to allow the failure
to be detected, diagnosed, and, if possible, corrected.
• The HP NonStop (formerly Tandem) system uses both
hardware and software duplication to ensure continued
operation despite faults.
Multiprocessing System Types
• Asymmetric: Master-Slave
• Symmetric (SMP): Each processor performs all
tasks within the operating system.
– SMP means that all processors are peers
– An example of an SMP system is AIX, a commercial
version of UNIX designed by IBM.
– An AIX system can be configured to employ dozens of
processors.
– The benefit of this model is that many processes can run
simultaneously—N processes can run if there are N
CPUs—without causing performance to deteriorate
significantly.
• Multiprocessing adds CPUs to increase computing
power. If the CPU has an integrated memory
controller, then adding CPUs can also increase the
amount of memory addressable in the system.
SMP vs Asymmetric
• Sun Microsystems’ operating system SunOS
Version 4 provided asymmetric multiprocessing,
whereas Version 5 (Solaris) is symmetric on the
same hardware. (Software decides)
• Hardware may also decide SMP/Asymmetric.
Recent OS Design Requirements
• A recent trend in CPU design is to include multiple
computing cores on a single chip.
• Such multiprocessor systems are termed
multicore.
• They can be more efficient than multiple chips with
single cores because on-chip communication is
faster than between-chip communication.
• In addition, one chip with multiple cores uses
significantly less power than multiple single-core
chips.
• It is important to note that while multicore systems
are multiprocessor systems, not all multiprocessor
systems are multicore.
Multithreaded and Multicore Chips

(a) A quad-core chip with a shared L2 cache.


(b) A quad-core chip with separate L2 caches.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Dual Core Design
• Each core has its own
register set as well as its own
local cache.
• Other designs might use a
shared cache or a
combination of local and
shared caches.
• Aside from architectural
considerations, such as
cache, memory, and bus
contention, multicore CPUs
appear to OS as N standard
processors.
Types of modern operating systems
• Mainframe operating systems: MVS
• Server operating systems: FreeBSD, Solaris
• Multiprocessor operating systems: Cellular IRIX
• Personal computer operating systems: Windows,
Unix
• Real-time operating systems: VxWorks
• Embedded operating systems
• Smart card operating systems
⇒ Some operating systems can fit into more than one
category
Blade Servers
• Blade servers are a relatively recent
development in which multiple processor
boards, I/O boards, and networking boards
are placed in the same chassis.
• The difference between these and traditional
multiprocessor systems is that each
blade-processor board boots independently
and runs its own operating system.
• Some blade-server boards are
multiprocessor as well
Clustered Systems
• Gathers together multiple CPUs.
• Loosely Coupled System
• Purpose is to provide high availability
– High availability is provided by adding a level of
redundancy in the system.
• A layer of cluster software runs on the cluster
nodes.
• Each node can monitor one or more of the
others (over the LAN).
– If the monitored machine fails, the monitoring
machine can take ownership of its storage and
restart the applications that were running on the
failed machine.
Kernel Mode

• Applications run in user mode, and core operating


system components run in kernel mode.
• While many drivers run in kernel mode, some
drivers may run in user mode.
• A transition from user mode to kernel mode occurs
when the application requests the help of operating
system or an interrupt or a system call occurs.
• The system starts in kernel mode when it boots and
after the operating system is loaded, it executes
applications in user mode.
• There are some privileged instructions that can only be executed in kernel mode.
• The operating system code runs in a privileged processor mode known as kernel mode
• Kernel Mode
and has access to system data and hardware.
When we start a user-mode application, the operating system creates a process for the
application.
Dual Mode of Operation Protection
• The goal is protecting the Operating
System and others from malicious or
ignorant users.
• The User/Kernel Mode and Privileged
instructions.
• At system boot time, the hardware starts
in kernel mode.
• The operating system is then loaded and
starts user applications in user mode.
Dual Mode of Operation
• Kernel mode is also called supervisor mode, system
mode, or privileged mode.
• A bit, called the mode bit, is added to the hardware of the
computer to indicate the current mode: kernel (0) or user (1).
• With the mode bit, we can distinguish between a task that is
executed on behalf of the operating system and one that is
executed on behalf of the user.
• The hardware allows privileged instructions to be executed
only in kernel mode.
• If an attempt is made to execute a privileged instruction in
user mode, the hardware does not execute the instruction
but rather treats it as illegal and traps it to the operating
system.
Dual Mode of Operation
•Concurrent threads might interfere with others.
•This leads to protection of resources by
user/supervisor mode.
•I/O Define I/O instructions as privileged; they can
be executed only in Supervisor mode.
•System calls get us from user to supervisor
mode.
Summarily
• The operating system code runs in a privileged processor
mode known as kernel mode and has access to system data
and hardware.
• Applications run in a non-privileged processor mode are
known as user mode and have limited access to system data
and hardware by making system calls, which are actually a
set of tightly controlled application programming interfaces
(APIs).
• Corresponding to each system call is a library procedure that
user programs can call.
• This procedure puts the parameters of the system call in a
specified place, such as the machine registers; it then issues
a TRAP instruction, which is a kind of protected procedure
call, to start the operating system.
Operating System Structure
• The CPU is wasted if a job waits for I/O.
• This leads to: Multiprogramming (dynamic
switching):
– While one job waits for a resource, the CPU can find
another job to run. It means that several jobs are ready
to run and only need the CPU in order to continue.
• By multiprogramming the CPU time is not wasted,
because, while one process moves on some I/O
work, the OS picks another process to execute till
the current one passes to I/O operation.
• Multiprogramming increases CPU utilization by
organizing jobs (code and data) so that the CPU
always has one to execute.
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
I/O Devices
∙ Controller runs a device-accepts commands from
the OS and executes them
∙ Complicated business
∙ e.g. gets command to read sector x on disk y.
Must convert to (cylinder, sector, head) address,
move arm to correct cylinder, wait for sector to
rotate under the head, read and store bits coming
off the drive, compute checksum, store bits as
words in memory
• Controller contains a computer to run its device

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Device Driver
∙ OS software that talks to controller-gives
commands, accepts responses
∙ Each controller manufacturer supplies a driver
for each OS
∙ Driver runs in kernel mode
∙ Controller has registers which are used to
communicate with the driver
∙ Three modes of communication
∙ Polling
∙ Interrupts
∙ DMA

Tanenb aum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I/O by polling device
∙ Driver issues command to controller
∙ Driver polls device until it is ready
∙ E.g. Send character to printer controller and
poll until it is ready to accept the next character
∙ Big use of CPU
∙ Called programmed I/O-not really used any
more

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Memory Management
• To execute a program all (or part) of the
instructions must be in memory
• All (or part) of the data that is needed by
the program must be in memory.
• Memory management determines what is in
memory and when
– Optimizing CPU utilization and computer
response to users
Memory Management Activities
• Keeping track of which parts of memory
are currently being used and by whom
• Deciding which processes (or parts
thereof) and data to move into and out of
memory
• Allocating and deallocating memory space
as needed
Storage Management
• OS provides uniform, logical view of information
storage
– Abstracts physical properties to logical storage unit - file
– Each medium is controlled by 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
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 need not 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)
Computing Environments -
Virtualization
• Emulation used when source CPU type different
from target type
– Generally slowest method
– When computer language not compiled to native code
– Interpretation
• Virtualization – OS natively compiled for CPU,
running guest
– OSes also natively compiled
– Consider VMware running WinXP guests, each running
applications, all on native WinXP host OS
– VMM provides virtualization services
Computing Environments - Virtualization
• Use cases involve laptops and desktops running
multiple OSes for exploration or compatibility
– Apple laptop running Mac OS X host, Windows as a
guest
– Developing apps for multiple OSes 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)
Computing Environments -
Virtualization
Virtual Machines (2)

(a) A type 1 hypervisor. (b) A type 2 hypervisor.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Computing Environments – Cloud
Computing
• Delivers computing, storage, even apps as a service across
a network
• Logical extension of virtualization as based on virtualization
– Amazon EC2 has thousands of servers, millions of VMs, PBs of
storage available across the Internet, pay based on usage
• 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)
Computing Environments – Cloud
Computing
• Cloud compute environments
composed of traditional OSes,
plus VMMs, plus cloud
management tools
– Internet connectivity requires
security like firewalls
– Load balancers spread traffic across
multiple applications
Kernel Data Structures
• Many similar to standard programming data
structures
• Singly linked list

• Doubly linked list

• Circular linked list


Kernel Data Structures
• Binary search tree
left <= right
– Search performance is O(n)
– Balanced binary search
tree is O(lg n)
Kernel Data Structures
• Hash function can create a hash map

• Bitmap – string of n binary digits representing the


status of n items
• Linux data structures defined in include files
<linux/list.h>,<linux/kfifo.h>,
<linux/rbtree.h>
System Structures
Operating System Services (Cont.)
• Another set of OS functions exists for ensuring the efficient operation of
the system itself via resource sharing
– Resource allocation - When multiple users or multiple jobs running
concurrently, resources must be allocated to each of them
• Many types of resources - Some (such as CPU cycles, main memory,
and file storage) may have special allocation code, others (such as I/O
devices) may have general request and release code
– Accounting - To keep track of which users use how much and what
kinds of computer resources
– Protection and security - The owners of information stored in a
multiuser or networked computer system may want to control use of
that information, concurrent processes should not interfere with each
other
• Protection involves ensuring that all access to system resources is
controlled
• Security of the system from outsiders requires user authentication,
extends to defending external I/O devices from invalid access attempts
• If a system is to be protected and secure, precautions must be instituted
throughout it. A chain is only as strong as its weakest link.
A View of Operating System Services
System calls
• System calls is the interface users contact
with OS and hardware
• System calls vary from system to system,
but the underlying concepts are similar
System Calls
• Typically written in a high-level language (C or
C++)
• Mostly accessed by programs via a high-level
Application Program Interface (API) rather than
direct system call use
– Three most common APIs are Win32 API for Windows,
POSIX API for POSIX-based systems (including virtually
all versions of UNIX, Linux, and Mac OS X), and Java
API for the Java virtual machine (JVM)
Example of System Calls
• System call sequence to copy the contents
of one file to another file
API – System Call – OS
Relationship
System Call Parameter Passing
• Three general methods used to pass parameters to
the OS
– Simplest: pass the parameters in registers
• Sometimes, may be more parameters than registers
– Parameters stored in a block, or table, in memory, and
address of block passed as a parameter in a register
• This approach taken by Linux and Solaris
– Parameters placed, or pushed, onto the stack by the
program and popped off the stack by the operating
system
– Block and stack methods do not limit the number or
length of parameters being passed
System Call Implementation
• Typically, a number associated with each
system call
– System-call interface maintains a table indexed
according to these numbers
• The system call interface invokes intended
system call in OS kernel and returns status of
the system call and any return values
• The caller need know nothing about how the
system call is implemented
Example of Standard API
System Calls
•The calling
program first
pushes the
parameters onto
the stack
•Executes a
TRAP instruction
to switch from
user mode to
kernel mode and
start execution at
a fixed address
within the kernelThe 11 steps in making the system call
read(fd, buffer, nbytes).
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Parameter Passing via Table
Actual call to the library procedure
• Trap either jumps to a single fixed location or there
is an 8-bit field in the instruction giving the index into
a table in memory containing jump addresses
• The kernel code that starts following the TRAP
examines the system-call number and then
dispatches to the correct system-call handler,
usually via a table of pointers to system-call
handlers indexed on system-call number.
• At that point the system-call handler runs.
• Once it has completed its work, control may be
returned to the user-space library procedure at the
instruction following the TRAP instruction.
Types of System Calls
• Process control
– end, abort
– load, execute
– create process, terminate process
– 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
Types of System Calls
• 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
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
Types of System Calls (Cont.)
• Protection
– Control access to resources
– Get and set permissions
– Allow and deny user access
Process Management
System Calls in Linux

Some system calls relating to processes.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls for File Management (1)

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System Calls for File Management (2)

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Miscellaneous System Calls

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Examples of Windows and
Unix System Calls
Standard C Library Example
• C program invoking printf() library call, which
calls write() system call
Memory Layout
• Processes have three segments:
text, data, and stack.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Shell

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
fork
• pid=fork()
• Duplicates parent process completely
Everything duplicated -data,registers,fd’s
• Fork returns a value (pid)
• Zero in child
• Child’s PID in parent
• Used to differentiate child from parent

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
fork and other calls
fork example code
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[]) {


printf("hello world (pid:%d)\n", (int) getpid());
int rc = fork();
if (rc < 0) { // fork failed; exit
fprintf(stderr, "fork failed\n");
exit(1);
} else if (rc == 0) { // child (new process)
printf("hello, I am child (pid:%d)\n", (int) getpid());
} else { // parent goes down this path (main)
printf("hello, I am parent of %d (pid:%d)\n", rc, (int)
getpid());
}
return 0;
}
execve
• Replaces process’ core image by the file named
in its invocation
• execve(name,arg,environp) has 3 parameters
• name of file (e.g. cp command)
• arg-pointer to argument array
• environp-pointer to environment array

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
excve (example)
• cp f1 f2 is located by execve and parameters
are passed to it by execve
• main(argc, argv, envp) is main prog in cp
• argc is #items on command line (=3 in cp)
• argv points to array (arg[0] points to cp, arg[1] points to f1,
• envp points to environment, an array of name=value with info like
terminal type

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
fork with wait (more deterministic)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main(int argc, char *argv[]) {
printf("hello world (pid:%d)\n", (int) getpid());
int rc = fork();
if (rc < 0) { // fork failed; exit
fprintf(stderr, "fork failed\n");
exit(1);
} else if (rc == 0) { // child (new process)
printf("hello, I am child (pid:%d)\n", (int) getpid());
} else { // parent goes down this path (main)
int rc_wait = wait(NULL);
printf("hello, I am parent of %d (rc_wait:%d) (pid:%d)\n",
rc, rc_wait, (int) getpid());
}
return 0; }
fork with exec (p3.c)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
int main(int argc, char *argv[]) {
printf("hello world (pid:%d)\n", (int) getpid());
int rc = fork();
if (rc < 0) { // fork failed; exit
fprintf(stderr, "fork failed\n");
exit(1);
} else if (rc == 0) { // child (new process)
printf("hello, I am child (pid:%d)\n", (int) getpid());
char *myargs[3];
myargs[0] = strdup("wc"); // program: "wc" (word count)
myargs[1] = strdup("p3.c"); // argument: file to count
myargs[2] = NULL; // marks end of array
execvp(myargs[0], myargs); // runs word count
printf("this shouldn’t print out");
} else { // parent goes down this path (main)
int rc_wait = wait(NULL);
printf("hello, I am parent of %d (rc_wait:%d) (pid:%d)\n",rc, rc_wait, (int) getpid());
}
return 0;
}
Redirection (wc p3.c > newfile.txt)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/wait.h>

int main(int argc, char *argv[]) {


int rc = fork();
if (rc < 0) { // fork failed; exit
fprintf(stderr, "fork failed\n");
exit(1);
} else if (rc == 0) { // child: redirect standard output to a file
close(STDOUT_FILENO);
open("./p4.output", O_CREAT|O_WRONLY|O_TRUNC, S_IRWXU);

// now exec "wc"...


char *myargs[3];
myargs[0] = strdup("wc"); // program: "wc" (word count)
myargs[1] = strdup("p4.c"); // argument: file to count
myargs[2] = NULL; // marks end of array
execvp(myargs[0], myargs); // runs word count
} else { // parent goes down this path (main)
int rc_wait = wait(NULL);
}
return 0;
}
Unix Pipe
grep -o foo file | wc –l
Beyond fork(), exec(), and wait(), there are a lot of other interfaces for
interacting with processes in UNIX systems. For example, the kill() system call
is used to send signals to a process, including directives to pause, die, and other
useful imperatives.
For convenience, in most UNIX shells, certain keystroke combinations are
configured to deliver a specific signal to the currently running process; for example,
control-c sends a SIGINT (interrupt) to the process (normally terminating it) and
control-z sends a SIGTSTP (stop) signal thus pausing the process in mid-execution
(you can resume it later with a command, e.g., the fg built-in command found in
many shells).
Signals
• Are notifications (software interrupt) sent to a
running process in order to notify it of various
"important or exceptional" events.
By their nature, they interrupt whatever the process is
doing at this minute, and force it to handle them
immediately.
• Signals can be initiated by programs, users, or
administrators.
• Each signal has an integer number that represents it
(1, 2 and so on), as well as a symbolic name that is
usually defined in the file /usr/include/signal.h or one
of the files included by it directly or indirectly
(HUP, INT and so on. Use the command 'kill -l' to see a list
of signals supported by your system).
Signals Handler
•Each signal may have a signal handler, which is a
function that gets called when the process receives
that signal.
The function is called in "asynchronous mode", meaning that
no where in your program you have code that calls this
function directly.
•Instead, when the signal is sent to the process, the
operating system stops the execution of the process,
and "forces" it to call the signal handler function.
When that signal handler function returns, the process continues
execution from wherever it happened to be before the signal was
received, as if this interruption never occurred.
Each Unix signal has a default set of effects on a Unix program.
A signal stack is a special area of memory to be used as the execution
stack during signal handlers.
Default Effect of Signal
• Each signal has a current disposition, which
determines how the process behaves when it is
delivered the signal i.e. action associated with a
signal.
Ignore / Catch / Let Default Action Apply
• Using sigaction/signal system calls, a process can
elect one of the following behaviors to occur on
delivery of the signal:
Perform the default action;
Ignore the signal;
or Catch the signal with a signal handler, a
programmer-defined function that is automatically invoked
when the signal is delivered.
• https://www.gnu.org/software/libc/manual/html_node/index.html#SEC_Contents
Signals Handlers …
• Programmers can code their applications to respond
in customized ways to most signals.
By default, a signal handler is invoked on the normal
process stack.
• It is possible to arrange that the signal handler uses
an alternate stack i.e. programmers can customize
signal handlers.
• Two signals are unable to be redefined by a signal
handler.
SIGKILL always stops a process and SIGSTOP always
moves a process from the foreground to the
background.
These two signals cannot be "caught" by a signal
handler.
Signals
• The entire signals subsystem provides a rich
infrastructure to deliver external events to
processes, including ways to receive and process
those signals within individual processes, and
ways to send signals to individual processes as
well as entire process groups.
• To use this form of communication, a process
should use the signal() system call to “catch”
various signals; doing so ensures that when a
particular signal is delivered to a process, it will
suspend its normal execution and run a particular
piece of code in response to the signal.
Sending Signals Using The Keyboard
• The most common way of sending signals to processes is using
the keyboard.
• There are certain key presses that are interpreted by the system
as requests to send signals to the process with which we are
interacting:

• Ctrl-C Pressing this key causes the system to send an INT


signal (SIGINT) to the running process.
• By default, this signal causes the process to immediately
terminate.
Sending Signals Using The Keyboard …

• Ctrl-Z Pressing this key causes the system to send


a TSTP signal (SIGTSTP) to the running process.
• By default, this signal causes the process to
suspend execution.

• Ctrl-\ Pressing this key causes the system to send a


ABRT signal (SIGABRT) to the running process.
• By default, this signal causes the process to
immediately terminate.
Sending Signals From Command Line
(internal to shell)
• kill The kill command accepts two parameters: a signal name (or number), and a
process ID.
• kill -<signal> <PID>
For example, in order to send the INT signal to process with PID 5342, type:
• kill -INT 5342
• This has the same affect as pressing Ctrl-C in the shell that runs that process.

• If no signal name or number is specified, the default is to send a SIGTERM signal to the
process, which normally causes its termination, and hence the name of the kill command.
• If SIGTERM fails, we can escalate to using the SIGKILL signal to stop the process:
• kill -9 4140
• Because SIGKILL cannot be handled, stopping a process with SIGKILL is generally
considered a bad idea. Using SIGKILL prevents a process from cleaning up after itself and
exiting gracefully.

• fg On most shells, using the 'fg' command will resume execution of the process (that
was suspended with Ctrl-Z), by sending it a CONT signal.
Catchable And Non-Catchable
Signals
• SIGKILL signal (kill -9 command in Unix) is such a
signal. This is use to shut down using this signal if it
gets "wild".
• One process that uses this signal is a system shutdown
process. It first sends a TERM signal to all processes, waits a
while, and after allowing them a "grace period" to shut down
cleanly, it kills whichever are left using the KILL signal.
• SIGSTOP is also a signal that a process cannot
catch, and forces the process's suspension
immediately.
• This is useful when debugging programs whose
behavior depends on timing.
More on Kill
• For a 'polite' stop to the process, send SIGTSTP:
• kill -TSTP [pid]

• For a 'hard' stop, send SIGSTOP:


• kill -STOP [pid]

• To resume execution of the process, sent SIGCONT:


• kill -CONT [pid]

https://www.gnu.org/software/libc/manual/html_node/Job-Control-Signals.html
Important

• Like KILL, STOP can’t be caught, blocked, or


ignored: it always stops the receiving process.
• TSTP on the other hand can be ignored or handled
in a different way; for example, shells, and Emacs,
set up TSTP handlers to deal with Ctrl-Z
themselves.
• This behaviour in shells ensures that pressing Ctrl-Z
is always safe, and won’t get you stuck in a terminal
with a stopped process and no way of resuming it.
Example
#include <stdio.h> /* standard I/O functions */

#include<unistd.h> /*standard unix functions, e.g. getpid()*/

#include <signal.h> /* signal name macros, signal() prototype */

/* first, here is the signal handler */


void catch_int(int sig_num)
{
/* re-set the signal handler again to catch_int, for next time */
signal(SIGINT, catch_int);
printf("Don't do that\n");
fflush(stdout);
}
int main(int argc, char* argv[])
{
/* set the INT (Ctrl-C) signal handler to 'catch_int' */
signal(SIGINT, catch_int);
for ( ;; )
pause();
}
Signal Types
• Maskable: signals which can be changed or ignored
by the user (e.g., Ctrl+C).
• Non-Maskable: signals which cannot be changed or
ignored by the user. These typically occur when the
user is signaled for non-recoverable hardware
errors.
Signals in Linux (1)

The signals required by POSIX.

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
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 (a) At system startup (b) running a program
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
• Process exits with code of 0 – no
error or > 0 – error code
System Programs
• System programs provide a convenient
environment for program development and
execution.
System Programs
• Most users’ view of the operating system is defined by
system programs, not the actual system calls

• File management - Create, delete, copy, rename, print,


dump, list, and 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
System Programs (Cont.)
• File modification
– Text editors / commands to search contents of files or
perform transformations of the text

• Programming-language support - Compilers,


assemblers, debuggers and interpreters

• Program loading and execution- Absolute


loaders, relocatable loaders, linkage editors, and
overlay-loaders, debugging systems for higher-level
and machine language

• Communications - Provide the mechanism for


creating virtual connections among processes,
users, and computer systems
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
MS Windows Registry

• It is a central hierarchical database used in MS Windows to


store information that is necessary to configure the system for
one or more users, applications, and hardware devices.
• Registry contains information that Windows continually
references during operation, such as profiles for each user,
the applications installed on the computer and the types of
documents that each can create, property sheet settings for
folders and application icons, what hardware exists on the
system, and the ports that are being used.
• The kernel, device drivers, services, Security Accounts
Manager, and user interface can all use the registry.
• Alternatively applications may use XML files for keeping
configuration information
Operating System Structure
• General-purpose OS is very large program
Simple Structure
• MS-DOS – written to
provide the most
functionality in the
least space
– Not divided into
modules
– Although MS-DOS has
some structure, its
interfaces and levels of
functionality are not
well separated
UNIX
• UNIX – limited by hardware functionality, the
original UNIX operating system had limited
structuring.
• 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
Traditional UNIX System Structure
Beyond simple but not fully layered
Structure of the Linux kernel

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Layered Approach
• The operating system is
divided into a number of
layers (levels), each built
on top of lower layers.
The bottom layer (layer
0), is the hardware; the
highest (layer N) is the
user interface.
• With modularity, layers
are selected such that
each uses functions
(operations) and
services of only
Microkernel System Structure
• Moves as much from the kernel into user space
• Mach example of microkernel.
– Mac OS X kernel (Darwin) partly based on Mach.

• Communication takes place between user modules using


message passing.

• Benefits:
– Easier to extend a microkernel
– Easier to port the operating system to new architectures
– More reliable (less code is running in kernel mode)
– More secure

• Detriments:
– Performance overhead of user space to kernel space
communication
Microkernel System Structure
Modules
• Most modern operating systems implement
loadable kernel modules.
– Uses object-oriented approach
– Each core component is separate
– Each talks to the others over known interfaces
– Each is loadable as needed within the kernel
• Overall, similar to layers but with more
flexible.
– Linux, Solaris, etc
Solaris Modular Approach
Hybrid Systems
• Most modern operating systems actually not one
pure model
– Hybrid combines multiple approaches to address
performance, security, usability needs
– Linux and Solaris kernels in kernel address space, so
monolithic, plus modular for dynamic loading of
functionality
– Windows mostly monolithic, plus microkernel for different
subsystem personalities
• Apple Mac OS X hybrid, layered, Aqua UI plus
Cocoa programming environment
– Kernel consists of Mach microkernel and BSD Unix parts,
plus I/O kit and dynamically loadable modules (called
kernel extensions)
Mac OS X Structure
iOS
• Apple mobile OS for iPhone, iPad
– Structured on Mac OS X, added
functionality
– Does not run OS X applications
natively
• Also runs on different CPU architecture
(ARM vs. Intel)
– Cocoa Touch Objective-C API for
developing apps
– Media services layer for graphics,
audio, video
– Core services provides cloud
computing, databases
– Core operating system, based on Mac
OS X kernel
Android
• Developed by Open Handset Alliance (mostly
Google): Purchased by Google in 2005
– AOSP
• Similar stack to IOS
• 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
Android Architecture
Android Linux Kernel
• Android kernel lacks drivers not applicable in
mobile environments, making the kernel
smaller.
• In addition, Android enhances the Linux
kernel with features that are tailored to the
mobile environment, and generally not as
useful or applicable on a desktop or laptop
platform.
Android Runtime Concepts (ART)
• Current application runtime used by Android,
introduced with Android version 4.4 (KitKat).
– When Android was designed initially, it was designed for
single core (with minimal multithreading support in
hardware) and low-memory devices
• All Android applications written in Java are compiled
to dex bytecode.
– While Dalvik uses dex bytecode format for portability, it
has to be converted (compiled) to machine code to be
actually run by a processor.
– The Dalvik runtime did this conversion from dex bytecode
to native machine code when the application ran, and this
process was called JIT (just-in-time) compilation.
– Because JIT compiles only a part of the code, it has a
smaller memory footprint and uses less physical space on
the device
Dalvik vs ART
• Dalvik has to do JIT-compilation every time the
app is run, which consumes a considerable
amount of processor resources.
• ART also executes dex bytecode but instead of
compiling the bytecode at runtime, ART compiles
the bytecode to native machine code during
install time of the app.
• This is called aheadof-time (AOT) compilation.
• ART uses the “dex2oat” tool to do this
compilation at install time.
• The output of the tool is a file that is then
executed when the application runs.
Life cycle of an APK
•The cycle begins with
source code being
compiled into .dex format
and combined with any
appropriate support code to
form an APK.
•On the user side, the
received APK is unpacked.
• The resources and native
code are generally installed
directly into the application
directory.
•The output of the dex2oat
function is an Executable
and Linkable Format (ELF)
file, which runs directly
without an interpreter.
System Libraries
• The layer below the Application Framework
consists of two parts: System Libraries, and
Android Runtime.
• The System Libraries component is a collection
of useful system functions, written in C or C+ +
and used by various components of the Android
system.
• They are called from the application framework
and applications through a Java interface.
• These features are exposed to developers
through the Android application framework.
System Libraries
• Surface Manager: Android uses a compositing window
manager similar to Vista or Compiz, but it is much
simpler.
– Instead of drawing directly to the screen buffer, drawing
commands go into off-screen bitmaps that are then
combined with other bitmaps to form the screen content.
– Create interesting effects, such as see-through windows
• OpenGL: OpenGL (Open Graphics Library) is a
cross-language, multiplatform API for rendering 2D and
3D computer graphics.
– OpenGL/ES (OpenGL for embedded systems) is a subset
of OpenGL designed for embedded systems.
• Media Framework: The Media Framework supports
video recording and playing in many formats, including
AAC, AVC (H.264), H.263, MP3, and MPEG-4.
System Libraries
• SQL Database: Android includes a lightweight
SQLite database engine for storing persistent data.
• Browser Engine: For fast display of HTML
content, Android uses the WebKit library, which is
essentially the same library used in Safari and
iPhone.
– It was also the library used for the Google Chrome
browser until Google switched to Blink.
• Bionic LibC: This is a stripped-down version of
the standard C system library, tuned for embedded
Linux-based devices.
– The interface is the standard Java Native Interface (JNI).
Android System Architecture
Operating-System Debugging
• Debugging is finding and fixing errors, or bugs
• OSes generate log files containing error
information
– Failure of an application can generate core dump file
capturing memory of the process
– Operating system failure can generate crash dump file
containing kernel memory
• Beyond crashes, performance tuning can optimize
system performance
– Sometimes using trace listings of activities, recorded
for analysis
– Profiling is periodic sampling of instruction pointer to
look for statistical trends
OS Performance Tuning
• Improve performance
by removing
bottlenecks
• OS must provide
means of computing
and displaying
measures of system
behavior
– For example, “top”
program or Windows
Task Manager
Dtrace: Performance analysis and
Troubleshooting tool
● DTrace tool in Solaris,
FreeBSD, Mac OS X
allows live instrumentation
on production systems
● Probes fire when code is
executed within a
provider, capturing state
data and sending it to
consumers of those
probes
● Example of following
XEventsQueued system
call move from libc
library to kernel and back
DTrace
● DTrace code to record
amount of time each process
with UserID 101 is in running
mode (on CPU) in
nanoseconds
Operating System Generation
• Operating systems are designed to run on any of a
class of machines; the system must be configured
for each specific computer site
• SYSGEN program obtains information concerning
the specific configuration of the hardware system
– Used to build system-specific compiled kernel or
system-tuned
– Can general more efficient code than one general
kernel
– Combine user-specified options and parameters with
manufacturer-supplied general-purpose program code
to produce an operating system tailored for a particular
hardware and software environment.
System Boot
• When power initialized on system, execution starts
at a fixed memory location
– Firmware ROM used to hold initial boot code
• Operating system must be made available to
hardware so hardware can start it
– Small piece of code – bootstrap loader, stored in
ROM or EEPROM locates the kernel, loads it into
memory, and starts it
– Sometimes two-step process where boot block at
fixed location loaded by ROM code, which loads
bootstrap loader from disk
• Common bootstrap loader, GRUB, allows
selection of kernel from multiple disks, versions,
kernel options
• Kernel loads and system is then running
Boot up phases
• There are 4 phases to starting up the system:
• BIOS
• Boot loader
• Kernel
• Upstart (which manages system tasks and
services )
Core Boot Tasks Started by Upstart
• Plymouth - The graphical boot animation and
logger
• mountall - Mounts all filesystems defined on
/etc/fstab
• network* - Network related services
• Display Manager (GDM,KDM,XDM,...)
• (upstart tasks/services are configured at
/etc/init)
BIOS Phase
• When the computer begins execution, it starts
by executing this code, which is also called the
firmware, as it is normally stored in a permanent
form of memory, such as ROM, on the
computer's motherboard.
• On a Macintosh computer this is the
OpenFirmware.
• This code must initialize the hardware other than
the CPU, and obtain the code for the next step,
the boot loader.
• Modern computers provide several possibilities
for the boot loader and the choice is normally
set on the BIOS startup screen.
Boot Loader Phase
• There are several possible types of boot loaders
and ways for the BIOS to obtain them.
• A boot loader stored in the first sector of a hard
disk, the Master Boot Record, or MBR.
– This may be GRUB or LILO or yaboot or others.
• A boot loader stored on some other storage
device, such as a CDR or USB flash drive.
• A boot loader which uses the network, such as
the Pre-Execution Environment (PXE).
– This code is normally stored on a ROM on the
networking card itself.
• The job of the boot loader is to begin the next
phase, loading the kernel and an initial ram disk
filesystem.
Kernel Phase
• The bootloader starts the kernel running.
• To keep kernels to a reasonable size and
permit separate modules for separate
hardware, modern kernels also use a file
system which is present in memory, called an
'initrd' for 'initial ram disk'.
– Both the kernel file to load and the initial ram disk
are normally specified as options to the boot
loader.
• The kernel launches the init script inside the
initrd file system, which loads hardware
drivers and finds the root partition.
System startup
• After the kernel is running, the remainder of the
operating system is brought online.
• First the root partition and filesystem is located,
checked and mounted.
• Next the init process is started, which runs the
initialization scripts.
• These scripts involve different /etc/rc scripts and
upstart events that eventually gives you a
ready-to-use computer with a login screen.
– The root partition with the operating system can be
somewhere completely different than the kernel, for
instance on another drive or on a remote computer.

You might also like