What is an operating system History of operating systems The operating system zoo Computer hardware review Operating system concepts System calls Bài giảng nhập môn điện toán Hệ điều hành Bài giảng nhập môn điện toán Hệ điều hành
Trang 1Phần 1: Hệ điều hành
Chương 3
1 What is an operating system
2 History of operating systems
3 The operating system zoo
4 Computer hardware review
5 Operating system concepts
6 System calls
Trang 2Tài liệu tham khảo: chương 1 của quyển
Andrew S Tanenbaum: Modern Operating Systems,
2 nd ed, Prentice Hall
http://www.prenhall.com/divisions/esm/app/author_tanenbaum/custom/mos2e/
Trang 3Giới thiệu
• A computer system consists of
– hardware
– system programs
Trang 4Hệ điều hành là gì?
• It is an extended machine
– Hides the messy details which must be performed
– Presents user with a virtual machine, easier to use
(by using system calls)
• It is a resource manager
– Multiplexing the resource in time: each program
gets time with the resource, e.g CPU, printer
– Multiplexing the resource in space: each program
gets space on the resource, e.g memory, disk
Trang 5Lịch sử hệ điều hành
• First generation 1945 - 1955
– vacuum tubes, plug boards
– Inventors: Aiken (USA), Zuse (Germany)
• Second generation 1955 - 1965
– transistors
– batch systems
• Third generation 1965 – 1980
– ICs (Integrated Circuits)
– multiprogramming, spooling, time-sharing
• Fourth generation 1980 – present
– LSI (Large Scale Integration)
– Hệ điều hành cho PC
Trang 6Lịch sử hệ điều hành
Thế hệ thứ 2
Early batch system (hệ thống xử lý bó)
– bring cards to 1401
– read cards to tape
– put tape on 7094 that does computing
–
Trang 7Lịch sử hệ điều hành
Thế hệ thứ 2
Structure of a typical FMS job
(FMS: Fortran Monitor System, hệ điều hành của IBM cho mainframe 7094)
Trang 9– DOS (Disk Operating System)
– MS-DOS (Microsoft Disk Operating System)
• 1983, IBM PC/AT (Intel 80286 CPU)
• 1985-1995, Windows on top of MS-DOS
• Pentium PC
– UNIX, Linux, Windows 2000
– X Windows system (UNIX, Linux)
Trang 10The Operating System Zoo
• Mainframe operating systems High-end Web servers
– OS/390
• Server operating systems Web service, file service
– UNIX, Linux, Windows 2000
• Multiprocessor operating systems
• Personal computer operating systems
– Linux, Windows XP, Macintosh
• Real-time operating systems Control systems
– VxWorks, QNX
• Embedded operating systems Mobile phones
– uCLinux, PalmOS, Windows CE
• Smart card operating systems Smart cards
Trang 11Computer Hardware Review
Các thành phần của một PC đơn giản
Monitor
Bus
Trang 12Computer Hardware Review
Trang 13Computer Hardware Review
Memory (1)
Typical memory hierarchy
numbers shown are rough approximations
Trang 14Computer Hardware Review
Memory (2)
Cấu trúc của một ổ đĩa cứng
Trang 15Computer Hardware Review
Memory (3)
Một cặp base-limit Hai cặp base-limit
Trang 16Computer Hardware Review
Trang 17Computer Hardware Review
Buses
Cấu trúc của một hệ thống Pentium
IDE bus SCSI bus
Trang 18Các ý niệm chủ đạo trong hệ điều hành
• Quá trình (process)
• Deadlock
• Quản lý bộ nhớ (memory management)
• Nhập/xuất dữ liệu (input/output)
• Tập tin (file)
• An ninh dữ liệu (security)
• The shell
Trang 19Các ý niệm chủ đạo trong hệ điều hành
Quá trình
Một cây quá trình (process tree)
– A đã tạo hai quá trình con, B và C
– B đã tạo ba quá trình con, D, E, và F
Quá trình là một chương trình đang thực thi
Trang 20Các ý niệm chủ đạo trong hệ điều hành
Deadlocks
• Khi hai hay nhiều quá trình tương tác với nhau thì
chúng có thể lâm vào tình trạng deadlock
– Ví dụ: một máy tính với một ổ băng từ và một ổ ghi
CD Hai quá trình A và B muốn ghi lên CD từ dữ liệu
trên băng từ
• Quá trình A yêu cầu và được cấp phát ổ băng từ
• Quá trình B yêu cầu và được cấp phát ổ ghi CD
• Quá trình A yêu cầu ổ ghi CD, bị tạm dừng
• Quá trình B yêu cầu ổ băng từ, bị tạm dừng
Trang 21Các ý niệm chủ đạo trong hệ điều hành
Trang 22Các ý niệm chủ đạo trong hệ điều hành
Files (2)
• Before mounting (gắn),
– files on floppy are inaccessible
• After mounting floppy on b,
– files on floppy are part of file hierarchy
Trong UNIX
Floppy disk
Trang 23Các ý niệm chủ đạo trong hệ điều hành
Files (3)
Two processes connected by a pipe
Trong UNIX
Trang 24Các ý niệm chủ đạo trong hệ điều hành
Shell
• Ví dụ một shell: UNIX command interpreter
– Là chương trình đợi và nhận lệnh của người dùng
từ terminal, gọi system call tương ứng với lệnh
shell không phải là một phần của hệ điều hành!
Trang 25System Calls
Process Management
Trang 26System CallsProcess Management (3)
Processes have three segments: text, data, stack
Trong UNIX
Trang 27System Calls
File Management
(file: tập tin)
Trang 28System Calls
Directory Management
(directory: thư mục)
Trang 29System CallsDirectory Management (2)
(a) File system before the mount(b) File system after the mount
Trong UNIX
Trang 30System Calls
Miscellaneous Tasks
Trang 31System CallsThe Windows Win32 API
Trang 32Metric Units
The metric prefixes
Trang 33Quá trình
Nói thêm về
Trang 34Mô hình của quá trình
(a) Multiprogramming of four programs
(b) Conceptual model of 4 independent, sequential processes
(c) Only one program active at any instant
Mô hình: kết quả của sự trừu tượng hóa (rút trích các thông tin chính yếu),
thường được biểu diễn bằng một sơ đồ.
Trang 35Tạo quá trình
Các biến cố chính gây ra việc tạo quá trình
1 System initialization
2 Execution of a process creation system
call by a running process
3 User request to create a new process
4 Initiation of a batch job
Trang 36Sự chấm dứt của quá trình
Quá trình chấm dứt dưới một trong các
điều kiện sau
1 Normal exit (voluntary, tự ý)
2 Error exit (voluntary)
3 Fatal error (involuntary, không tự ý)
4 Killed by another process (involuntary)
Trang 37Process Hierarchies
• Parent creates a child process, child processes
can create its own process
– Forms a hierarchy
– UNIX calls this a "process group"
• Windows has no concept of process hierarchy
– all processes are created equal
Trong UNIX
Trang 38Các trạng thái của quá trình (1)
• Possible process states
Trang 39Các trạng thái của quá trình (2)
• Lowest layer of process-structured OS
– handles interrupts, scheduling
• Above that layer are sequential processes
Trang 41Hiện thực quá trình (2)
Skeleton of what lowest level of OS does when an
interrupt occurs
Trang 42Định thời
Nói thêm về
Trang 43Giới thiệu về định thời
Mục tiêu của giải thuật định thời dưới các tình huống khác nhau
(Hệ thống tương tác)
(Hệ thống thời gian thực) (Hệ thống xử lý bó)
Trang 44Định thời trong hệ thống xử lý bó
An example of shortest job first scheduling
(a) Running four jobs in the original order
(b) Running them in shortest job first order
Đơn vị: phút
Trang 45Định thời trong hệ thống tương tác (1)
Round Robin Scheduling (Định thời xoay vòng)
(a) list of runnable processes
(b) list of runnable processes after B uses up its time
quantum
Trang 46Định thời trong hệ thống tương tác (2)
A scheduling algorithm with four priority classes:
- Round-robin scheduling within each class
- Run the processes of the higher priority classes first
Trang 48– small amount of fast, expensive memory – cache
– some medium-speed, medium-price main memory
– gigabytes of slow, cheap disk storage
• Memory manager handles the memory hierarchy
Trang 49Basic Memory Management i.e without Swapping or Paging
• Monoprogramming: three simple ways of organizing
memory with an operating system and one user process
Trang 50Multiprogramming with Fixed Partitions
Fixed memory partitions
(a) separate input queues for each partition
Trang 51Memory allocation changes as
– processes come into memory: process A is swapped in from disk,
Fig (g)
– leave memory: process A is swapped out to disk, Fig (d)
Shaded regions are unused memory
Trang 52Bộ nhớ ảo
Phân trang (Paging) (1)
The position and function of the MMU
(Memory Management Unit)
Bộ nhớ ảo: programs may be only partially in main memory
Trang 54Bảng các trang (Page table)
Trang 55Phân đoạn bộ nhớ (1)
• One-dimensional address space with growing tables
Tables during a compilation
Trang 56Phân đoạn bộ nhớ (2)
Trang 57Phân đoạn bộ nhớ (3)
Trang 58Implementation of Segmentation
• Paging the segments: the virtual memory on
the Intel Pentium
Trang 59Hệ thống file
Nói thêm về
• Files
• Directories
• File system implementation
• Example file systems
Trang 60Long-term Information Storage
Yêu cầu đặt ra cho việc lưu trữ thông tin lâu dài
• Must be possible to store large amounts of data
• Information stored must survive the termination of
the process using it
• Multiple processes must be able to access the
information concurrently
Lời giải: lưu thông tin trên đĩa cứng (hay CD-ROM,…)
dưới dạng các tập tin (file).
Trang 61File, dưới cái nhìn của người sử dụng
Trang 62File Naming
Typical file extensions
Trang 63File Structure
Three kinds of files
(a) byte sequence
(b) record sequence
Trang 64File Types
(a) An executable file (b) An archive
Trang 65Truy cập file (File Access)
• Sequential access
– read all bytes/records from the beginning
– cannot jump around, could rewind or back up
– convenient when medium was mag tape
• Random access
– bytes/records read in any order
– essential for data base systems
– read can be …
• move file marker (seek), then read or …
• read and then move file marker
Trang 66File Attributes
Possible file attributes
Trang 67Các thao tác lên tập tin
Trang 68An Example Program Using File System Calls (1/2)
Trang 69An Example Program Using File System Calls (2/2)
Trang 70Directories (Folders)
Single-Level Directory Systems
• Example of a single-level directory system that
– contains 4 files
– owned by 3 different people, A, B, and C
• Được sử dụng trên máy CDC 6600
Trang 71Two-level Directory Systems
Letters indicate owners of the directories and files
Trang 72Hierarchical Directory Systems
A hierarchical directory system
Trang 73A UNIX directory tree
Path names cho file trong
một directory tree
/usr/lib/dict
Trang 74Các thao tác lên thư mục
Trang 75File và directory dưới cái nhìn của người hiện
thực
• Layout của file system
• Hiện thực file
• Hiện thực directory
Trang 76File System Implementation
A possible file system layout
Trang 77Implementing Files (1)
(a) Contiguous allocation of disk space for 7 files
(b) State of the disk after files D and E have been removed
Trang 78Implementing Files (2)
An example i-node
Trang 79Implementing Directories
(a) A simple directory
- fixed size entries
- disk addresses and attributes in directory entry
(b) Directory in which each entry just refers to an i-node
Trang 80The MS-DOS File System
The MS-DOS directory entry
Trang 81The UNIX V7 File System (1)
A UNIX V7 directory entry
Trang 82The UNIX V7 File System (2)
A UNIX i-node
Trang 83The UNIX V7 File System (3)
The steps in looking up /usr/ast/mbox