0% found this document useful (0 votes)
13 views50 pages

CH 1

Chapter 1 introduces the fundamental concepts of operating systems, including their role as intermediaries between users and hardware, and outlines the organization of computer systems. It covers key topics such as multiprogramming, multitasking, memory management, and virtualization, emphasizing the importance of resource management and system calls. The chapter also discusses the structure of computer systems, the function of interrupts, and the characteristics of various types of storage.

Uploaded by

anischelly95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views50 pages

CH 1

Chapter 1 introduces the fundamental concepts of operating systems, including their role as intermediaries between users and hardware, and outlines the organization of computer systems. It covers key topics such as multiprogramming, multitasking, memory management, and virtualization, emphasizing the importance of resource management and system calls. The chapter also discusses the structure of computer systems, the function of interrupts, and the characteristics of various types of storage.

Uploaded by

anischelly95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Chapter 1: Introduction

Presented by: Dr. Labed Abdeldjalil


Chapter 1: Introduction

▪ What Operating Systems Do


▪ Computer-System Organization
▪ Computer-System Architecture
▪ Operating-System Operations
▪ Resource Management
▪ Virtualization
▪ System Calls
▪ Why Applications are Operating System Specific

Operating System 1.2


Objectives

▪ Describe the general organization of a computer system and the role of

interrupts

▪ Describe the components in a modern, multiprocessor computer system

▪ Illustrate the transition from user mode to kernel mode

▪ Illustrate how system calls are used to provide operating system services

Operating System 1.3


What is an Operating System?

▪ A program that acts as an intermediary between a user of a computer and


the computer hardware

▪ Operating system goals:

• Execute user programs and make solving user problems easier

• Make the computer system convenient to use

• Use the computer hardware in an efficient manner

Operating System 1.4


Computer System Structure

▪ Computer system can be divided into four components:


1) Hardware – provides basic computing resources
 CPU, memory, I/O devices
2) Operating system
 Controls and coordinates use of hardware among various
applications and users
3) Application programs – define the ways in which the system
resources are used to solve the computing problems of the users
 Word processors, compilers, web browsers, database systems,
video games
4) Users
 People, machines, other computers

Operating System 1.5


Abstract View of Components of Computer

Operating System 1.6


Operating System Definition

▪ No universally accepted definition


▪ “The one program running at all times on the computer”
• is the kernel, part of the operating system

▪ Everything else is either


• A system program (ships with the operating system, but not part of
the kernel) , or
• An application program, all programs not associated with the
operating system

▪ Today’s OSes for general purpose and mobile computing also include
middleware – a set of software frameworks that provide additional
services to application developers such as databases, multimedia,
graphics

Operating System 1.7


Computer System Organization

▪ Computer-system operation
• One or more CPUs, device controllers connect through common bus
providing access to shared memory
 Device controllers It’s a small electronic part that knows how to
speak the device’s language
 The CPU sends commands, and the device controller makes
sure the connected device understands them.

Example:
CPU: "Hey printer, print this!"
Device controller: "Alright, let me tell the
printer to do that and get back to you."

Operating System 1.8


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

▪ Each device controller type has an operating system device driver to


manage it

• Device driver is a system software that teaches the computer how to


use its HW!

▪ 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
Operating System 1.9
Computer-System Operation
▪ Example
▪ The device driver initializes an
I/O operation by loading
appropriate registers in the
device controller.
▪ The device controller checks the
registers to decide the required
action (e.g., read a character
from the keyboard).
▪ The controller transfers data
from the device to its local buffer.
▪ Once the transfer is complete,
the device controller notifies the
device driver.
▪ The device driver hands control
back to the operating system,
potentially providing the data or
its pointer for further use. Interrupt-drive I/O Cycle
Operating System 1.10
Common Functions of Interrupts

▪ An interrupt is like tapping someone on the shoulder to get their


attention while they’re working.
➢ Here’s what happens:
• The CPU stops what it’s doing and jumps to a special helper
program (Interrupt Service Routine or ISR) to deal with the
interrupt.
• The CPU uses an interrupt vector (a list of addresses) to find the
right helper program for the task.
• Before jumping, it saves where it stopped CPU
(the address of the interrupted instruction) interrupt
so it can return and continue later.
▪ A trap or exception is a software-generated
interrupt caused either by an error or a user
request
▪ An operating system is interrupt driven

