Introduction to Operating System - Lecture 2

1mohamedgamal54 37 views 87 slides Sep 18, 2024
Slide 1
Slide 1 of 87
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87

About This Presentation

Introduction to the Operating System where we cover the basics.


Slide Content

By Mohamed Gamal
Lecture 2: Computer
System Structure
Operating System

–What’s an Operating System (OS)?
–What’re the three well-known OSes existing today?
–What’re the main basic operations of the computer?
–What’re the main computer system components?
Test your knowledge ?

–What’s the difference between multiprocessing and
multiprogramming?
–What’s the difference between Application Programs and
System Programs?
–What’s the difference between LAN and WAN?
–Explain Grid Systems concept and its derivatives.
–CMD Revision.
Test your knowledge ?

The topics of today’s lecture:
Agenda

–Computer system consists of
•CPU
•Device controllers
•Common bus
•Shared memory
–CPU and device controllers execute concurrently.
–Memory controller synchronizes access to memory.
Computer System Operation

–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
Computer System Operation

–An interrupt is a signal sent to the CPU
–Interrupt transfers control to the interrupt service routine
generally, through the interrupt vector, which contains the
addresses of all the service routines.
–Interrupt types:
•Hardware Interrupts (polling/vectored)
•Software Interrupts: system calls (trap/exception)
Interrupts

–A trap is a software generated interrupt caused by:
•Error: division by zero or invalid memory access
•Request: from a user program to O/S
–An operating system is interrupt driven.
Interrupts (Cont.)

1)CPU is interrupted
2)CPU stops current process
3)CPU transfers execution to a fixed location ‘registers + Program Counter’
4)CPU executes interrupt service routine
5)CPU resumes process
–Notes:
•Interrupts must be handled quickly
•Interrupted process information must be stored
Interrupt Handling

1)Power up
2)Initial program: bootstrap (firmware)
–Stored in ROM or EPROM
–Initialize:
1)CPU registers
2)Device controllers
3)Memory contents
4)Load the operating system (kernel)
3)Kernel starts the first process – init
4)Init waits for an event (interrupt) to occur
Computer System Startup
Power-On Self-Test
BIOS: basic input/output system

–Controllers:
•Are in charge of a specific type of device
•Moves data between device and local buffer
•A controller may have more than one device
•Buffer size varies
–Two types (Synchronous + Asynchronous):
•Type 1: After I/O starts, control returns to user program only upon I/O
completion.
•Type 2: After I/O starts, control returns to user program without waiting
for I/O completion.
I/O Structure

–Used for high-speed I/O devices able to transmit information at
close to memory speeds.
–Device controller transfers blocks of data from buffer storage
directly to main memory without CPU intervention.
–Only one interrupt is generated per block, rather than the one
interrupt per byte.
Direct Memory Access (DMA) Structure
Old Structure: I/O → CPU → Memory
Modern Structure: I/O → Memory

Direct Memory Access (DMA) Structure
A von Neumann architecture
Modern Computer

–The basic unit of computer storage is the bit.
–Computer Storage:
•A byte is 8 bits
•A kilobyte (KB) is 1,024
1
(2
10
) bytes
•A megabyte (MB) is 1,024
2
(2
20
) bytes
•A gigabyte (GB) is 1,024
3
(2
30
) bytes
•A terabyte (TB) is 1,024
4
(2
40
) bytes
•A petabyte (PB) is 1,024
5
(2
50
) bytes
–Given enough bits a computer can represent:
•numbers, letters, images, sounds, documents … etc.
Storage Definitions and Notation Review
01000001
Character ‘A’

Storage Definitions and Notation Review (Cont.)
Memory Unit Description
Bit 0 or 1
Byte 8 bits
KiloByte (KB) 1024 Bytes
MegaByte (MB) 1024 KB
GigaByte (GB) 1024 MB
TeraByte (TB) 1024 GB
PetaByte (PB) 1024 TB
HexaByte or exaByte (EB) 1024 PB
ZettaByte (ZB) 1024 EB
YottaByte (YB) 1024 ZB
BrontoByte 1024 YB
GeopByte 1024 Bronto Bytes

00000000000000000000000000000000000000011111111111111111111111111111111100000111111111111100000000000
00
00000000000000000000000000000000000000011111111111111111111111111101110000000000111111111000000000000
00
00000000000000000000000000000000000000011111111111111111111111111111111000000000001111111000000000000
00
00000000000000000000000000000000000000111111111111111111111111111111110000000000001111111000000000000
00
00000000000000000000000000000000000000111111111111111111111111111111000000000000001111111000000000000
00
00000000000000000000000000000000000000111111111111111111111111111111110000000000001111111000000000000
00
00000000000000000000000000000000000000111111111111111111111111111111111111110000001111110000000000000
00
00000000000000000000000000000000000000111111111111111111111111110111111111111110000111100000000000000
00
00000000000000000000000000000000000000011111111111111111111111110001111111111111000111100000000000000
00
00000000000000000000000000000000000000011111111111111111111111110000111111111100000111000000000000000
00
00000000000000000000000000000000000011111000011111111111111111100000000000000000000111000000000000000
00
00000000000000000000000000000000000011111000111111111111111111100000000000000000000000100000000000000
00
00000000000000000000000000000000000011111111111111111111111111111100000000000000000000010000000000000
00
00000000000000000000000000000000000001111111111111111111111111111110000000000000000110000000000000000
00

