PRINCIPLES OF OPERATING
SYSTEMS
CISC 2005
INTRODUCTION
Huanle Xu
CIS Dept., University of Macau
https://www.fst.um.edu.mo/personal/huanlexu/
Operating System 1
Content of this lecture
■ Course information (personnel, policy,
prerequisite, agenda, etc.)
■ Why learning OS?
■ What is an OS? What does it do?
■ Summary
Operating System 2
Goals of this course
■ Understand operating system concepts
■ How OS works, and more importantly, why?
■ Basis for future learning
■ Get hands dirty
– You will almost implement many components of real OS
■ Ready you for the real-world challenges!
– No one will help you to debug your program
– “My program crashes, why?” --- find out yourself!
Operating System 3
Suggested Textbooks
Modern Operating Systems, 4th Edition
(Main textbook)
Andrew S. Tanenbaum and Herbert Bos
Operating Systems Concepts
(Further reading)
ABRAHAM SILBERSCHATZ and
PETER BAER GALVIN
Operating System 4
Personnel
■ Instructor:
– Huanle Xu (huanlexu@um.edu.mo)
■ Research areas: Cloud Computing & Distributed Systems
■ 2024 FST Research Excellence Awrad
■ 2024 UM Outstanding Academic Staff
■ 2021 ACM SoCC Best Paper Award
– Office hour: To be announced
– Homepage: https://www.fst.um.edu.mo/personal/huanlexu/
■ TAs:
– Zizhao Mo and others (to be announced later)
Operating System 5
Prerequisite
■ Programming experiences
– You will be programming in C
■ Computer organizations
– What is an Instruction (e.g., load, store)?
– What is CPU? Memory? Registers?
– What is Stack? Stack pointer?
– What is Program Counter (PC)?
Operating System 6
Course Contents
■ Overview of computer hardware
■ Threads and processes
■ Synchronization and concurrency
■ Scheduling
■ Memory Management, Virtual Memory
■ Disk Management and File Systems
■ Advanced topics
Operating System 7
Grading
■ Exams
– Mid-term - 25%
– Final - 35%
■ In-Class Participant
– Lab and Quiz – 10%
■ Assignments
– Programming - 20%
– Written Homework – 10%
■ Policies
– No extensions to deadlines
– 20% penalty per day submitted late
Operating System 8
Practice sessions
■ Optional to attend
■ TA will be available in the first 75 mins of each lab session
– They are there to answer your question
– Give tutorials if needed
Operating System 9
What to Expect From Assignments
■ Building an OS is difficult
– Perhaps the hardest lab in your undergraduate study
– OS: one of the hardest programs to write & debug
■ Principles may sound easy, implementation is extremely hard
– The labs give specifications about the key modules, not
implementations
■ You will spend a lot of time on the assignments
– Allows for imagination
– Allows for errors and frustration
– Lab instructions ask that you design well, before you code
– Assume that you will do the design/coding outside lab hours
Operating System 10
But it is rewarding!
■ Solid understanding of how an OS works
– Appreciations on the implementation efforts that make things
work
■ Solid technical capability
– Again: OS is one of the hardest programs to write and debug
– Quickly hack into unfamiliar code base
Operating System 11
What to expect from lectures
■ Not only understand how, but more importantly, why
■ You are encouraged to speak up
– Ask questions, answer questions
“The mediocre teacher tells. The good teacher explains. The
superior teacher demonstrates. The great teacher inspires.”
Operating System 12
Exam
■ Midterm
– Covers first half of class
■ Final
– Covers second half of class + selected material from first part
■ Assignment-related knowledge may be included in the exams
– So do your assignments and do NOT copy!
Operating System 13
How NotTo pass CISC2005
■ Do not come to lecture
– It’s nice out, the slides are online, and material in the
book anyway
– TRUTH: Lecture material is the basis for exams
– It is much more efficient to learn through discussion
■ Copy other people’s assignment
– It is cheating!
– How can you answer the questions in midterm or final
exams?
Operating System 14
Before we start
■ Any questions?
■ Do you think this will be a hard class?
Operating System 15
Why learning OS?
■ Fulfill requirement?
■ Great programmers understand Operating System
– http://www.youtube.com/watch?v=-3Rt2_9d7Jg
■ Which course is this?
■ http://matt-welsh.blogspot.ca/2010/10/in-defense-of-mark-zuckerberg.html
– Software companies love OS students
■ OS is the foundation of all software! (and it’s hard to code!)
■ Academic research in OS is very influential
– What do Microsoft, Apple, VMware, or even Google sell?
Operating System 16
What is an OS?
■ Anyone?
■ Give a few names of an OS?
– Desktops?
– Smart phones?
Operating System 17
OS and hardware
■ The OS abstracts/controls/mediates access to hardware resources
(what resources?)
– Computation (CPUs)
– Volatile storage (memory) and persistent storage (disk, etc.)
– Communication (network, modem, etc.)
– Input/output devices (keyboard, display, printer, etc.)
Operating System 18
Benefits to Applications
■ Simpler
– no tweaking device registers
■ Device independent
– all disks look the same
■ Portable
– same program runs on
Windows95/98/ME/NT/2000/XP/Vista/Windows
7/Windows 8/Windows 10
■ Worry less about interference from other applications
Operating System 19
OS is…
■ Software layer between hardware and applications
■ The OS is “all the code that you didn’t have to write” to implement your
application
Operating System 20
An example comparing life
with/without OS
Life with an OS Life without an OS
file = open (“test.txt”,
O_WRONLY); • Blocks, platter, track, and sector
write (file, “test”, 4);
• Where is this file on disk? Which
close (file); platter, track, and sectors?
• Code needs to change on a
different system
Operating System 21
What does an OS do?
■ Resources
– Allocation
– Protection
– Reclamation
– Virtualization
Operating System 22
What does an OS do?
■ Resources • Finite resources Government:
– Allocation • Competing demands Limited budget,
– Protection Land,
• Examples: Natural resources
– Reclamation
– Virtualization • CPU
• Memory
• Disk
• Network
Operating System 23
CPU Pipelining
A three-stage pipeline A superscalar CPU
Operating System 24
CPU Management
•Process Trace
• The shaded areas represent code executed by the dispatcher.
The same sequence of instructions is executed by the
dispatcher in each instance because the same functionality of
the dispatcher is being executed.
• We assume that the OS only allows a process to continue
execution for a maximum of six instruction cycles, after which
it is interrupted; this prevents any single process from
monopolizing processor time.
• The first six instructions of process A are executed, followed by
a time-out and the execution of some code in the dispatcher,
which executes six instructions before turning control to
process B.
• After four instructions are executed, process B requests an I/O
action for which it must wait. Therefore, the processor stops
executing process B and moves on, via the dispatcher, to
process C.
• After a timeout, the processor moves back to process A. When
this process times out, process B is still waiting for the I/O
operation to complete, so the dispatcher moves on to process
C again.
Operating System 25
What does an OS do?
■ Resources • You can’t hurt me, Government:
– Allocation I can’t hurt you. Law and order
– Protection
– Reclamation • Some degrees of
– Virtualization safety and security
Operating System 26
What does an OS do?
■ Resources • The OS gives, Government:
– Allocation The OS takes away Income Tax
– Protection
– Reclamation • Sometimes
– Virtualization involuntarily
Operating System 27
What does an OS do?
■ Resources • Illusion of infinite, Government:
– Allocation private resources Social welfare and
• Memory vs. insurance
– Protection disk
– Reclamation • Time-shared
– Virtualization CPU
Operating System 28
Why you want to learn OS?
■ Foundation to other software
– Databases, Browsers, Computational software, … …
■ OS is one of the hardest software piece to write & debug
– Directly talks to hardware (very ugly interfaces)
– Abstract into clean interfaces
– They are BIG
– Lines of code:
■ Windows Vista (2006): 50M (XP + 10M)
■ Linux 3.6: 15.9 M
■ Android 4.0: > 1M
Operating System 29
Why you want to learn OS?
■ Many OS concepts (e.g., protection, resource management) is needed in
other places
– E.g., browser
■ OS is used everywhere
– Your car is running on Linux/Windows
Operating System 30
Any Questions?
Operating System 31