Operating System 1.11


Storage Structure
▪ Main memory – only large storage media that the CPU can access directly
• Random access
• Typically, volatile
• Typically, random-access memory in the form of Dynamic Random-
access Memory (DRAM)
▪ Secondary storage – extension of main memory that provides large
nonvolatile storage capacity

Main memory

Operating System 1.12


Storage Structure (Cont.)
▪ Hard Disk Drives (HDD) – rigid metal or glass platters covered with
magnetic recording material
• Disk surface is logically divided into tracks, which are subdivided into
sectors
• The disk controller determines the logical interaction between the device
and the computer
▪ Non-volatile memory (NVM) devices– faster than hard disks, nonvolatile
• Various technologies (SSD)
• Becoming more popular as capacity and performance increases, price drops

HDD SSD

Operating System 1.13


Storage Definitions and Notation Review (OPTIONAL)

The basic unit of computer storage is the bit. A bit can contain one of two
values, 0 and 1. All other storage in a computer is based on collections of bits.
Given enough bits, it is amazing how many things a computer can represent:
numbers, letters, images, movies, sounds, documents, and programs, to name
a few. A byte is 8 bits, and on most computers it is the smallest convenient
chunk of storage. For example, most computers don’t have an instruction to
move a bit but do have one to move a byte. A less common term is word,
which is a given computer architecture’s native unit of data. A word is made
up of one or more bytes. For example, a computer that has 64-bit registers and
64-bit memory addressing typically has 64-bit (8-byte) words. A computer
executes many operations in its native word size rather than a byte at a time.

Computer storage, along with most computer throughput, is generally


measured and manipulated in bytes and collections of bytes. A kilobyte, or
KB , is 1,024 bytes; a megabyte, or MB, is 1,0242 bytes; a gigabyte, or GB, is
1,0243 bytes; a terabyte, or TB, is 1,0244 bytes; and a petabyte, or PB, is 1,0245
bytes. Computer manufacturers often round off these numbers and say that
a megabyte is 1 million bytes and a gigabyte is 1 billion bytes. Networking
measurements are an exception to this general rule; they are given in bits
(because networks move data a bit at a time).

Operating System 1.14


Storage Hierarchy

▪ Storage systems organized in hierarchy


• Speed
• Cost
• Volatility
▪ Caching – copying information into faster storage system;
• main memory can be viewed as a cache for secondary storage

Operating System 1.15


Storage-Device Hierarchy

Operating System 1.16


Characteristics of Various Types of Storage (OPTIONAL)

Movement between levels of storage hierarchy can be explicit or implicit

Operating System 1.17


Direct Memory Access Structure
▪ Think of Direct Memory Access (DMA) as a way to make data transfer
faster and smarter by skipping the CPU for most of the work.
▪ Normal I/O:
In regular data transfer, the CPU handles every little step, like moving
each byte of data between the device and memory. This takes a lot of time
and effort for the CPU.
• the CPU gets interrupted for every byte of data transferred.
▪ DMA:
With DMA, the device controller (a helper for the hardware) can directly
move large chunks of data from the device (like a hard drive) to the
computer's memory without involving the CPU.
• With DMA, the CPU is interrupted only once per block of data,
saving time and reducing workload.

Analogy Imagine you want to fill a bucket with water:


Without DMA: The CPU fills the bucket one cup at a time (slow and
exhausting).
With DMA: A hose (device controller) fills the bucket all at once, and the
CPU only checks when it's done!
Operating System 1.18
How a Modern Computer Works

A von Neumann architecture

Operating System 1.19


Operating-System Operations

Operating System 1.20


Multiprogramming (Batch system)

▪ Multiprogramming is a way to make computers handling many tasks at once

instead of waiting for one to finish completely.

▪ A single user or task (like printing a file) cannot always keep the CPU and devices

(like a printer or hard drive) busy.

▪ Multiprogramming keeps multiple tasks (jobs) ready so the CPU always has

something to do.

Operating System 1.21


Memory Layout for Multiprogrammed System

Operating System 1.22


Multitasking (Timesharing)

▪ Multitasking is a logical extension of Multiprogramming– the CPU quickly