–Punched Card
•Early method of data storage used with early computers
•Containing several punched holes that represents data
Early Data Storage

–Main memory - RAM (volatile)
•Only large storage media that the CPU can access directly.
–Secondary storage (non-volatile)
•Extension of main memory that provides large nonvolatile storage capacity.
–Tertiary Storage
Storage Structure (Cont.)

–Array of memory words
–Each byte has an address
–Memory Address:
•Physical
•Logical
–CPU Instructions:
•Load: moves a word from main memory to CPU register
•Store: move a word from CPU register to main memory
Random Access Memory (RAM)

–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.
Magnetic Disk (Hard Disk Drive – HDD)

First Hard Disk Drive (HDD)
•IBM RAMDAC computer – 1956
•Solid-state drives (SSD) now

–Early secondary storage
–Slow access time
–Usage
•Backup
•Storage of infrequently used information
–Examples:
•Magnetic tape
•Optical disc
•Optical tapes
Tertiary Storage

–Information in use copied from slower to faster storage temporarily
–Faster storage (cache) checked first to determine if information is
there
•If it is, information used directly from the cache (fast)
•If not, data copied to cache and used there
–Cache is smaller than storage being cached
–Cache depends on locality (nearest storage to access).
–Multitasking environments depends on caching!
Caching concept

Storage-Device Hierarchy
bytes
MBs
MBs - GBs
GBs - TBs
GBs - TBs
GBs - TBs
GBs - TBs

Performance of Various Levels of Storage

–Mode bit provided by hardware to indicate the current mode
•User mode (bit 0)
•kernel mode (bit 1)
–Provides ability to distinguish when system is running:
•user code (Application Program - 0)
•kernel code (System Program - 1)
Hardware Dual-Mode

–Some instructions designated as privileged, and are only executable
in kernel mode
–System call changes mode to kernel, and the return from call resets
it to user
Hardware Dual-Mode (Cont.)

–All I/O instructions are privileged
–I/O device registers are inaccessible by user
–Users cannot issue I/O instructions directly
–Users must do it through the OS
1) I/O Protection

–Must provide memory protection at least for the interrupt
vector and the interrupt service routines.
–In order to have memory protection:
•add two registers that determine the range of legal addresses a
program may access
✓Base Register: holds the smallest legal physical memory address.
✓Limit Register: contains the size of the range.
•Memory outside the defined range is protected.
2) Memory Protection

2) Memory Protection (Cont.)
OS

2) Memory Protection (Cont.)

3) CPU Protection (Cont.)
–Timers
•interrupts CPU after specified period
–Timer is decremented every clock tick
–Use of timers
•Time sharing systems
✓Interrupt every N milliseconds
✓Switch control to other processes
•Computing current time

File type Extension Function
executable .exe ready to run program
source code .c .cpp .py .java … etc. source code in various languages
Batch .bat .sh Commands to the CMD
Text .txt .doc .docx .pdf .ppt .pptxtextual data and documents
Images .png .jpg .jpeg .svg .webp .gif .heic Viewing format
Audio .mp3 .mp4 .wav .ogg .webm songs and other audio related
Archive .zip .rar compressed files
File Types – Name, Extension

Directory Structure
•A collection of nodes containing information about all files
F 1F 2
F 3
F 4
F n
Directory / Folder
Files
Both the directory structure and the files reside on disk

A Typical File-system Organization
•Windows File System:
✓NTFS (New Technology File System)
•Linux File System:
✓ext4 (Fourth Extended File System)
•macOS File System:
✓APFS (Apple File System)
•Others:
✓FAT32 (File Allocation Table)
✓exFAT (Extended File Allocation Table)
Protection Issue: read, write, execute, append, delete … etc.
directory
files
directory
files
directory
files
disk 1 disk 2
Partition D
Partition C
Partition E

A Typical File-system Organization

Types of viruses

Types of viruses (Cont.)
Type Function
Worms a computer program that replicates itself.
Trojan Horse
a sort of destructive program that remains disguised in a normal software
program.
Ransomware designed to encrypt your files and block access to them until a ransom is paid.
Adware an unwanted software that displays advertisements on your screen.
Spyware
invades your computer and attempts to steal your personal information such
as credit card or banking information, web accounts.

How to protect yourself ?
–Antivirus
•is a program that secures your system from any potential
viruses.
–Firewall
•is a protective shield that keeps bad things away from
your computer.

Operating System Services

–Almost all operating systems have a user interface (UI)
•Command-Line (CLI)
•Graphics User Interface (GUI)
•Batch
1) User Interface

Types of User Interface (UI)

