Lecture No. 03
Dated: 24-04-2025
Memory Protection
Process Address Space
The area of memory which a process
is allowed to access is called process address space
.
A process
must not be able to access memory outside of this space otherwise it can corrupt memory of other processes
and even operating system
.1
There are 2 registers
used to provide memory protection
.
Base Register
It holds the smallest legal physical memory address
for a process
.
Limit Register
It contains the size of the process
.
Hardware address protection with base and limit registers
\(\text{address} \in [64, 64 + 128]\)
CPU
Protection
We use a timer
which interrupts the CPU
to make sure that the user doesn't get stuck in an infinite loop and control remains in operating system
1's hands.
The timer
period can be fixed or variable.
A variable timer
can be made by using a fixed rate clock
and a counter
.
The operating system
1 sets the counter
to some positive number \(N\) called the time slice
which decrements over time with each clock
impulse, using the clock interrupt service routine
.
After the counter
reaches \(0\), a timer interrupt
is generated, operating system
1 is invoked and control is transferred back to the CPU
while it performs house keeping tasks.
Load-Timer
is a privileged instruction
.
OS
1 Components
Process Management
A process
can be though of a program
in execution.
It needs certain resources to perform its task such as
- CPU time
- Memory
- Files
- I/O devices
The operating system
1 is responsible for
- Creating and terminating both
user
andsystem processes
- Suspending and resuming
processes
- Providing mechanisms for
- process synchronization
- process communication
- deadlock handling
Main Memory Management
Main memory
is an array (a repository) of bytes
, each with their own address
which hold quickly accessible data by CPU
and I/O
devices.
It contains the code
, data
, stack
and other parts of a process
.
The CPU
reads instruction during its machine cycle
- Fetch
- Decode
- Execute
The operating system
1 is responsible for following activities in connection with memory management.
- Keeping track of free
memory space
- Keeping track of which parts of
memory
are currently being used and by whom - Deciding which
processes
are to be loaded intomemory
whenmemory space
becomes available - Deciding how much
memory
is to be allocated to aprocess
- Allocating and deallocating
memory space
as needed - Ensuring that a
process
is not overwritten on top of another
Secondary Storage Management
The programs alongside with the data they process, have to be loaded into the main memory
or primary storage
.
The computer system must provide a secondary storage
for source and destination of programs and their data as the main memory
is temporary.
The operating system
1 does the following in this context
- Free space management
- Storage allocation and deallocation
- Disk scheduling
I/O System Management
The I/O
system consists of
- A
memory management
component that includesbuffering
caching
spooling
- A general
device driver
interface Drivers
forspecific hardware devices
File Management
Computers can store information on several types of physical media, such as
- Magnetic tape
- Magnetic disk
- Optical disk
The operating system
1 maps these files onto the physical media
and accesses these media via the storage devices
.
The OS
1 is responsible for the following activities with respect to file management
- Creating and deleting files
- Creating and deleting directories
- Supporting primitives (operations) for manipulating files and directories
- Mapping files onto the secondary storage
- Backing up files on stable (nonvolatile) storage media
Protection System
There can be multiple users
and processes
running at the same time and the resources must be protected from each other's activities to prevent loss.
Networking
A distributed system
is a collection of processors
that do not share memory
, peripheral devices
or a clock
.
Instead each processor
has its own local memory
and clock
and the processors
communicate with each other through various communication lines such as high speed buses or networks.
A distributed system
collects physically separate and possibly heterogeneous systems, into a single coherent system providing the user with access to the various resources that system maintains.
Command line Interpreter (shells)
It is an interface between the users
and the operating system
.1
Some operating systems
1 provide the interpreter
in the kernel
.
Other operating systems like Linux
, Unix
and DOS
treat it like a special program.
It is also known as shell
sometimes.
There are some examples
- Bourne shell (
sh
) - C shell (
csh
) - Bourne Again shell (
bash
) - TC shell (
tcsh
) - Korn shell (
ksh
)
Operating System Services
Program Execution
The system must be able to do the following in regards to programs
- Load
- Execute
- Terminate
I/O Operations
A running program
may require a file
or an I/O
device.
For efficiency and protective reasons, users
usually cannot directly access the I/O
devices and need the middle man, that is operating system
.1
File System Manipulation
Programs
should be able to do the following operations on files
.
- Create
- Modify
- Delete
Communications
There can be communication between processes
through shared memory
or message passing
.
Error Detection
Errors can occur in any part of the system and operating system
1 should be able to know where the error has occurred and how to respond to them.
In order to assist the efficient operation of the system itself, the system provides the following functions
Resource Allocation
When multiple users
and jobs
are running on the system, resources must be allocated to each of them.
Accounting
We can keep track of which user
accesses certain resources to later generate statistics.
Protection
When multiple users
and processes
are executing, the resources must be protected from corruption by each other.
Entry point into Kernel
There are 4 events that cause execution of a piece of code in the kernel
.
These events are
- Interrupt
- Trap
- System call
- Signal
System Calls
These provide an interface between the process
and the operating system
.1 These calls are generally available as assembly language instructions
.
The interface to system calls
is the entry point of kernel code
which is not usually and easily provided to the user
for security reasons.
These are categorized into following groups
- Process Control
- File Management
- Device Management
- Information maintenance
- Communications
Semantics of System Call Execution
Following sequence of events take place when a user
invokes a system call
.
- The
user process
makes a call to alibrary function
. - The
library routine
puts the appropriateparameters
on a well known place such asregisters
or on thestack
. Theseparameters
include arguments for thesystem call
,return address
andcall number
. There are 3 general methods used to pass parameters between a runningprogram
and theoperating system
.- Pass
parameters
inregisters
- Store the
parameters
in a table which is stored on themain memory
and the tableaddress
is passed as aparameter
in aregister
. - Push the
parameters
onto thestack
by the program and pop off thestack
byoperating system
.1
- Pass
- A
trap
instruction is executed to change mode fromuser
tokernel
and give control tooperating system
.1 - The
operating system
1 then determines whichsystem call
is to be carried out by examining one of theparameters
(the call number) passed to it bylibrary routine
. - The
kernel
uses call number to index akernel table
(thedispatch table
) which contains pointers toservice routines
for allsystem calls
. - The
service routine
is executed and control given back touser program
via return fromtrap instruction
the instruction also changes mode fromsystem
touser
. - The
library function
executes the instruction followingtrap
interprets the return values from thekernel
and returns to the userprocess
.
Pictorial view of the steps needed for execution of a system call
Operating Systems Structures
Logical structure of DOS
Logical structure of UNIX