switches between tasks so fast that it feels like everything is happening at the
same time. This allows multiple users or programs to interact with the computer
while it's running.
▪ Unlike older systems where you had to wait for one job to finish, multitasking allows
users to interact with their programs while they are running.
• Response time should be < 1 second
• Each user has at least one program executing in memory  process
• If several jobs ready to run at the same time  CPU scheduling
• If processes don’t fit in memory, swapping (temporarily moves some tasks
to the disk) moves them in and out to run

▪ Note: Both multiprogramming and multitasking can execute more than one jobs,
but a specific time is allotted to every process in multitasking that causes other
process to wait while one is being executed. This is referred to as time sharing
system. In both of the processes, the waiting time and response time is reduced to
a great extent.

Operating System 1.23


Dual-mode Operation
▪ Dual mode is a feature in computer systems that provides two distinct
operating modes:
• User Mode: For running user applications with restricted access to
system resources.
• Kernel Mode: For the operating system, where it has full access to
hardware and system resources.
▪ Mode bit provided by hardware
• Provides ability to distinguish when system is running user code or
kernel code.
• When a user is running  mode bit is “user”
• When kernel code is executing  mode bit is “kernel”
▪ How do we guarantee that user does not explicitly set the mode bit to
“kernel”?
• System call changes mode to kernel, return from call resets it to user
▪ Some instructions designated as privileged, only executable in kernel
mode

Operating System 1.24


Transition from User to Kernel Mode

Operating System 1.25


Timer
▪ A timer is a mechanism used by the operating system to maintain
control over processes and ensure fairness in resource usage.
▪ Purpose of a Timer:
• Prevent Infinite Loops: Stops a program from running endlessly
and hogging the CPU.
• Resource Management: Ensures no single process uses more
time than allowed.
▪ How It Works:
• Timer Setup: The operating system sets a timer before scheduling
a process. This is done using a privileged instruction, meaning only
the OS can set the timer.
• Decrementing Counter: The timer has a counter that is
decremented by the computer’s physical clock.
• Interrupt on Timeout: When the counter reaches zero, the timer
generates an interrupt. The interrupt gives control back to the OS.
• Action by OS: The OS either: Stops or reschedules the process
that exceeded its time limit. Terminates it if necessary.
Operating System 1.26
Process Management
▪ A process is a program in execution. It is a unit of work within the
system. Program is a passive entity; process is an active entity.
▪ Process needs resources to accomplish its task
• CPU, memory, I/O, files
• Initialization data
▪ Process termination requires reclaim of any reusable resources

▪ Typically, system has many processes, some user, some operating


system running concurrently on one or more CPUs

Operating System 1.27


Process Management Activities

The operating system is responsible for the following activities in


connection with process management:
▪ Creating and deleting both user and system processes
▪ Suspending and resuming processes
▪ Providing mechanisms for process synchronization
▪ Providing mechanisms for process communication
▪ Providing mechanisms for deadlock handling

Operating System 1.28


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

Operating System 1.29


File-system 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

Operating System 1.30


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
• Mounting and unmounting
• Free-space management
• Storage allocation
• Disk scheduling
• Partitioning
• Protection

Operating System 1.31


Virtualization

▪ Virtualization:
• Allows multiple operating systems (OSes) to run on the same hardware
simultaneously.
• Example: Running Windows XP inside Windows 10 using VMware.
▪ Emulation:
• Used when the source CPU type (e.g., PowerPC) is different from the
target CPU type (e.g., Intel x86).
• Converts instructions from one CPU type to another but is generally
slower.
▪ How Virtualization Works:
• The host OS runs a Virtual Machine Manager (VMM), which provides
virtualization services.
• The VMM creates virtual machines (VMs) that allow guest OSes to
run as if they have their own hardware.
• Both the host OS and guest OSes are natively compiled for the same
CPU.
Operating System 1.32
Computing Environments - Virtualization

Operating System 1.33


DEFINITIONS OF COMPUTER SYSTEM COMPONENTS

Core

Operating System 1.34


Computer-System Architecture

▪ Most systems use a single general-purpose processor


