Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 38

OPERATING SYSTEM LEC

System Call

Provides the interface between a process and the OS

It is an instruction that generates an interrupt that causes OS to gain control


of processor.

Process request action by OS.

System Calls

Interface between running


program and the OS.

Assembly language instructions


(macros and subroutines)
Some higher level languages
allow system calls to be made
directly (e.g. C)

Passing parameters between a


running program and OS via
registers, memory tables or
stack.

Unix has about 32 system calls

read(), write(), open(), close(),


fork(), exec(), ioctl(),..

Types of System Calls

Process control- end/abort, load/execute, create/terminate, wait for event


File management- create, delete, open close, get file attributes
Device management- request, release, read, write, get/set device
attributes, attach, detach.
Info maintenance- time, date
Communication-open connection, close connection

Major components

Process management
Memory management
I/O
Secondary Storage
File System
Protection
Accounting
Shell (OS UI)
GUI
Networking

Process Management

A process is a program in execution.

A process needs certain resources such as CPU, memory ,


files and I/O.

These resources are given when a process is created

When the process terminates, OS reclaims the resources

Program- passive

Process-active

At most one instruction is executed on behalf of a process

Processes

Scheduler Maintains a record


of the processes.

Adds new processes when


launched.

Removes old processes when


completed.

Uses a process table.

Process Table Information


about each process including:

Main memory cells (RAM)

Priority

Running or waiting (input


from user or saving to disk)

Rick Graziani
graziani@cabrillo.edu

Viewing processes with Microsoft Windows

Task Bar Right-click, Task Manager

Ending a process Killing the process


8

Rick Graziani
graziani@cabrillo.edu

Processes

Dispatcher - Oversees the


execution of each process by the
CPU.

Gives each process a time slice of


CPU time.

Changes between processes.

Rick Graziani
graziani@cabrillo.edu

Process management

The OS is responsible for

Create user/ system processes


Deleting user/system processes
Allocating hardware resources to a process.
Process communication
Deadlock handling
Suspend a process
Resume a process
Clone a process
Inter-process communication
Inter-process synchronization
Create / delete a child process

Memory Management

Concerned with the management of primary memory

Which part s being used

Which processes are to be loaded

Allocation techniques

De-allocation techniques

File Management

A file is a logical collection of information

OS provides a logical view

OS create, deletes files

OS maps files onto secondary storage

Creating/deleting directories.

Backing up files

Secondary storage Management

OS is responsible for :

free space management

Storage allocation

Disk scheduling

I/O Management

I/O controller keeps track of the status of the devices


Buffering, caching, spooling
Device driver interface
Drivers- Device drivers are the routines that interact with specific

device types:

Encapsulates device specific knowledge

E.g. how to initialize a device, how to request the I/O,

how to handle interrupts and errors

E.g. SCSI device drivers, Ethernet card drivers,

video card drivers, sound card drivers

I/O Structure

Synchronous I/O
wait

instruction idles CPU until next interrupt

no

simultaneous I/O processing, at most one outstanding


I/O request at a time.

Asynchronous I/O

After I/O is initiated, control returns to user program


without waiting for I/O completion.

Networking
An OS typically has a built-in communication infrastructure that
implements:
A network protocol software stack
A route lookup module to map a given destination
address to a next hop.
A name lookup service to map a given name to a
destination machine.

Command interpreter (shell)


A particular program that handles the
interpretation of users

commands and helps to manage processes

On some systems, command interpreter may


be a standard part of the OS

On others, its just not privileged code that


provides an interface to the user

On others there may be no command language

Accounting
Keeps
Both

track of resource usage

to enforce quotas youre


over the disk limit.

Protection

Processor protection

Protection mechanisms are implement in OS to support security policies.

The goal of security system is to authenticate and authorize.

Hardware Protection

Dual Mode Operation

I/O Protection

Memory Protection

CPU Protection

Dual Mode

Gives protection or shared resources