- Provide a programming interface to the services provided by the OS.
- Generally available as assembly-language instructions.
–Typically written in a high-level language (C or C++)
-Mostly accessed by programs via a high-level Application Programming
Interface (API) rather than direct system call use
2) System Calls

System Call Position
User-mode
User-mode
Kernel-mode

System Call Interface (API)

Hierarchy Summary
Library Function
System Call Interface (API)
System Call

- Copy Program Example:
• open (file 1)
• create (file 2)
• read(file 1)
• write (file 2)
• close (file 1)
• close (file 2)
System Call Example
file 1 file 2

–Process Control
–File Management
–Device Management
–Information Maintenance
–Communications
–Protection
Types of Systems Calls

–create process, terminate process
–end, abort
–load, execute
–get process attributes, set process attributes
–wait for time
–wait event, signal event
–allocate & free memory
1) Process Control System Calls

–create file, delete file
–open, close file
–read, write, reposition
–get file attributes, set file attributes
2) File Management System Calls

–request device, release device
–read, write
–get device attributes, set device attributes
–logically attach or detach devices
3) Device Management System Calls

–get time or date, set time or date
–get process, file, or device data/attributes
–Set process, file, or device data/attributes
–get system data, set system data
4) Information Maintenance System Calls

–create, delete communication connection
–send, receive messages
–transfer status information
–attach or detach remote devices
5) Communications System Calls

Communication Models
(a) Shared Memory. (b) Message Passing.

–Control access to resources
–Get and set permissions
–Allow and deny user access
6) Protection

System Calls Types – Summary

Binary Logic – Definition
–Binary logic consists of binary variables and a set of logical
operations.
–Each variable having two and only two distinct possible values: 1
and 0.
–Three Basic logical operations: AND, OR, and NOT.
1 0

Binary Logic – Definition
–Binary logic consists of binary variables and a set of logical
operations.
Logic Gates
Basic Gates
AND
OR
NOT
Derived
Gates
NOR
NAND
XOR
XNOR

How does they look ?

AND Logic Gate
Inputs Output
x y F = x • y
0 0 0
0 1 0
1 0 0
1 1 1
x
y
F
AND Gate
x AND y is equal to F
F = x • y
F = xy

OR Logic Gate
Inputs Output
x y F = x + y
0 0 0
0 1 1
1 0 1
1 1 1
OR Gate
x OR y is equal to F
F = x + y
x
y
F

NOT/Inverter Logic Gate
Inputs Output
A F
0 1
1 0
X F
NOT Gate
F = X’
F = X

NAND Logic Gate
Inputs Output
x y F = (x • y)
0 0 1
0 1 1
1 0 1
1 1 0
NAND Gate
x NAND y is equal to F
F = (x • y)
x
y
F

NOR Logic Gate
Inputs Output
x y F = (x + y)
0 0 1
0 1 0
1 0 0
1 1 0
NOR Gate
x NOR y is equal to F
F = (x + y)
x
y
F

XOR Logic Gate
Inputs Output
x y F = x ⊕ y
0 0 0
0 1 1
1 0 1
1 1 0
XOR Gate
x XOR y is equal to F
F = x ⊕ y
x
y
F

XNOR Logic Gate
Inputs Output
x y F = (x ⊕ y)
0 0 1
0 1 0
1 0 0
1 1 1
XNOR Gate
x XNOR y is equal to F
F = (x ⊕ y)
x
y
F

Examples
a)Four-input OR gate
b)Three-input OR gate
c)Mixture of both

Distributive Laws
x y z y + z x • (y + z) x • y x • z (x • y) + (x • z)
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

Distributive Laws (Cont.)
x y z y + z x • (y + z) x • y x • z (x • y) + (x • z)
0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0
0 1 0 1 0 0 0 0
0 1 1 1 0 0 0 0
1 0 0 0 0 0 0 0
1 0 1 1 1 0 1 1
1 1 0 1 1 1 0 1
1 1 1 1 1 1 1 1

Another Example
x y x' y' x + y (x + y)’x'y’x y x' + y’(xy)’
0 0
0 1
1 0
1 1

Another Example (Cont.)
x y x' y' x + y (x + y)’x'y’xy x' + y’(xy)’
0 0 1 1 0 1 1 0 1 1
0 1 1 0 1 0 0 0 1 1
1 0 0 1 1 0 0 0 1 1
1 1 0 0 1 0 0 1 0 0

Conversions
x
y
x
y
x
F

Conversions (Cont.)
x
y
x
y
x
F
F = xy + x(x + y)

Conversions (Cont.)
x'
y
z'
x'
y'
z
F

F = x (y' + z) (x' + y + z')
Conversions (Cont.)
x'
y
z'
x'
y'
z
F

– To find the one’s complement you simply invert the binary number.
Example:
•The one’s complement of the binary number 10001000 is 01110111
One’s Complement

–What’s DMA (Direct Memory Access)?
–What’re the main computer system components?
–Mention three types of storage structure along with their
advantages.
–What’re the three main logic gates found?
Test your knowledge ?

End of lecture 2
Thank You!