Post on 19-Oct-2020
OPERATING SYSTEMS A BRIEF INTRODUCTION
ECE 650 - REZA BABAEE
LEARNING OBJECTIVES
▸ Explain the main concepts of an Operating system:
▸ History & definitions
▸ Process
▸ Memory
▸ I/O and file system
▸ System call Today’s class
REFERENCES
▸ Chapter 1,2 of Modern Operating Systems by Andrew S. Tanenbaum, 4th Edition
▸ Chapter 2 of Operating Systems: Internals and Design Principles by William Stallings, 9th Edition
▸ Slides credit: Paul A.S. Ward
A BIT HISTORY
https://www.computerhistory.org/timeline/computers/
EARLY STAGE
▸ First digital computer by Charles Babbage
▸ First programmer Ada Lovelace
▸ 1945-1955: Vacuum Tubes
▸ 1955-1965: Transistors and Batch Systems
IC STAGE
▸ 1965- 1980: ICs and Multiprogramming
Replaced by spooling
PC STAGE‣ 1980-Present: Personal computers
‣ MULTICS & birth of UNIX
‣ MINIX and Linux
‣ The story of PC ‣ IBM PC
‣ Bill Gates and BASIC
‣ Gary Kildall and CP/M
‣ Bill Gates buys DOS from a local manufacturer ! MS DOS
‣ Doug Engelbart and the invention of GUI (used by Xerox)
‣ Observed by Steve Jobs ! birth of Lisa and Apple Macintosh (OS X)
‣ Followed by birth of MS Windows (a GUI layer on top of DOS for a decade)
‣ GUI for UNIX-like systems ! X11 (X Window System)
MOBILE STAGE
▸ 1990-Present: Mobile computers
▸ Birth of smartphones in mid-90s by Nokia (Symbian OS)
▸ Blackberry’s RIM (2002)
▸ Apple’s iOS (2007)
▸ Fierce competition between RIM and iOS
▸ Settled by the birth of Android (2008)
FOUNDATIONS
https://www.coulterfamilycounseling.com/building-a-strong-relationship-foundation/
WHAT IS AN OPERATING SYSTEM?
▸ Abstraction layer for machine (top-down) ▸ Producing an extended machine
▸ Example: SATA interface and a disk driver
▸ Files and folders
BEAUTIFUL ABSTRACTION?
fd = socket(AF_INET, SOCK_STREAM, 0); getsockname(fd, (sockaddr *)&binder, &binderSockLen); nready = select(maxfd+1, &rset, NULL, NULL, NULL); FD_ISSET(listenfd, &rset); connfd = accept(listenfd, (sockaddr *)&cliaddr, &clilen);
(Compared to the alternative, yes, it is)
ABSTRACTION LAYERS
Image courtesy: Fig. 2.1 Operating Systems: Internals and Design Principles by William Stallings, 9th Edition
WHAT IS AN OPERATING SYSTEM?
▸ 2) Resource manager (bottom-up)
• Time multiplexing (CPU)
• Space multiplexing (Memory)
http
s://a
mte
lefo
n.co
m/w
p-co
nten
t/upl
oads
/201
1/05
/Min
iInfo
Pro
KE
Y.jp
g
OS TAXONOMY
▸ Mainframes (batch, transaction processing, timesharing)
▸ OS/390 (being replaced by UNIX variants such as Linux)
▸ Server (serving multiple users at once)
▸ Solaris, FreeBSD, Windows Server
▸ Multiprocessor (running on a machine with multiprocessors)
▸ Windows and Linux
▸ PC (personal usage)
▸ Linux, Windows, OS X
OS TAXONOMY - CONT.
▸ Hand-held Devices
▸ Android, iOS
▸ Embedded (control devices that are not generally thought of as computers and which do not accept user-installed software)
▸ QNX
▸ Sensor-node (tiny sensor nodes communicating with each other)
▸ TinyOS
▸ Real-time (time is key in their design, industrial controllers)
▸ QNX, eCos
▸ Smart card (credit-card-sized devices containing a CPU)
▸ JVM
HARDWARE OVERVIEW
https://www.unifiedsystems.ca/best-computer-hardware-certifications-2018-to-give-you-the-edge/
PROCESSORS
▸ Simple CPU cycle (pipeline vs superscalar)
▸ Registers (why?)
• General registers
• PC (Program Counter)
• SP (Stack Pointer)
• PSW (Program Status Word) ! part. Important in I/O and system calls
‣ User vs kernel mode
‣ System calls
• Creating a TRAP and switching to kernel-mode
Image courtesy: Fig. 1.7 Modern Operating Systems by Andrew Tanenbaum, 4th Edition
MEMORY
▸ Ideal memory
▸ Extremely fast
▸ Abundantly large
▸ Dirt cheap!
→ As of today not all conditions are satisfied at the same time!
Image courtesy: Fig. 1.9 Modern Operating Systems by Andrew Tanenbaum, 4th Edition
DISK
▸ Mechanical:
▸ One or more metal platters that rotate
▸ Different from SSDs
▸ Virtual memory
▸ Managed by MMU (memory management Unit) Image courtesy: Fig. 1.10 Modern Operating Systems by Andrew Tanenbaum, 4th Edition
OS ARCHITECTURE
https://www.dezeen.com/2018/06/15/zaha-hadid-architects-morpheus-hotel-in-macau-architecture/
MONOLITHIC
Image courtesy: Fig. 1.24 Modern Operating Systems by Andrew Tanenbaum, 4th Edition
LAYERED
Image courtesy: Fig. 1.25 Modern Operating Systems by Andrew Tanenbaum, 4th Edition
MICROKERNEL
Image courtesy: Fig. 1.26 Modern Operating Systems by Andrew Tanenbaum, 4th Edition
CLIENT-SERVER
Image courtesy: Fig. 1.27 Modern Operating Systems by Andrew Tanenbaum, 4th Edition
VIRTUAL MACHINES
Image courtesy: Fig. 1.28 Modern Operating Systems by Andrew Tanenbaum, 4th Edition
05-OS-INTRO
https://toronto-employmentlawyer.com/break-workplaces/
OS CONCEPTS
http://charlessledge.com/use-incubation-solve-hard-problems/
PROCESS
▸ Consists of three components
1. An executable program
2. Data needed/created by the program
3. Execution context of the program
- All information OS needs to manage the process during and between execution [PC, CPU registers, stack pointers, files opened, resources owned...]
PROCESS MODEL
▸ A program in execution (?)
▸ Sequential execution
▸ Program Counter to keep track of next instruction
▸ Give the illusion (is it?) of a dedicated computer
SIMPLIFIED PROCESS CONTROL BLOCK
▸ Identifier: PID
▸ State:
▸ Running
▸ Not-running
▸ Priority
▸ Program counter
▸ Memory pointer
▸ Context data (registers)
▸ I/O status (why?)
▸ Accounting information (CPU time)
Image courtesy: Fig. 3.1 Operating Systems: Internals and Design Principles by William Stallings, 9th Edition
PROCESS STATE
▸ Not-running state must be further subdivided into
▸ ready to execute
▸ blocked (e.g., waiting for I/O)
▸ newly created
▸ exiting
▸ Why? need to assist the dispatcher
▸ dispatcher cannot just choose the process that has been in the queue the longest because it may be blocked
PROCESS 5-STATE DIAGRAM
Image courtesy: Fig. 3.6 Operating Systems: Internals and Design Principles by William Stallings, 9th Edition
PROCESS CREATION
▸ When?
1. System initialization
2. System call by a running process
3. User request
4. Batch-job initiation
PROCESS CREATION
▸ What?
▸ Assign a unique process identifier
▸ Allocate space for the process
▸ program, data, stack, PCB
▸ Initialize process control block
▸ Set up appropriate linkages
▸ e.g., add new process to linked list used for scheduling queue
▸ Create or expand other data structures
▸ e.g., maintain an accounting file
PROCESS TERMINATION
1. Process exits normally, by program choice
2. Process exits with error
3. Fatal error
4. Killed by another process
CONTEXT SWITCH
▸ More than just switching from user mode to kernel mode
▸ The currently executing process is to be changed
▸ Which means: execution context must be switched
▸ Save the context of processor in the PCB
▸ Including program counter, other registers
▸ Update the PCB and put it to appropriate queue - ready, blocked, ....
CONTEXT SWITCH - CONT.
▸ Select another process for execution (another PCB)
▸ Update the PCB of the process selected
▸ Update memory-management data structures
▸ Restore processor context to that of the selected process
▸ Question:
▸ What does this imply for the contents of
- Cache?
- Main memory (as opposed to virtual memory)?
THREADS
▸ A thread is a light-weight process that has execution state (running, ready, etc.)
▸ Thread context saved when thread not running
▸ A thread has an execution stack
▸ Some per-thread static storage for global variables
▸ Access to the entire memory and all resources of its process
▸ All threads of a process share this
UNI- AND MULTI-THREADED PROCESS MODEL
User Stack
Kernel Stack
User Addr. Space
Process Control Block
User Stack
Kernel Stack
User Addr. Space
Process Control Block
User Stack
Kernel Stack
User Stack
Kernel Stack
Thread Control Block
Thread Control Block
Thread Control Block
Thread Thread Thread
Single-Threaded Multithreaded
WHY USING A THREAD?
▸ Less time needed
▸ to create a new thread than a process
▸ to terminate a thread than a process
▸ to switch between two threads within the same process
▸ Communication between threads is faster (why?)
▸ Cache and main memory performance benefits
▸ Penalty: lesser inter-thread protection
THREAD STATE
▸ key thread states: running, ready, blocked
▸ basic thread operations
▸ spawn
▸ block
▸ unblock
▸ finish
▸ Question: If a thread blocks, does the entire process block?
MEMORY MANAGEMENT
▸ Separation of process address spaces
▸ Protection and access control
▸ Automatic allocation and management
▸ Long-term storage management
TYPICALLY MET WITH VIRTUAL
MEMORY
VIRTUAL MEMORY
▸ Physical memory [RAM]: limited, shared
▸ VM allows programmers to work with independent address spaces
▸ Parts of process address space may be in RAM, parts on disk
▸ If required, VM must also allow individual processes to share regions of memory
VIRTUAL MEMORY - PAGING
▸ Process view: main memory consists of a number of fixed-size blocks, called pages
▸ Main memory consists of correspondingly sized memory blocks called frames
▸ Virtual address has two components: a page number and an offset within the page
▸ A page may be located in any frame in main memory
VIRTUAL MEMORY - ADDRESSING
Image courtesy: Fig. 2.10 Operating Systems: Internals and Design Principles by William Stallings, 9th Edition
FILE SYSTEM
▸ Implements long-term store
▸ Information stored in named objects called files
▸ Hierarchical structure: directories, subdirectories, files
INFORMATION PROTECTION AND SECURITY
▸ Access control
▸ regulate user access to the system
▸ Information flow control
▸ regulate flow of data within the system and its delivery to programs/processes
▸ Certification
▸ proving that access and flow control perform according to specifications
SCHEDULING AND RESOURCE MANAGEMENT
▸ General situation: K resources, N processes wishing to use resources
▸ Need to decide who gets what and when
▸ Objectives:
▸ Fairness
▸ Differential responsiveness
▸ Efficiency
05-OS-CONCEPTS
SYSTEM CALLS
https://pxhere.com/en/photo/1449809
WHAT IS A SYSTEM CALL?
▸ A call into the operating system!
▸ Meaning:
▸ Switching from user to kernel mode
▸ Cost?
▸ Need to preserve all state of calling entity
SYSTEM CALL - EXAMPLEcount = read(fd, &buf, n);
1. User program a. Push n b. Push &buf c. Push fd d. Call “read” (go to 2) e. ….
2. Library Set up trap a. Put code for “read” in relevant register b. Trap (go to 3) c. Return to 1.e
3. In kernel: a. Dispatch b. Return to 2.c
SYSTEM CALL - PROCESS MANAGEMENT
pid = fork(); pid = waitpid(pid, &statloc, options); rc = execve(name, argv, environp); exit(status);
SYSTEM CALL - FILE MANAGEMENT
fd = open(file, flags, mode); fd = open(“./fubar”, O_RDWR); rc = close(fd); n = read(fd, buf, n); n = write(fd, buf, n); position = lseek(fd, offset, whence); rc = stat(name, &buf);
SYSTEM CALL - HELP
▸ Manual 2 contains information on all system calls
▸ man 2
▸ See “man man” for information on the un*x manual
▸ Use “apropos ” to hunt around for stuff