Operating Systems
-
Upload
daryl-rosales -
Category
Documents
-
view
33 -
download
0
description
Transcript of Operating Systems
![Page 1: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/1.jpg)
Operating Systems
國立清華大學資訊工程學系
CS1356 資訊工程導論
112/04/20
![Page 2: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/2.jpg)
How does a computer start executing?
![Page 3: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/3.jpg)
3
Simple Answer
• The program counter is initiated with a particular address in a special memory when the computer is powered on– That address is start of a (special) program
to bring up other programs and the system– But DRAM is volatile!– So, we use read-only memory (ROM)
![Page 4: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/4.jpg)
Suppose the computer runs only one program
…Full control of everything, e.g. CPU
Manage everything
![Page 5: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/5.jpg)
Suppose the computer runs many programs …
•How do they get executed?
•How do they get the most important resource – the CPU?
![Page 6: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/6.jpg)
6
Grabbing the CPU
• In a single-processor computer, only one CPU to be shared by all programs
• Who can get the microphone?(analogy by 資工四年清班張明禾 )
![Page 7: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/7.jpg)
7
We Need a Chairperson!
• The chairperson decides who gets the microphone to speak next
• Two ways to schedule:– Let each speaker talk until he/she finishes– “Interrupts” the speaker to get back the
microphone and turn to another speaker time sharing
![Page 8: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/8.jpg)
8
Chairperson Can Do More
• Which portion of blackboarda speaker can write? memory management
• Who can use 幻燈機 (projector)?– Why not operated by chairperson?– Device driver and management
Chairperson is OS
![Page 9: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/9.jpg)
9
What Is a System?
• A set of interacting, interdependent entities forming an integrated whole. – From Wikipedia
• Five components– Hardware – Software– Data– Procedure– User
System
Hardware
Software
User
Data
Procedure
![Page 10: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/10.jpg)
10
Software Classification
• Operating system is one kind of software
(Fig. 3.3)
![Page 11: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/11.jpg)
11
Operating Systems
• One kind of software that controls the overall operation of a computer – Unix, Sun Solaris– Linux: Ubuntu, Redhat, ...– Microsoft Windows– Apple Mac OS X– Google Chrome OS
![Page 12: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/12.jpg)
12
Outline
• Components and functions
• Process management
• Handling competition for resources
• Security
![Page 13: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/13.jpg)
13
Components and Functions
Shell, kernel, file manager, device drivers, memory manager,
bootstrapping, scheduler, dispatcher
![Page 14: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/14.jpg)
14
Components of OS
• For user: shell, privilege control (security)
• For data: file manager
• For hardware: device manager, memory manager, and boot manager
• For software: – Where to store: file manger, registry– How to execute: scheduler, process manager
![Page 15: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/15.jpg)
15
How about Procedure?
• OS needs to define a set of rules or working flows for users and hardware/ software developers.– For example, you need to double click an icon
to open a program or a file.– Design a simple yet useful procedure for a
complicated system is not an easy job. – This is for books like “How to use
computers?” to talk about
![Page 16: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/16.jpg)
16
Shell
• Shell: an interface between users and the operating system– Text based: 命令提示字元– Graphical user interface
(GUI)• Windows, icons, menus,
pointers (WIMP)• Window manager
(Fig. 3.4)
![Page 17: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/17.jpg)
17
File Manager
• File manager: organizes and maintains the records of files in mass storages
• Hierarchical structure– Directory (or folder), directory path
• File descriptor– File name, extension, size, updated
date, permissions, attributes, …
• File operations– Copy, paste, creation, open…
![Page 18: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/18.jpg)
18
Device Manager
• Communicate with the controllers/devices– Drive the corresponding peripheral devices– Each device driver is uniquely designed for its
particular type of device
![Page 19: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/19.jpg)
19
Memory Manager
• Coordinates the use of memory
• Suppose computer runs only one program– The program can use any part of the main
memory (i.e., DRAM)– What if the program is larger than the memory?
store only the needed portion
– Who makes the move?
![Page 20: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/20.jpg)
20
Memory Manager
• Suppose computer runs many programs at the same time– What if programs are larger than the memory?– Which program uses which part of the
memory?– How to protect they from each other?
All done by OS!
![Page 21: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/21.jpg)
21
Virtual Memory
• Create the illusion of a memory space much larger than physical memory. How?– Store only needed portion in memory and the
remaining in disks– Shuffle portions between memory and disks– Program uses virtual address, while OS does
the mapping
• Paging: memory is grouped into pages to facilitate the mapping and shuffling
![Page 22: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/22.jpg)
22
Example of Paging
• There are 8 pages; each is of 4KB – Main memory is of size 16KB (4 pages)– Programs use virtual
address to access data and code
– OS does the mappingand paging
Disk
Page 0
Page 1
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Virtual address
Main memory
![Page 23: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/23.jpg)
23
Get It Started: Bootstrapping
• Loader: a special program places machine programs to main memory for execution– Think about the problem 2 of homework 3– Usually part of the OS’s scheduler
• Who loads the OS to memory?– A “special memory” that contains a “program”
to load the OS after computer is powered on.
Read-only memory (ROM) Bootstrap
![Page 24: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/24.jpg)
24
The Booting Process
The program counter is initiated with a particular address in ROM where the bootstrap is stored
![Page 25: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/25.jpg)
25
BIOS and Firmware
• The bootstrap program and other basic input/output functions are contained in a special ROM, called BIOS (basic input/output system)
• A program stored in ROM is called firmware– Hardware or software?
![Page 26: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/26.jpg)
26
Process Management
History, today, and future
![Page 27: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/27.jpg)
27
A Program vs. a Process
• Program: a set of instructions, e.g., notepad.c, notepad.exe
• Process: activity of executing a program• A program can be run multiple times, each
instance/activity called a process• Interprocess communication
– The communication between processes (may from running one or more programs)
![Page 28: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/28.jpg)
28
Evolution of Computers
• Batch processing
• Interactive processing: requires real-time processing
• Time-sharing/multitasking: implemented by multiprogramming
• New challenges: multicore processors, and small devices
![Page 29: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/29.jpg)
29
Batch Processing
FIFO: first in first serve
![Page 30: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/30.jpg)
30
Interactive Processing
Text editing, music/movie playing, …
![Page 31: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/31.jpg)
31
Time-sharing/Multitasking
• Time-sharing between process A and process B
(Fig. 3.6)
![Page 32: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/32.jpg)
32
Context (Process State)
• Snapshot of current status of a process– A process identifier, or PID– Register values, Program Counter value– The memory space, I/O, files for the process– Can be saved and resumed as if the process is not
interrupted
• Another meaning: execution state of the process– Ready: ready for execution– Waiting: waiting for some I/O– Complete: finished process
![Page 33: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/33.jpg)
33
Scheduler
• Determines which processes should be considered for execution based on some priorities or concerns– Using process table for administration
• Process table– Ready or waiting– Priority– Non-scheduling information: memory pages,
etc.
![Page 34: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/34.jpg)
34
Dispatcher
• Gives time slices to a process that is ready
• Executes a context switch when the running process’s time slice is over– Time slice: a time segment for each execution– Interrupt: the signal generated by a hardware
timer to indicate the end of a time slice.– The interrupt handler (part of dispatcher)
starts after the interrupt to perform context switch
![Page 35: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/35.jpg)
35
Context Switch (process switch)
1. Get an interrupt from timer
2. Go to the interrupt handlera. Save the context of process A
b. Find a process ready to run(Assume that is process B)
c. Load the context of process B
3. Start (continue) process B
![Page 36: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/36.jpg)
36
Thread
• A task existing within a process that allows multiple independent instances to be executed concurrently– Multiple threads share resources such as
memory, program code, … – Each thread has its own program counter,
registers, and stack (local memory)
• The context switch of threads is much faster than that of processes
![Page 37: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/37.jpg)
37
Exercises
• Suppose an OS allocates time slices in 10 millisecond units and the time required for a context switch is negligible. How many processes can obtain a time slice is one second?
• If it takes one microsecond to perform a context switch and processes use only half of their allotted 10 millisecond time slices, what percent of a CPU’s time is spent performing context switches rather than executing processes?
![Page 38: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/38.jpg)
38
New Challenges
• Multicore processor– A processing system composed of two or
more independent cores (or CPUs), which share resources, such as memory.
• Embedded systems, small devices– A computer system designed to perform one
or a few dedicated functions, often with real-time computing constraints.
![Page 39: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/39.jpg)
39
Multiprocessor Machines
• How to assign tasks to processors?– Load balance problem
• How to use processors to handle one task?– Parallelization, scaling problem
Processor 1
Processor 4
Processor 2
Processor 3
Task 1
Task 2
Task 3
Task 4
Task 5
Task 6
Task 7
Task 8
Task 9
![Page 40: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/40.jpg)
40
OS for Small Devices
• Embedded systems, PDA, mp3 player, cell phone, GPS,…– Limited storage, limited power, – Usually has real time requirement
• Turkey system: store all programs and data in a persistent memory– No BIOS and program loader
![Page 41: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/41.jpg)
41
Handling Competition for Resources
![Page 42: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/42.jpg)
42
Competition for Resources
• What are resources?– CPU, memory, files, peripheral devices, …
• In a multitasking system, resources are shared by processes
• Some resources should not be employed by more than one process simultaneously
– E.g., printer
![Page 43: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/43.jpg)
43
Handling Competitions
• Define critical regions– Critical Region: A group of instructions that
should be executed by only one process at a time
– Mutual exclusion: Requirement for proper implementation of a critical region
![Page 44: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/44.jpg)
44
First Algorithm
• Use a flag (a global memory address)– flag=1: the critical region is occupied – flag=0: no process is in the critical region
• Problem:
– Both processes get into the critical region
if (flag == 0) { flag = 1; /*critical region*/}
Process Aif (flag == 0) { flag = 1; /*critical region*/ }
Process B Context switch to BContext switch to A
![Page 45: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/45.jpg)
45
Solutions
• Testing&setting the flag must be completed w/o interruption (atomic)
1. Use disable_Interrupt() to prevent context switch during the flag test and set process.
2. A machine instruction called “test-and-set” which cannot be interrupted
• Semaphore: a properly implemented flag
Diable_Interrupt();if (flag == 0) { flag = 1; Enable_Interrupt(); / *critical region*/ }Enable_Interrupt();
![Page 46: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/46.jpg)
46
Another Problem: Deadlock
• Example:– A is in critical region 1, and waits to enter
critical region 2– B is in critical region 2, and waits to enter
critical region 1
if (test_set(flag1)) { /*critical region 1*/ while(!test_set(flag2)); /*critical region 2*/ }
Process Aif (test_set(flag2)) { /*critical region 2*/ while (!test_set(flag1)); /*critical region 1*/ }
Process B Context switch to BContext switch to A
![Page 47: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/47.jpg)
47
Conditions for Deadlock
1. Competition for non-sharable resources
2. Resources requested on a partial basis
3. Allocated resources cannot be forcibly retrieved
4. Circular wait
Remove any one of the conditions can resolve the deadlock.
![Page 48: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/48.jpg)
48
Solutions
Which condition is removed?1. Kill one of the process2. Processes need to request all the
required resources at one time3. Spooling
• For example, stores the data to be printed and waits the printer available
4. Divide a file into pieces so that it can be altered by different processes
![Page 49: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/49.jpg)
49
Exercises
• There is a bridge that only allows one car to pass. When two cars meet in the middle, it causes “deadlock”. The following solutions remove which conditions– Do not let a car onto the bridge until the
bridge is empty.– If cars meet, make one of them back up.– Add a second lane to the bridge.
• What’s the drawback of solution 1?
![Page 50: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/50.jpg)
50
Security
![Page 51: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/51.jpg)
51
Security
• Attacks– Malware– Spyware and
phishing– Adware and spam– Abnormal behaviors
• Defenses– User management
• Privilege control
– Protections• Antivirus software• Auditing software• Firewall, spam filter
– Encryption
![Page 52: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/52.jpg)
52
Malware
• Infect programs/computers, erase data, slowdown performance…
• Types – Virus: attached to an existing program
– Worm: a stand alone program
– Trojan horse: disguised as valid files or programs
![Page 53: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/53.jpg)
53
Spyware and Phishing
• Spyware: collects information about users without their knowledge. – Keylogger: log the keys struck on a keyboard– Login sniffing: simulates the login process to
get valid user name and password.– Network sniffing: intercept network messages
• Phishing: acquires information by masquerading as a trustworthy entity in an electronic communication.
![Page 54: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/54.jpg)
54
Adware and Spam
• Adware: automatically plays, displays, or downloads advertisements to a computer after the software is installed on it or while the application is being used.
• Spam: sends unsolicited bulk messages indiscriminately.– Email spam
![Page 55: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/55.jpg)
55
Abnormal Behaviors
• Dictionary attack: trying passwords derived from a list of words in a dictionary.
• Denial of service attack: overloading a computer (server) with messages to make a computer resource unavailable to its intended users.
• Spoofing attack: masquerading as a party other than one’s self
![Page 56: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/56.jpg)
56
User Management
• To protect the computer’s resource from access by unauthorized personnel.
• User authentication process: – Username, password, fingerprint, …
• Super user / administrator / root– A kind of user having higher privilege to
control machines and operating system.
![Page 57: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/57.jpg)
57
Privilege Control
• To prevent malicious programs to execute dangerous instructions.
• Privilege levels: – Nonprivilege mode: only “safe” instructions
• For example, to access some part of memory.
– Privilege mode: all kinds of instructions• Those instructions that can be only executed in the
privilege mode are called privilege instructions.
![Page 58: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/58.jpg)
58
Protections
• Antivirus software: detecting and removing the presence of known viruses and other infections.
• Auditing software: detecting and preventing abnormal situations
• Firewall: filtering messages passing through computers.– Spam filter: firewall for email spam
![Page 59: Operating Systems](https://reader036.fdocuments.net/reader036/viewer/2022062722/56813925550346895da0cc96/html5/thumbnails/59.jpg)
59
Related Courses
• Operation system – 作業系統,計算機系統管理,平行程式
• Security– 計算機系統管理,密碼與網路安全概論
• http://www.wikipedia.org/• Textbook chap3, sec 4.5 (security)
References