Unit 3. Operating System
• 3.1 Structure
• 3.2 Device Management and Configuration
• 3.3 Resource sharing
• 3.4 File Systems
3.3 Resource sharing
Resource Sharing 资源共享
• Multitasking （多任务） is sharing the
processor so that several tasks appear to
execute simultaneously on a single CPU.
• Resources like memory, files, and printers
can be shared.
3.3.1 Managing Memory
• Processes shares the available memory on a computer
– Executable programs written in binary machine code
contains instructions and data whose storage locations
are indicated by memory addresses.
– Relocation （重定位） scheme allows the computer to
load multiple programs in memory
– In a virtual memory system, system juggles memory
pages （内存页面） between RAM and disk if there is
no sufficient RAM
• Executable programs written in binary machine
code contains instructions and data whose
storage locations are indicated by memory
• Any memory location that contains an address is
specially marked in a binary file.
• When a user runs the program
– OS allocates memory for it and loads into the
allocated memory area.
– OS updates all the memory references so that they
point to the correct locations.
0 逻辑地址空间 物理地址空间
Load A data1 Load A 200
Load A 200
200 1200 。
data1 3456 3456
逻辑地址空间 BR 物理地址空间
LOAD A 200 200 + 1100
• Advantages :
– Simple to implement
– Does not require any change in the hardware
– Memory allocated to program should be contiguous
– Size of running program is limited to the amount of
physical memory installed on the machine
Virtual Memory 虚拟内存
– Typical PC has 256MB memory or more.
– Some memory are assigned to the OS and the
remainder for user programs.
– The kernel allocates memory and keeps track of the
memory spaces used by each program.
Virtual Memory (Cont.)
• To increase program flexibility, virtual memory scheme is
used by Windows and Linux.
– Using the virtual memory scheme, a small amount of
RAM is required for a program to run, and the rest of
the program’s address space is kept on the disk.
– In a system that uses virtual memory, every program
runs in its own private address space.
– Virtual address space can be larger than processor’s
Virtual Memory (cont.)
• In virtual memory scheme, memory is divided into pages 页面
– Page is the smallest unit of memory allocated for a program.
– On Pentium platforms, a page is 4 KB.
• A processor works in two modes, real and virtual modes.
– In real mode 物理模式, addresses refer to the physical
locations in RAM.
• Only the kernel runs in real mode.
– In virtual mode 虚拟模式, a page table provides a mapping
between each physical address and virtual address.
• For every physical location in RAM, there is an entry in the
• A page table 页表 is used for every program maintained by
• User Programs are not aware of all the virtual memory scheme
Page Fault 缺页中断
• Entire program is not loaded into the memory at once.
• For the pages decided not to load, there is a special
marker indicating “PAGE NOT IN RAM”
• Page Fault:
– Generated when a memory translation circuitry
checks the page table and finds a “NOT IN RAM”
– This is a kind of interrupt and processor stops
executing the user program.
– Control is passed to the Kernel.
– Kernel checks where the page fault came from and
loads the specific program, allocating needed RAM.
状态 状态 阻塞队列
塞 绪 作业调度 后备作业队列
Virtual Memory (continued)
– The program does not need to be loaded
contiguously into RAM.
– The program does not need to be loaded completely
– The program does not need to start at a specific
– Can slow access to data because it is stored on the
hard drive which is significantly slower than physical
– Keeps the hard disk busy, delaying access to other
Virtual Memory Layout
address zero is reserved and
made unreadable to catch the
common bug of trying to use a
NULL pointer to access data
Machine code instruction
dynamically linked shared libraries
in some systems, the operating
system or operating system kernel
becomes part of an application's
memory during system calls.
3.3.2 Resource Sharing: Files
• Files are shared between applications and
users in a networking environment.
• OS defines a set of permissions for files to
prevent unauthorized access to files.
• Permissions include:
– Read access读访问: allows user to read a file
– Write access写访问: allows user to modify or delete
– Execute access执行访问: allows user to perform
special operations such as viewing the contents of a
directory or executing a program
Resource Sharing - Printers
• Can be shared among applications, users, and machines
• Files to be printed are sent to a print server, which
maintains a list of files to be printed
• Server processes one request for printing at a time
• Print requests are stored on a disk in a process called
• Spooling allows the process issuing the print to continue
with other processes.
• If a printer is connected to a network, print requests from
other machines on the same network can be processed.
• (Simultaneous Peripheral Operations On Line，假脱机工
作方式，又称排队转储技术 ) The overlapping of low-
speed operations with normal processing.
• It originated with mainframes in order to optimize slow
operations such as reading cards and printing.
• Card input was read onto disk and printer output was
stored on disk. In that way, the actual business data
processing was done at high speed, since all I/O was on
输入设备 I/O缓冲区 输出设备
道 进程 进程 道
输入井、输出井 输入进程、输出进程 I/O缓冲区
用户进程 注： 数据流
卡 SPOOLing 印
机 井管理程序 机
SPOOLing 技 术 实 现 原 理 示 意 图
Resource Sharing: Monitor,
Keyboard, and Mouse
• Monitor, keyboard, and mouse are shared when many
tasks are running at the same time.
• This function is a part of the OS known as Window
• Tasks are not displayed on the monitor directly.
• Each task has one or more windows associated with it for
reading and writing data through the windows.
• Window System control the task’s window display.
• User can change the arrangement of window by resizing,
minimizing, or maximizing the window.
3.4 File Systems
3.4.1 File Systems 文件系统
• A file system defines the structure and the rules
used to read, write, and maintain information
stored on a disk.
• Which system used is determined by;
– Security needs
– Need for a dual-booting system
• System that an operating system or program uses to organize
and keep track of files.
• A file 文件is a named collection of data existing on a storage
• Filename 文件名 is a unique set of letters and numbers that
identifies a file and describes the file contents.
• File extensions 文件扩展名 indicate the category to which the
file belongs, preceded with a dot.
• The maximum number of characters that a file name can have is
different for different operating systems.
• Wildcards 通配符 are used to represent unknown group of
characters in the filename and the extension.
– For example, “newfile*” means all the files whose name begin with
“newfile” followed by whatever characters in the file name
File Systems (continued)
• Files can be of two types
– An executable file可执行文件 containing program instructions that
tell a computer how to perform a specific task.
– Data file数据文件 containing words, numbers, or pictures that can be
viewed, edited, saved, sent, or printed.
• Filename extensions fall into 2 categories:
– Generic filename extension通用扩展名: indicates the general type
of data contained in a file, which can be opened with several
software packages (e.g .txt)
– Application-specific filename extension专用扩展名: associated with
specific application software and the application used to create the
file (e.g. .doc, .ppt)
• Other type of files are essential for software and
hardware operations (e.g. .bat, .sys .cfg, .dll).
• File manager utility software helps us locate, rename,
move, copy, and delete files (e.g. Internet Explorer).
• Device Letters are identifications for storage devices such
as the floppy disk drive, the hard disk drive, and CD-ROM
or DVD drives.
• Operating system maintains list of all the files in a
“directory” for each disk.
• A directory路径 contains all the information about the file
including the filename, filename extension, date and time
the file was created, and the file size.
• Main directory: root directory that contains useful list of all
the files within the directory.
• Folder gives the file system a hierarchical
structure, like a family tree.
• The file system will not permit two items in a
folder to have the same name.
• Folder names usually do not have a file extension
• Folders are housed in the computer drive.
• A computer can have many drives, drive A, drive
C, drive D, drive E, etc.
• One way to access the drives is by double-
clicking on the icon named "My Computer" on
• Operating system maintains list of all the files in a
“directory” for each disk.
• File specification, also called a path, includes the drive letter,
folder, Filename and an Extension that identifies a file.
– For example: C:\Ssd2\Text\demo.doc.
Drive Letter Folder Subfolder Filename extension
• Names of folders are differentiated from drive letters and files
separated by the backslash symbol “\” (Dos & Windows).
File Names and Types
.txt Plain text file .doc Microsoft Word document
HTML (Hypertext Markup Microsoft Excel
Language) document spreadsheet
JPEG image (Joint
GIF image (Graphic
.gif .jpg Photographic Experts
Executable file (binary
.wav Sound file .exe
MS-DOS executable Driver (for a peripheral
("command" file) device)
Batch (script) file for the
DOS command interpreter
3.4.2 File Allocation Table
• The operating system keeps track of data
(documents, pictures, etc.) by placing it into a file.
• To store and retrieve files:
– Disk divided into tracks
– Tracks are divided into sectors
– Sectors grouped into clusters
File Allocation Table
• Hard disks are divided into tracks and sectors.
• Each sector contains 512 bytes. (NTFS does allow
you to change this number.)
• Small files occupy fraction of sectors, the remaining
sectors are called Slack Space 松散空间.
• Large files of ten million bytes require thousands of
sectors spread across multiple tracks.
• Sectors are grouped into clusters 簇.
Tracks and sectors on a disk
Example: 3 ½ high density diskette
• 80 concentric tracks
• Each track is divided into 18 sectors.
• Each sector in turn contains 512 bytes.
• So let’s see . . . . .
80 tracks X 18 sectors X 2 sides X 512 bytes =
1,474,560 bytes = 1.4 MB
• A cluster 簇, also known as an allocation unit 分配
单元, consists of one or more sectors of storage
space, and represents the minimum amount of
space that an operating system allocates when
saving the contents of a file to a disk.
• The number of sectors per cluster is dependent on
– Type of disk (floppy disk, hard disk)
– Version of operating systems
– Size of disk
• The number of clusters per disk is determined by
the filing system (FAT 16, FAT 32 or NTFS).
• Each cluster contains 4,8,16,32,64 adjacent
• Cluster size depends on drive capacity.
• This is the smallest unit of storage the operating
system can manage.
– For example, on a PC with a 200MB hard disk, the
smallest cluster is eight sectors (8 x 512 bytes) or 4K.
On a 2GB disk, the cluster is 32K. That means a 1K
file takes up 32K on the disk, wasting an inordinate
amount of space.
– In mid-1996, the Windows 95 that came with new PCs
(Win95B) introduced the FAT32 32-bit file allocation
table which decreased the cluster size to 4K.
Slack Space (松散空间 )
• File size = 2KB
• Hard drive = 2GB
– FAT 16 – the file will use 1 cluster which is 64 sectors,
• 64 X 512 bytes per sector = 32KB – 2KB = 30KB slack space
– FAT 32 – the file will use 1 clusters which is 8 sectors,
• 8 X 512 bytes per sector = 4KB – 2KB = 2KB slack space
– NTFS – the file will use 1 cluster which is 4 sectors,
• 4 X 512 bytes per sector = 2KB – 2KB = 0 slack space
• So, what does this all mean to us, as Windows XP
– The bigger your disk – the bigger your clusters (because
there is a maximum number of clusters per disk).
– One way to help alleviate the problem of slack space is
to partition the hard drive into smaller “drives”.
Reducing the drive size will reduce the cluster size.
File Allocation Table
• FAT 文件分区表: Contains an entry for every
cluster on the disk.
• All clusters in a file are chained together.
FAT Gives each cluster the number of the
next cluster for that file
• All the clusters can be found when the first
cluster is known.
FAT File Systems
• FAT 16 – oldest, created for DOS, supported by most
OSs’, cannot be installed on partitions larger than 4 GB
• FAT 32 – supports disks up to 2TB in size, compatible
with Windows 98 and up
– NOTE: Microsoft Windows 2000, XP only supports
FAT32 partitions up to a size of 32 GB.
– File on this File System up to 4GB.
• New Technology File System 新技术文件系统
• An optional file system for Windows NT, 2000
and XP operating systems. NTFS is the more
advanced file system, compared to FAT32.
• It improves performance and is required in order
to implement numerous security and
administrative features in the OS.
– For example, NTFS supports Active Directory
domain names and provides file encryption.
Permissions can be set at the file level rather than by
folder, and individual users can be assigned disk
– No limit to the sector size
– better file security (Encrypting File System) :
enables data to be encrypted as it is saved to
– disk compression
– supports the Unicode character set and allows
file names up to 255 characters in length.
– File and Folder Permissions
– reliability and stability.
– logging features: NTFS is designed to log
activity and recover on the fly from hard disk
– Cluster size is variable depending on the size
of the logical drives.
– More efficient allocation of disk space
– Supports data access control and ownership
privileges to restrict unauthorized access to
data in a multi-user environment
– NTFS volumes can not be accessed by DOS,
or Windows 95 or Windows 98.
• Compact Disc File System (CDFS 光盘文件系统)
– recording and naming files on a CD
• Universal Disk Format (UDF 通用磁盘格式)
– Universal Disk Format (UDF) is a file system defined
by the Optical Storage Technology Association.
– UDF is the successor to the ISO 9660 (CDFS) format.
– UDF is used for removable media such as DVD, CD,
compact disc–recordable (CD-R), compact disc–
rewritable (CD-RW), write once, read many (WORM)
Default Cluster Sizes for Volumes with
Windows XP Professional File Systems
Which file system should you use?
• If your computer runs only Windows XP
and you do not plan to install other OS,
• However if you want to use other OS and
you want to access the volumes you must
use FAT16 or FAT32
OS and File System Compatibility
Operating System FAT16 FAT32 NTFS
Windows 95, 98, ME
(prior to OSR2)
• For more information about file system, access:
END of Unit 3