You are on page 1of 37

Lecture 5: Operating System

Layer
IT064IU - Introduction to Computing
SUMMER 2021
Instructor: Le Duy Tan, PhD
Email: ldtan@hcmiu.edu.vn 1
1. Operating system
Software
clasification

This figure is from “CS: An overview”.


Roles of an Operating System
v Application software: Programs that help us
solve real-world problems. Give some
examples?
v System software: Programs that manage a
computer system and interact with Hardware.
E.g., ...
v Operating system: System software that
manages computer resources and provides an
interface for system interaction
Operating System Components
vUser Interface: Communicates with
users
qText based (Shell), e.g. Bourne
shell, Bash shell, C shell, and
Korn shell
qGraphical user interface (GUI),
e.g. GNOME, KDE , Unity, etc.
vKernel: Performs basic functions
q File manager
q Device drivers
q Memory manager
q Scheduler and dispatcher
5
This slide is from “CS: An overview”.
In the startup sequence
vThe CPU starts and fetches instructions into RAM from the BIOS, which is
stored in the ROM.
vThe BIOS starts the monitor and keyboard and does some basic checks to
make sure the computer is working properly. For example, it will look for
the RAM.
vThe BIOS then starts the boot sequence. It will look for the operating
system.
vIf you don’t change any of the settings, the BIOS will fetch the operating
system from the hard drive and load it into the RAM.
vThe BIOS then transfers control to the operating system.

6
General Picture
Memory, Process, and CPU Management
vMultiprogramming The technique of keeping multiple programs in main
memory at the same time, competing for the CPU
vMemory management The act of keeping track of how and where programs are
loaded in main memory.
vProcess The dynamic representation of a program during execution
vProcess management The act of keeping track of information for active
processes
vCPU scheduling The act of determining which process in memory is given
access to the CPU so that it may execute
Batch Processing
In mordern computing system:
v.bat in Microsoft Windows
vShell script in linux
need the same or similar resources
pu
nc
he
dc
ard
s

A punched cards In early systems, human operators would organize jobs into batches
2. Memory Management
vPhysical address An actual address in the main
memory device
vLogical address: A reference to a stored value
relative to the program making the reference
vAddress binding The mapping from a logical
address to a physical address

Physical address
Memory management

Single contiguous MM Partition MM Paged MM


Single Contiguous Memory Management
(1/2)
v The entire application program is loaded into one
continuous area of memory
v Only one program other than the operating system can
be processed at one time
v A logical address is simply an integer value relative to
the starting point of the program as if the program loaded
at location 0 of main memory.
v To produce a physical address, we add a logical address
to the starting address of the program in physical main
memory
v Simple but not multiprocessing
Single Contiguous Memory Management
(2/2)
v If the program is loaded starting at address A,
then the physical address corresponding to
logical address L is A + L
v Ex: Suppose the program is loaded into
memory beginning at address A = 555555.
When a program uses relative address
L = 222222, we know that it is actually
referring to address A+ L = 777777 in physical
main memory
v Simple to implement and manage but waste
both memory space and CPU time
Partition Memory Management (1/2)
More than one application program in memory at the
same time, sharing memory space and CPU time
vFixed-partition technique: The memory management
technique in which memory is divided into a specific
number of partitions into which programs are loaded.
vDynamic-partition technique: The memory
management technique in which memory is divided into
partitions as needed to accommodate programs.
vBase register A register that holds the beginning
address of the current partition
vBounds register A register that holds the length of the
current partition
Partition Memory Management (2/2)
Three general approaches to partition selection:
v First fit, in which the program is allocated to the first
partition big enough to hold it
v Best fit, in which the program is allocated to the
smallest partition big enough to hold it
v Worst fit, in which the program is allocated to the
largest partition big enough to hold it
Makes efficient use of main memory by maintaining
several programs in memory at one time
Paged Memory Management (1/2)
vPaged memory technique: A memory management
technique in which processes are divided into fixed-size
pages and stored in memory frames when loaded
vFrame: A fixed-size portion of main memory that holds a
process page
vPage: A fixed-size portion of a process that is stored into a
memory frame
vPage-map table (PMT): The table used by the operating
system to keep track of page/frame relationships
Paged Memory Management (2/2)

A logical address: <1, 222>


<page, offset>
Ex: <1, 222>
Page 1 of process 1 is in frame 12
A page size of 1024 (assumption)
Therefore, the corresponding physical address
12 * 1024 + 222 = 12510
Process Management
Process states The conceptual stages through which a process
moves as it is managed by the operating system