• Most systems have special-purpose processors as well
• Used a single processor containing one CPU with a single processing
core
▪ Multiprocessors systems growing in use and importance
• Also known as parallel systems, tightly-coupled systems
• Advantages include:
1. Increased throughput
2. Economy of scale
3. Increased reliability – graceful degradation or fault tolerance
• Two types:
1. Asymmetric Multiprocessing – each processor is assigned a
specific task.
2. Symmetric Multiprocessing – each processor performs all tasks

Operating System 1.35


Symmetric Multiprocessing Architecture

Operating System 1.36


Dual-Core Design
▪ Multi-chip and multicore
▪ Systems containing all chips
• Chassis containing multiple separate systems

Operating System 1.37


Clustered Systems

▪ Like multiprocessor systems, but multiple systems working together


• Usually sharing storage via a storage-area network (SAN)
• Provides a high-availability service which survives failures
• Some clusters are for high-performance computing (HPC)
 Applications must be written to use parallelization

Operating System 1.38


System Calls
▪ The OS provides many services, like managing files, running programs,
and controlling hardware. Programs need a way to talk to the OS to use
these services. This is done through a Application Programming
Interface (API).
▪ Typically written in a high-level language (C or C++)
▪ An API is like a translator between a program and the OS.
▪ Programs use the API to request services from the OS, without worrying
about low-level system details.
▪ When a program uses an API, the API translates its request into system
calls, which communicate directly with the OS.
▪ Example:
▪ Imagine you want to save a file in a program:
• The program uses an API to ask the OS to save the file.
• The API translates the request into a system call.
• The OS handles the file-saving operation and returns a success
message.

Operating System 1.39


Example of System Calls

▪ System call sequence to copy the contents of one file to another file
• cp in.txt out.txt

Operating System 1.40


Example of Standard API

Operating System 1.41


System Call Implementation
▪ A system call is how a program asks the operating system (OS) to
perform a specific task, like reading a file or accessing hardware. The
system call interface manages this process.
▪ Each system call is given a unique number and, these numbers are
used to identify the system call in the OS.
▪ The OS keeps a table where each number points to the function that
performs the system call in the OS kernel.
▪ Process Flow:
• A program makes a request using the API.
• The system call interface matches the request to the right system
call using the table.
• The system call runs in the kernel, does the requested task, and
sends back the result (status or data).
▪ The programmer doesn’t need to know how the system call works
inside the OS
• For example, in C language you should not care how scanf or
read invoke the system call.
Operating System 1.42
API – System Call – OS Relationship

Operating System 1.43


Types of System Calls

▪ Process control
• create process, terminate process
• end, abort
• load, execute
• get process attributes, set process attributes
• wait for time
• wait event, signal event
• allocate and free memory
• Dump memory if error
• Debugger for determining bugs, single step execution
• Locks for managing access to shared data between processes

Operating System 1.44


Types of System Calls (Cont.)

▪ File management
• create file, delete file
• open, close file
• read, write, reposition
• get and set file attributes
▪ Device management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices

Operating System 1.45


Types of System Calls (Cont.)

▪ Information maintenance
• get time or date, set time or date
• get system data, set system data
• get and set process, file, or device attributes
▪ Communications
• create, delete communication connection
• send, receive messages if message passing model to host
name or process name
 From client to server
• Shared-memory model create and gain access to memory
regions
• transfer status information
• attach and detach remote devices

Operating System 1.46


Types of System Calls (Cont.)

▪ Protection
• Control access to resources
• Get and set permissions
• Allow and deny user access

Operating System 1.47


Examples of Windows and Unix System Calls

Operating System 1.48


Standard C Library Example
▪ C program invoking printf() library call, which calls write() system call

Operating System 1.49


Why Applications are Operating System Specific

▪ Apps compiled on one system usually not executable on other operating


systems
▪ Each operating system provides its own unique system calls
• Own file formats, etc.
▪ Apps can be multi-operating system
• Written in interpreted language like Python, Ruby, and interpreter
available on multiple operating systems
• App written in language that includes a VM containing the running app
(like Java)
• Use standard language (like C), compile separately on each operating
system to run on each
▪ Application Binary Interface (ABI) is architecture equivalent of API,
defines how different components of binary code can interface for a given
operating system on a given architecture, CPU, etc.

Operating System 1.50

You might also like