User mode, privileged mode
A mode bit is added to the hardware to indicate the mode
With the mode bit it is possible to distinguish between the modes.
On booting user process starts in user mode.
If an attempt is made to execute a privileged instruction in user mode the
hardware traps it to the OS.

Dual-mode operation(cont.)
User

Mode bit added to computer


hardware to indicate the
current mode: monitor(0) or
user(1).
When an interrupt or fault
occurs, hardware switches to
monitor mode.
Privileged instructions only in
monitor mode.

Interrupt/
fault

Set
user
mode

Monitor

Dual-mode operation

Sharing system resources requires operating system


to ensure that an incorrect program cannot cause
other programs to execute incorrectly.

Provide hardware support to differentiate between


at least two modes of operation:
1. User mode -- execution done on behalf of a user.
2. Monitor mode (supervisor/kernel/system mode) -execution done on behalf of operating system.

I/O Protection

All I/O instructions are privileged instructions.

Must ensure that a user program could never gain


control of the computer in monitor mode, for e.g. a
user program that as part of its execution, stores a
new address in the interrupt vector.

Memory Protection
0

Must provide memory protection


at least for the interrupt vector
and the interrupt service
routines.
To provide memory protection,
add two registers that determine
the range of legal addresses a
program may address.

Base Register - holds smallest


legal physical memory address.
Limit register - contains the size
of the range.

Memory outside the defined


range is protected.

When executing in monitor mode,


the OS has unrestricted access to
both monitor and users memory.

256000

monitor
Job1
Base register
300040

3000040
Job 2
420940

120900
Job 3

880000
Job 4
1024000

Limit register

CPU Protection

Timer - interrupts computer after specified period to


ensure that OS maintains control.

Timer is decremented every clock tick.

When timer reaches a value of 0, an interrupt occurs.

Timer is commonly used to implement time sharing.

Timer is also used to compute the current time.

Load timer is a privileged instruction.

Operating Systems: How are they organized?

Simple

Layered

Lower levels independent of upper levels

Microkernel

Only one or two levels of code

OS built from many user-level processes

Modular

Core kernel with Dynamically loadable modules

OS structure

Its not always clear how to stitch OS modules


together:
Command Interpreter
Information Services
Error Handling

File System

Accounting System

Protection System

Process Management

Memory
Management

Secondary Storage
Management
I/O System

Early structure: Monolithic

Traditionally, OSs (like UNIX, DOS) were built as a


monolithic entity:

user programs

OS

everything

hardware

Monolithic Design

Major Advantages:

Cost of module interaction is low

Disadvantages

Hard to understand

Hard to modify

Unreliable

Hard to maintain

Monolithic Design

Major Advantages:

Cost of module interaction is low

Disadvantages

Hard to understand

Hard to modify

Unreliable

Hard to maintain

Design

Top down approach overall functionality is separated into components.

Layered approach each layer uses services of lower layers. Needs careful
definition of each layer. Layer N is user, Layer 0 is hardware.

Layered OS Structure

OS divided into number of


layers - bottom layer is
hardware, highest layer is
the user interface.

Each layer uses functions


and services of only lowerlevel layers.

THE Operating System


Kernel has successive layers
of abstraction.

Layered Operating System

Modules-based Structure

Most modern operating systems implement 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

OPERATING SYSTEM
OVERVIEW

Characteristics

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.
Incoming interrupts are disabled while another interrupt is being
processed to prevent a lost interrupt.
A trap is a software-generated interrupt caused either by an error
or a user request.
An operating system is interrupt driven.

36

OPERATING SYSTEM
OVERVIEW

Storage
Hierarchy

Very fast storage is very expensive. So the Operating System manages a hierarchy of
storage devices in order to make the best use of resources. In fact, considerable effort
goes into this support.

Fast and Expensive

Slow an Cheap
37

Virtual Machines

Logically treats hardware


and OS kernel as
hardware

Provides interface
identical to underlying
bare hardware.

Creates illusion of
multiple processes - each
with its own processor
and virtual memory

processes
processes
processes

kernel kernel kernel


Virtual machine
hardware

You might also like