The process life cycle


Process management - Process states
vIn the new state, a process is being created.
vA process that has no barriers to its execution
is in the ready state.
vA process in the running state is currently
being executed by the CPU. Its instructions
are being processed in the fetch–execute
cycle.
vA process in the waiting state is currently
waiting for resources (other than the CPU).
vA process in the terminated state has
completed its execution and is no longer
active.
CPU Scheduling
vCPU scheduling is the act of determining
which process in the ready state should be
moved to the running state.
vNon-preemptive scheduling CPU
scheduling that occurs when the currently
executing process gives up the CPU
voluntarily
vPreemptive scheduling CPU scheduling that
occurs when the operating system decides to
favor another process, preempting the
currently executing process
CPU Scheduling
First Come, First Served (FCFS): non-preemptive
Processes are moved to the CPU in the order in which
they arrive in the running state

The average turnaround time:


(140 + 215 + 535 + 815 + 940) / 5 = 529
Easy to implement but suffers from its lack of attention to important factors
such as service time requirements
CPU Scheduling
Shortest Job Next (SJN) or Shortest job first (SJF) : non-
preemptive
Looks at all processes in the ready state and dispatches the
one with the smallest service time

The average turnaround time:


(75 + 200 + 340 + 620 + 940) / 5 = 435
SJN algorithm relies on knowledge of the future which is essentially impossible to
determine
CPU Scheduling
Round Robin: preemptive
Distribute the processing time equitably among all ready
processes
Time slice: The amount of time given to each process in
the round-robin CPU- scheduling algorithm

The average turnaround time:


(515 + 325 + 940 + 920 + 640) / 5 = 668
Most widely used - supports all kinds of jobs and is considered the most fair
Quiz 1
If, in a single contiguous memory management system, the
program is loaded at address 30215, compute the physical
addresses (in decimal) that correspond to the following logical
addresses:
a. 9223
b. 2302
c. 7044
Quiz 2
If the partitions are fixed and a new
job arrives requiring 52 blocks of
main memory, show memory after
using each of the following partition
selection approaches:
a) First fit
b)Best fit
c) Worst fit
Quiz 3
If the frame size is 1024, what is the physical address associated with
the logical address <2, 85>?
Quiz 4
Draw a Gantt chart that shows the completion times for each process
and calculate the turnaround time using
a) first-come, first-served CPU scheduling
b) shortest-job-next CPU scheduling
c) round-robin CPU scheduling with a time slice of 20

Process P1 P2 P3 P4
Service time 60 30 90 25
2. File system directory
File Systems
vFile A named collection of data,
used for organizing secondary
memory.
vFile system The operating
system’s logical view of the files
it manages.
vDirectory A named group of
files.
File Operations
vCreate a file
vDelete a file
vOpen a file create / delete /
vClose a file open / close / write
vRead data from a file data / append data
vWrite data to a file ... to a file in Python
vReposition the current file pointer in a file
vAppend data to the end of a file
vTruncate a file (delete its contents)
vRename a file
vCopy a file
File protection
Directory Trees
vDirectory tree A structure showing the nested directory organization
of the file system
vRoot directory The topmost directory, in which all others are
contained
vPath Names:

absolute relative
slash A Unix directory tree backslash A Windows directory tree
Quiz
1. Windows:
Show the absolute
path to each of the
following files or
directories:
a) QTEffects.qtx
b) brooks.mp3
c) 3dMaze.scr
d) Powerpnt.exe
Quiz
2. Unix (Linux):
Show the absolute
path to each of the
following files or
directories:
a) tar
b) access.old
c) named.conf
d) smith
e) week3.txt
f) printall
Quiz
3. Windows:
Assuming the current
working directory is
C:\WINDOWS\System, give
the relative path name to the
following files or directories
a) QTImage.qtx
b) calc.exe
c) letters
d) proj3.java
e) adobep4.hlp
f) WinWord.exe
Summary
vAn operating system is the part of the system software that manages
resources on a computer.
vMultiprogramming is the technique for keeping multiple programs in
memory at the same time, contending for time on the CPU.
vBatch processing organizes jobs into batches that use the same or similar
resources.
vAn operating system must manage memory to control and monitor where
processes are loaded into main memory.
vCPU scheduling algorithms determine which process gets priority to use
vthe CPU next.
vA file system defines the way our secondary memory is organized.
vDirectories are used to organize files on disk.

You might also like