Kabul Education University
Computer Science Faculty
Information Technology Department
Operating System
Introduction
1
Road Map
• Info ( the instructor)
• The course and its objectives
• Syllabus ( brief glance) and detailed
• Reference Books
• Grading Policy
• Course Policy
• Why we should study OS
• About OS
2
Info:
• Instructor: Asst. Prof. Sayed Elham “Sadat”
• BCS - Computer Networks,
• M.Tech – Computer Science Engineering
• Email: sayed.elham@kuk.ac.in
sayed.elham@keu.edu.af
3
Learning Outcomes
• Aim of the course: Students will be able to:
• Describe the major components of operating systems
• Explain the role of the OS as a high level interface to the hardware
• Explain what an operating system does and how it is used
• Use OS as a resource manager that supports multiprogramming
• Discuss the importance and use of threads and processes in an OS
• Understand the role of Concurrency in an OS
• Explain the low level implementation of memory management.
• Explain File system management in OS.
4
Core topics
• Introduction to Operating Systems
• Process and Process Management
• Threads and Concurrency
• CPU Scheduling
• Process Synchronization
• Deadlocks
• Memory Management
• Storage Management
5
Core topics
• File System interface
• Security and Protection
• Open Source and Closed Source
6
Grading Policy
• Midterm 20%
• Programming assignments 20%
• Homework and Quizzes 10%
• Final 50%
---------------------------------------------------------------------
• Total 100%
• Note: with a little modifications.
7
Course Policy
• Attending at least 75% lectures are mandatory for exam qualification.
• No noise during lecture.
• Silent your mobile phone.
• If you have question(s), raise your hand. ( we can discuss at end of each
class).
8
Class Pic.
• Pre-Requisites
• Advance programming
• Computer architecture
• Data structures and Algorithms
9
What is an Operating System?
• A program that acts as an intermediary between a user of a computer
and the computer hardware.
• Software between applications and hardware
• Control Freak
• Must never ever loose control of the hardware
• Resource Manager
• Give resources to applications
• Take resources from applications
• Protection and Security
• Great Pretender
• Make resources look different
• Make finite resources appear as infinite resources
10
Why study Operating System?
• OS is a key part of a computer System
• It makes our lives better (and worse)
• it is “magic” and we want to understand how
• it has “power” and we want to have the power
• OS is complex
• how many procedures does a keystroke invoke?
• what happens when your running application program references a pointer
having the value 0?
• real OS is huge and very expensive to build
• Win/NT: 8 years, 1000s of people
• Wind. 4k ppls, 2k on base, 2k on other systems
11
Computer System Structure
• Computer system can be divided into four components:
• Hardware – provides basic computing resources
• CPU, memory, I/O devices
• Operating system
• Controls and coordinates use of hardware among various applications and users
• 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
• Users
• People, other computers
12
Four Components of a Computer System
13
What Operating Systems Do
• To understand the operating system’s role, we need to explore operating
systems from two viewpoints:
1. User Point of View
2. System Point of View
14
1 User point of view
• Users want convenience, ease of use and good performance
• Don’t care about resource utilization
•Shared computer such as mainframe must keep all users happy when
they are connected through terminals.
•Users of dedicate systems such as workstations have dedicated
resources but frequently use shared resources from servers.
•Handheld computers are resource poor, optimized for usability and
battery life
•Some computers have little or no user interface, such as embedded
computers in devices and automobiles
15
1 User point of view cont.
•Most computer users sit in front of a PC, consisting of a monitor, keyboard, mouse,
and system unit. Such a system is designed for one user to monopolize its
resources. The goal is to maximize the work that the user is performing. Here, the
OS is designed for ease of use, not caring of resource utilization
•In other cases, a user sits at a terminal connected to a mainframe or a
minicomputer. Other users are accessing the same computer through other
terminals. These users share resources and may exchange information. The OS in
such cases is designed to maximize resource utilization to assure that all available
CPU time, memory, and I/O are used efficiently and that no individual user takes
more than her fair share.
•In still other cases, users sit at workstations connected to networks of other
workstations and servers. These users have dedicated resources at their disposal,
but they also share resources such as networking and servers, including file,
compute, and print servers. Therefore, their OS is designed to compromise
between individual usability and resource utilization. 16
2 System point of view
• Must Utilize all the resources efficiently and fairly.
• Operating System offer a reasonable way to solve the problem of creating a usable
computing system.
• OS is a resource allocator
• Manages all resources
• Decides between conflicting requests for efficient and fair resource use
• OS is a control program
• Controls execution of programs to prevent errors and improper use of the
computer
17
2 System point of view cont.
•In this point of view, the OS is the program most intimately involved with the
hardware.
•A computer system has many resources that may be required to solve a problem:
CPU time, memory space, file-storage space, I/O devices, and so on.
•The operating system acts as the manager of these resources.
•A slightly different view of an OS emphasizes the need to control the various I/O
devices and user programs.
•An operating system is a control program. A control program manages the
execution of user programs to prevent errors and improper use of the computer. It
is especially concerned with the operation and control of I/O devices.
18
What is an Operating System?
• OS is an Interface between computer hardware and user. AND
• An operating system is a program that manages a computer’s hardware,
and provides a basis for application programs
• And 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
19
Operating System Definition (Cont.)
• No universally accepted definition
• “Everything a vendor ships when you order an operating system” is a
good approximation
• But varies wildly
• “The one program running at all times on the computer” is the
kernel.
• Everything else is either
• a system program (ships with the operating system) , or an application
program.
20
Computer Startup
• when it is powered up or rebooted—it needs to have an initial
program to run. This initial program is known as bootstrap program,
• bootstrap program is loaded at power-up or reboot
• Typically stored in ROM or EPROM, generally known as firmware
• Initializes all aspects of system
• Loads operating system kernel and starts execution
• UEFI: Unified Extensible Firmware Interface
21
Types of Operating System
Your Home Work
22
Open Source & Closed Source Operating Systems
• Open source operating system - Open-source operating system is a type of
computer software in which source code is released under a license in which the
copyright holder grants users the rights to use, study, change, and distribute the
software to anyone and for any purpose.
• Examples of open source operating systems are Linux, Open Solaris, Open BSD,
Free BSD.
23
Open Source & Closed Source Operating Systems
• Closed source operating system - Closed-source operating systems use code that
is proprietary and kept secret to prevent its use by other entities. Traditionally, they
are sold for a profit.
• Examples of closed source operating systems are Mac OS, UNIX, Windows.
24
Computing Environments
• Traditional computing
• Office environment - PCs connected to a network, terminals attached to
mainframe or minicomputers using time-sharing.
• Home networks - Used to be single system, then modems, now firewalled &
networked.
25
Computing Environments
• Client-Server Computing
• Dumb terminals supplanted by smart PCs. Many systems such as servers,
responding to requests generated by clients.
Server Computer provides an interface to client to request services (i.e.
database)
File-server provides interface for clients to store and retrieve files.
26
Computing Environments
• Peer to Peer Computing / Workgroup Computing
• P2P does not distinguish clients and servers
• Instead all nodes are considered peers.
• Each peer may each act as client, server or both;
• A node must join P2P network to use its resources.
• Operating systems used in peer to peer computing are clients which may belong to
same or different vendors.
27
Computing Environments
• Web based Computing system
• Web has become ubiquitous & PCs are most prevalent devices.
• More devices becoming networked to allow web access.
• Use of operating systems like Windows 95 has evolved into Linux and Windows,
which can be clients and servers.
28
Computing Environments
• Cloud computing
● Cloud computing is the delivery of computing as service rather than a product.
● Cloud computing means storing and accessing data and programs over the
internet instead of your computer's hard drive.
● It allows on-demand network access to shared computing resources over the
internet from a remote location.
29
What is a User Interface?
• User interface is a medium or the screen thru which a user interacts with an
application, website or an operating system in order to complete the tasks.
• The user interface is of two types
• Command Line Interface (CLI)
• Graphical User Interface (GUI)
30
User Interface
• Command Line Interface - CLI allows a user to perform tasks by entering
commands at prompts by using the keyboard keys.
• Its working mechanism is very easy, but it is not user friendly.
• Users enter the specific command, press “Enter”, and then wait for a response.
• After receiving the command, the CLI processes it accordingly and shows the
output/result on the same screen; command line interpreter is used for this
purpose.
31
User Interface
• Graphical User Interface - A GUI uses windows, icons, and menus to perform
tasks such as opening, deleting, and moving files.
• Although many GUI operating systems are through the use of a mouse, the
keyboard can also be utilized by using keyboard shortcuts or arrow keys.
• GUI operating systems are much easier to learn and use because commands do not
need memorized.
32
User Interface
33
Distributed Operating System
• A distributed operating system (DOS) is an essential type of operating system. A
distributed operating system is an extension of the network operating system that
supports higher levels of communication and integration of the machines on the
network.
• This system looks to its users like an ordinary centralized operating system but runs
on multiple, independent central processing units (CPUs).
34
Distributed Operating System
• The Distributed operating system involves a collection of autonomous computer
systems, capable of communicating and cooperating with each other through a
LAN / WAN.
• A DOS is used in the distributed system where it manages the system shared
resources used by multiple processes, the process scheduling activity, the
communication and synchronization between running processes etc.
• It is also helps in resource sharing, improves the reliability, communication and
computation speedup.
35
Distributed Operating System
• Examples of distributed operating system are:
• LOCUS
• MICROS
• IRIX
• OSF/1
36
Computer System Organization
• Computer-system operation
• A modern general-purpose computer system consists of one or more CPUs and a
number of device controllers connected through a common bus that provides access to
shared memory. Each device controller is in charge of a specific type of device.
• Concurrent or parallel execution of CPUs and devices competing for memory cycles
37
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
• 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
38
Interrupt
• In an operating system, an interrupt is a signal sent to the CPU that
temporarily stops the current program so the CPU can handle an
important event immediately.
• It’s like the CPU is reading a book (running a program) and someone
taps on its shoulder (interrupt) to tell it something urgent. The CPU
pauses reading, handles the urgent matter, and then goes back to
where it left off.
39
Types and classification of Interrupts
1. Hardware Interrupts
• These are generated by external hardware devices to get the CPU’s
attention.
Maskable Interrupt (MI)
• Can be turned on or off (masked) by the CPU.
• If masked, the CPU ignores it temporarily.
• Example: A printer asking for more data while the CPU is busy.
Non-Maskable Interrupt (NMI)
• Cannot be ignored by the CPU.
• Used for urgent events like hardware failures.
• Example: Memory parity error or power failure.
• invalid memory access, page fault.
40
Types and classification of Interrupts
2. Software Interrupts
• These are generated by programs or the operating system itself.
2.1 Normal Interrupt
• Explicitly triggered by a program to request a service from the OS.
• Often used for system calls.
• Example: A program asks the OS to read a file.
2.2 Exception
• Generated automatically when the CPU detects an error or special condition.
• Example: Division by zero, invalid memory access, page fault.
41
Types and classification of Interrupts (Cont.)
Classification of Interrupts According to Periodicity of Occurrence:
1. Periodic Interrupts
• Occur at regular, predictable intervals.
• Usually generated by hardware timers or clock circuits.
• Commonly used for time-sharing in multitasking operating systems, refreshing displays, or sampling data at fixed intervals.
• Example:
• System clock interrupt every 10 ms to schedule processes.
• Refreshing the system clock on your computer.
2. Aperiodic Interrupts
• Occur at irregular, unpredictable intervals.
• Usually triggered by external events that the system cannot forecast in advance.
• Often come from user actions or hardware devices when an event happens.
• Example:
• Keyboard key press.
• Mouse movement.
• Network packet arrival.
42
Storage Definitions and Notation Review
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
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).
43
Storage Structure
• Main memory – only large storage media that the CPU can access directly
• Random access
• Typically volatile
• Secondary storage – extension of main memory that provides large nonvolatile
storage capacity
• Hard disks – SSD metal or glass platters covered with magnetic recording material
• Disk surface is logically divided into tracks, which are subdivided into sectors and
further into Blocks
• The disk controller determines the logical interaction between the device and the
computer
• Solid-state disks – faster than hard disks, nonvolatile
• Various technologies
• Becoming more popular
44
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
• Device Driver for each device controller to manage I/O
• Provides uniform interface between controller and kernel
45
Storage-Device Hierarchy
46
Caching
• Important principle, performed at many levels in a computer (in
hardware, operating system, software)
• 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
47
Computer-System Architecture
• Single Processor
• Multiprocessors
48
Computer-System Architecture
Singleprocessor
Computer systems comes with single or multiple Processors.
• Most systems use a single general-purpose processor
• Most systems have special-purpose processors as well
most computer systems used a single processor. On a singleprocessor
system, there is one main CPU capable of executing a general-purpose
instruction set, including instructions from user processes.
49
Computer-System Architecture
Multiprocessors
• Multiprocessors mean multiple CPU Chips inside a single Computer.
• Also known as parallel systems, tightly-coupled systems
• Advantages include:
1. Increased throughput
2. Economy of scale
3. Increased reliability – fault tolerance
• Two types:
1. Asymmetric Multiprocessing – each processor is assigned a specie task.
2. Symmetric Multiprocessing – each processor performs all tasks
•Multiprocessors System can be multicore systems when a single CPU chip
contains multiple cores. The core can be consider as a standard
independent processor.
50
Symmetric Multiprocessing Architecture
51
A Dual-Core Design
• A dual-core CPU has two central processing units, so it appears to the
operating system as two CPUs. A CPU with two cores,
• for example, could run two different processes at the same time.
52
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
• Asymmetric clustering has one machine in hot-standby mode
• Symmetric clustering has multiple nodes running applications, monitoring each other
• Some clusters are for high-performance computing (HPC)
• Applications must be written to use parallelization
53
Clustered Systems
•Like multiprocessor systems, but multiple systems working
together
• Some have distributed lock manager (DLM) to avoid conflicting
operations
• provides functions that allow cooperating processes in a cluster to
synchronize access to a shared resource
• Notify a process that has queued a lock request to a resource when its
request has been granted.
54
Clustered Systems
55
Operating-System Operations
• Interrupt driven (hardware and software)
• "interrupt-driven" operation refers to a mechanism where the
execution of the current process or task is temporarily halted to allow
the CPU to respond to an event or condition that requires immediate
attention.
• This event is known as an "interrupt." The interrupt-driven approach is
essential for efficient multitasking and real-time system operations.
• Hardware interrupt by one of the devices
• Software interrupt (exception or trap):
• Software error (e.g., division by zero)
• Request for operating system service
• Other process problems include infinite loop, processes modifying each other or the
operating system
56
Operating-System Operations (cont.)
• Dual-mode operation allows OS to protect itself and other system
components from malfunctioning.
• User mode and kernel mode
• Mode bit provided by hardware
• Provides ability to distinguish when system is running user code or kernel code or mode: kernel
(0) or user (1).
• Some instructions designated as privileged, only executable in kernel mode
• System call changes mode from user to kernel, return from call resets it to user
• Increasingly CPUs support multi-mode operations
• i.e. virtual machine manager (VMM) mode for guest VMs
57
• Kernel Mode: In Kernel mode, the executing code has complete and unrestricted
access to the underlying hardware. It can execute any CPU instruction and reference
any memory address. Kernel mode is generally reserved for the lowest-level, most
trusted functions of the operating system. Crashes in kernel mode are catastrophic;
they will halt the entire PC.
• User Mode: In User mode, the executing code has no ability to directly access
hardware or reference memory. Code running in user mode must delegate to system
APIs to access hardware or memory. Due to the protection afforded by this sort of
isolation, crashes in user mode are always recoverable. Most of the code running on
your computer will execute in user mode.
58
Operating-System Operations (cont.)
Transition from User to Kernel Mode
59
Timer
• We must ensure that the operating system maintains control over the CPU.
• We cannot allow a user program to get stuck in an infinite loop or to fail to call
system services and never return control to the operating system.
• To accomplish this goal, we can use a timer.
• Timer to prevent infinite loop / process hogging resources.
• A timer can be set to interrupt the computer after a specified period.
• The period may be fixed (for example, 1/60 second) or variable (for example,
from 1 millisecond to 1 second).
60
Timer
• A variable timer is generally implemented by a fixed-rate clock and a counter.
• The operating system sets the counter.
• Every time the clock ticks, the counter is decremented.
• When the counter reaches 0, an interrupt occurs.
61
Multiprogramming OS
• Multi Programming OS
• Non- Preemptive
• If will complete the processing of P1 and after that it will process the P2 or P3 or P4.
• Until and unless the process wants to access an I/O.
• Advantage
• CPU Idle time is decreasing,
• CPU will not stay free
• CPU will only stay free when the P1 an instruction of a process is accessing some I/O (ex. It want to access some
device or file).
• In this time, the OS will give some other process to CPU.
• Means we have abundance no. of process available.
• Example of a class and teacher solving every 5 question of all students.
62
Multiprogramming OS
• Single users frequently have multiple programs running.
• Multiprogramming increases CPU Utilization by organizing jobs (code and data) so that the CPU
always has one to execute.
• The operating system keeps several jobs in memory simultaneously.
• Since main memory is too small to accommodate all jobs.
• The jobs are kept initially on the disk in the job pool.
• This pool consists of all processes residing on disk awaiting allocation of main memory.
• The operating system picks and begins to execute one of the jobs in memory.
• Eventually, the job may have to wait for some task, such as an I/O operation, to complete.
• In a non-multiprogrammed system, the CPU would sit idle.
• In a multiprogrammed system, the operating system simply switches to, and
executes, another job.
• When that job needs to wait, the CPU switches to another job, and so on.
63
Multiprogramming OS
Virtual Memory Job Pool
Virtual memory is a memory management technique
in the operating system that gives users the illusion
Job pool is a program of the operating system
that they are working with memory that is equal to
that is located in operating system and stores
the memory of secondary storage medium ( that is
newly created processes while they are waiting
very large memory). Thus, this allows a programmer
for their respective resources.
to write a program that requires more memory than
the actual memory.
The concept of the job pool states that a newly
The concept behind virtual memory is that it
created process is stored in a pool called a job
creates an illusion that we are working with a very
pool, where these processes wait for the
large memory when actually we are using only a
resources to get allocated in order to get
part of the memory.
executed.
64
Multi-tasking OS
• Multi tasking
• Preemptive
• Means it is time sharing.
• The OS decide in advance that a process will be executed for sometime.
• If it got executed under that time interval, then well and good.
• Otherwise, I’ll schedule it again in future.
• Example : we only solve 2 question of each student in class.
• Advantages:
• CPU will not be idle.
• Response time is faster.
65
Multithreading
• Process is simply codes.
• inside a process we have codes, statements, instructions.
• in a code we may have thousands of statements or instructions.
• A thread is the smallest unit of processing that can be performed in an
OS.
• For example we execute an specific amount of statements, then another
amount of statements.
66
Thank You
Any Questions?
67