The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

OPERATING SYSTEM introduces the design and implementation of operating systems. This course will cover briefly the evolution and major components of operating system. Particular emphasis will be given to three major OS subsystems; memory management, processes management, file systems and operating systems in mobile devices today that supporting distributed systems.

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by rasmaliza.pkt, 2021-09-19 05:33:53

INTRODUCTION TO OPERATING SYSTEM

OPERATING SYSTEM introduces the design and implementation of operating systems. This course will cover briefly the evolution and major components of operating system. Particular emphasis will be given to three major OS subsystems; memory management, processes management, file systems and operating systems in mobile devices today that supporting distributed systems.

2.2 Process Management

Benefit of Multithreads

 Responsiveness -
Multithreading an interactive
application may allow a
program to continue running
even if part of it is blocked or is
performing a lengthy operation,
thereby increasing
responsiveness to the user.

 Resource sharing - Processes
can only share resources
through techniques such as
shared memory and message
passing.

92 48

2.2 Process Management

Benefit of Multithreads

 Economy - Allocating memory
and resources for process
creation is costly. Because
threads share the resources of
the process to which they
belong, it is more economical to
create and context-switch
threads

 Scalability - Can be even
greater in a multiprocessor
architecture, where threads may
be running in parallel on
different processing cores. A
single-threaded process can run
on only one processor,
regardless how many are
available.

93 49

Definition of Deadlock
Deadlock Conditions
Deadlock Solutions

94

2.3 Deadlock

Definition

• A situation that occurs when two programs or devices
are each waiting for a response from the other before
continuing.

• In operating systems, a situation in which two or
more processes are prevented from continuing while
each waits for resources to be freed by the
continuation of the other

• A process requests resources; if the resources are
not available at that time, the process enters a
waiting state. Sometimes, a waiting process is never
again able to change state, because the resources it
has requested are held by other waiting processes.
This situation is called a deadlock

95 51

2.3 Deadlock

Resource Deadlock

• This system is deadlocked because each process holds
a resource being requested by the other process and
neither process is willing to release the resource it
holds

96 52

2.3 Deadlock

Deadlock Conditions

4 Types of Deadlock

1. Mutual exclusion :
only one process at a
time can use a resource

Process A
Process B

t0 t3 t6

2. Hold and wait : a process holding at least one resource
while waiting for another resources.

Holds Holds
Currently I’m Currently I’m using
using a printer a scanner
Process B
Process A
53
97

2.3 Deadlock

Deadlock Conditions

3. No preemption : a process hold a resource for a long
time. Resource can be released only voluntarily by the
process holding it, after that process has completed its
task

Yes! I’m
conquered
this
printer!

Process A

Process B

I need to --wait-- --wait-- --wait-- --wait-- --wait-- --wait-- --wait-- --wait----wait-- --wait-- --wait-- -- t200
wait for a t0 wait--
long time!

98 54

2.3 Deadlock

Deadlock Conditions

4. Circular wait : processes are waiting for resources held
by other processes, which are waiting for other resources

Waiting for

Process A Process B

Waiting for Waiting for

Process D Process C

Waiting for

99 55

2.3 Deadlock

Deadlock Solutions

3 Various Of Deadlock Solutions

a. Prevention and avoidance of deadlock
 Ensure deadlock does not happen
 Use information about resource requests to
dynamically avoid unsafe situations

b. Allow deadlock, detect deadlock and recover
deadlock
 Allow deadlocks, but detect when occur
 Recover and continue

c. Ignore deadlock

100 56



CHAPTER 3

101

CHAPTER 3

This topic gives a description on how the operating
system manages the file system. Discussions on file
organization, file allocation methods, free space
management and backup techniques are covered in
this topic.

Lesson Learning Outcome :
At the end of this chapter, students should be able to:
• Explain file management in operating system
• Explain the protection of file in operating system
• File Access Techniques

102

3.1 File Management
3.2 Protection in File

Management

103

Concepts of File File Allocation
File Access Techniques Methods
Directory Structures
Free Space
Management

104

3.1 File Management

Concept of File

• Computers can store information on various storage
media, such as magnetic disks, magnetic tapes, and
optical disks

• File is a sequence of bits, bytes, lines or records
which is defined by the files creator and user.

• Named collection of data that is manipulated as a
unit

• Reside on secondary storage devices
• Some key concept of file :

 File Attributes (name, type, location, size,
protection, time, date and user identification)

 File Operations (create, write, read, delete,
truncate the files)

 File Types (refer next slide)
 File Structure

105

3.1 File Management

File Types

Executable Exe, com, Ready to run machine language
bin or none program

object Obj, o Compliled, mechine language,
not linked
source C, cc, java,
code perl, asm Source code in various
languages
batch Bat, sh
Commands to the command
markup Xml, html, interpreter
tex
Textual data, documents
Word Xml, rtf,
processor docx Various word-processor formats

106

3.1 File Management

File Types

library Lib, a, so, Libraries of routines for
dll programmers

Print or Gif, pdf, jpg ASCII or binary file in a format
view Rar, zip, tar for printing or viewing

archive Related files groups into one
file, sometimes compressed, for
archiving or storage

mulitmedia Mpeg, mov, Binary file containing audio or
mp3, mp4, A/V information
avi

107

3.1 File Management

File Access Technique

• Concerned with how records are arranged and
characteristics of medium used to store the files

• The manner in which the records of a file are
arranged on secondary storage

3 types of file access
technique

Sequential Indexed
Access Access

Direct
Access

108

3.1 File Management

> File Access Techniques

Sequential Access

Easiest to implement because records are stored &
retrieved serially, one after other.

Information in the file is processed in order, one
record after the other.

This is by far the most common mode of access of
files. For example, computer editors* usually access
files in this fashion.

A read operation reads the next portion of the file
and automatically advances the file pointer.

A write appends to the end of the file and the file
pointer advances to the end of the newly written
material (the new end of file).

109

3.1 File Management

> File Access Techniques

Sequential Access

Such a file can be reset to the beginning, and,

1 on some systems, a program may be able to

skip forward (next) or backward (rewind) n
records, for some integer n.

2 Suited to magnetic tape or backup tape devices

110

3.1 File Management

> File Access Techniques

Direct Access

Give users flexibility of accessing any record in
any order without having to begin search from
beginning of file.

Bytes or records can be read or written in any
order of block

The file is viewed as a numbered sequence of
block or records.

A direct-access file allows random blocks to be
read or written

Direct access files are of great use for
intermediate access to large amounts of
information.

111

3.1 File Management

> File Access Techniques

Sequential Access

1 Sometimes this is implemented by each read
and write operation specifying a position

parameter

2 Suited to hard disk devices

112

3.1 File Management

> File Access Techniques

Indexed Access

Combines best of sequential and direct access.

A file is sorted in ascending order based on a
number of keys (Sequence)

Each disk block may contain a number of a fixed
length logical records

An index table stores the keys of the first block in
each block

We can search the index table to locate the block
that contains the desired record

Example of indexed access is one level B-, B+
or B Tree

113

3.1 File Management

> File Access Techniques

Sequential Access

Indexed access implementation

114

3.1 File Management

Directory Structures

Next, we consider how to store files. There are
typically thousands, millions, even billions of files
within a computer.

Files are stored on random-access storage devices,
including hard disks, optical disks, and solid-state
(memory-based) disks.

4 important directory structures

storage structure directory overview

single-level two-level
directory directory

115

3.1 File Management

> Directory Structures

Storages Structures

A general-purpose computer system has multiple
storage devices, and those devices can be sliced
up into volumes that hold file systems*.

Computer systems may have zero or more file
systems, and the file systems maybe of varying
types.

Example of file system:

A Solaris system may have dozens of file
systems of a dozen different types, as shown
in the file system list in

116

3.1 File Management

> Directory Structures

Storages Structures

B Linux system may have dozens of file
systems of a different types, as shown in
the file system list in

file systems* - A file system typically manages
operations, such as storage management, file
naming, directories/folders, metadata, access
rules and privileges

117

3.1 File Management

> Directory Structures

Storages Structures

The directory can be viewed as a symbol table
that translates file names into their directory
entries.

The directory entries must allow user to insert
entries, to delete entries, to search for a named
entry, and to list all the entries in the directory.

The operations that are to be performed on a
directory:

01 Search for a file
02 Create a file
03 Delete for a file
04 List a directory
05 Rename for a file
06 Traverse the file system

118

3.1 File Management

> Directory Structures

Single Level Directory

The simplest directory structure is the single-level
directory.

All files are contained in the same directory, which
is easy to support and understand.

A single-level directory has significant limitations :

When the number of files
increases
When the system has more
than one user.

04

Since all files are in the same directory, they must
have unique names.

Can leads to confusion of file names
among different users

119

3.1 File Management
> Directory Structures

Single Level Directory

Single-level directory implementation

Even a single user on a single-level directory may
find it difficult to remember the names of all the
files as the number of files increases. It is not
uncommon for a user to have hundreds of files on
one computer system and an equal number of
additional files on another system.

120

3.1 File Management

> Directory Structures

Two Level Directory

The standard solution is to create a separate
directory for each user

Each user has its own user file directory (UFD) and
have similar structures, but each lists only the files
of a single user.

When a user job starts or a user logs in, the
system’s master file directory (MFD) is searched.

The MFD is indexed by user name or account
number, and each entry points to the UFD for
that user.

Different users may have files with the same
name, as long as all the file names within each
UFD are unique

121

3.1 File Management

> Directory Structures

Two Level Directory

To create a file for a user, the operating system
searches only that user’s UFD to ascertain
whether another file of that name exists.

To delete a file, the operating system confines its
search to the local UFD; thus, it cannot accidentally
delete another user’s file that has the same name.

122

3.1 File Management

File Allocation Methods

The main problem is how to allocate space to
these files so that disk space is utilized effectively
and files can be accessed quickly.

3 major methods of allocating disk
space are in wide use :

contiguous linked
indexed

Each method has advantages and disadvantages.

Some systems support all three, it is more
common for a system to use one method for
all files within a file-system type.

123

3.1 File Management

> File Allocation Methods

Contiguous Allocation

Requires that each file occupy a set of contiguous
blocks on the disk

The directory entry for each file indicates the address
of the starting block and the length of the area
allocated for this file.

Accessing a file that has been allocated contiguously
is easy.

For sequential access, the file system remembers the
disk address of the last block referenced

Both sequential and direct access can be supported
by contiguous allocation

Implementation

124

3.1 File Management

> File Allocation Methods

Contiguous Allocation

Advantages

Easy to implement
Read performance is excellent

Disadvantages

Hard to find space for a new file

Problem of external fragmentation -
as files are allocated and deleted, the
free disk space is broken into little
pieces
Need to compacts all free space into
one contiguous space – the cost of
this compaction is time

Will need to manage free lists

125

3.1 File Management

> File Allocation Methods

Linked Allocation

Solves all problems of contiguous allocation.

With linked allocation, each file is a linked list of
disk blocks; the disk blocks may be scattered
anywhere on the disk.

The directory contains a pointer to the first and
last blocks of the file. For example, a file of five
blocks might start at block 9 and continue at block
16, then block 1, then block 10, and finally block
25.

Each block contains a pointer to the next block.

These pointers are not made available to the user.

A file can continue to grow as long as free blocks
are available.

126

3.1 File Management

> File Allocation Methods

Linked Allocation

Implementation

127

3.1 File Management

> File Allocation Methods

Linked Allocation

Advantages

There is no external fragmentation with
linked allocation, and any free block on
the free-space list can be used to
satisfy a request

Never necessary to compact disk
space

Disadvantages

Major problem : can be
used effectively only for
sequential-access files

Inefficient to support a direct-
access capability because required
a disk seek.

Space required for the pointers

128

3.1 File Management

> File Allocation Methods

Indexed Allocation

Linked allocation solves the external-fragmentation
and size-declaration problems of contiguous
allocation but cannot support efficient direct
access

Indexed allocation solves this problem by bringing
all the pointers together into one location: the
index block.

Each file has its own index block, which is an array
of disk-block addresses.

Indexed allocation supports direct access, without
suffering from external fragmentation, because any
free block on the disk can satisfy a request for more
space.

Indexed allocation does suffer from wasted space

129

3.1 File Management

> File Allocation Methods

Indexed Allocation

Implementation

130

3.1 File Management

> File Allocation Methods

Indexed Allocation

Advantages

There is no external fragmentation with
linked allocation, and any free block on
the free-space list can be used to
satisfy a request

Never necessary to compact disk
space

Disadvantages

The pointers use an additional
disk block

131

3.1 File Management

Free Space Management

Since disk space is limited, we need to reuse the
space from deleted files for new files, if possible.
(Write-once optical disks allow only one write to
any given sector, and thus reuse is not physically
possible).

To keep track of free disk space, the system
maintains a free-space list. The free-space list
records all free disk.

2 free space list techniques :

bit vector / bit mapped

linked list

132

3.1 File Management

> Free Space Management

Bit Vector / Bit Mapped

The free space list is implemented as
bit map/bit vector.

Each block is represent by 1 bit:
• If a block is free, the bit is 1. If a block is allocated,

the bit is 0.

Assume the following blocks a allocated, the rest free
• 2,3,4,5,8,9,10,11,12,13,17,18,25,26 and 27

The free-space bit map would be
• 0011110011111100011000000111000000…..

Advantages:
• Relatively simple
• Efficiency to find the first free

blocks or n consecutive free blocks

on the disk.

133

3.1 File Management

> Free Space Management

Linked List

• Link together all the free disk blocks.
• Keeping a pointer to the first free block in a

special location on the disk and caching it in
memory.
• The first block contains a pointer to the next
free disk block
• Using this scheme, it isn’t easy to traverse the
free list.

134

Type of File Operations
Access Control
Prevent Data Loss

135

3.2 Protection in File Management

Type of File Operations

• The need to protect files is a direct result of the
ability to access files.

• We could provide complete protection by
prohibiting access.

• Protection mechanisms provide controlled access
by limiting the types of file access that can be
made.

• Access is permitted or denied depending on several
types of operations can be controlled:
 Read -> Read from the file.
 Write -> Write or rewrite the file.
 Execute -> Load the file into
memory and execute it.
 Append -> Write new
information at the end of the
file.
 Delete -> Delete the file and
free its space for possible reuse.
 List -> List the name and
attributes of the file.

136

3.2 Protection in File Management

Access Control

• The most common approach to the protection
problem is to make access dependent on the
identity of the user. Different users may need
different types of access to a file or directory.

• The most general scheme to implement identity
dependent access is :
 Access control list (ACL) -
specifying user names and the
types of access allowed for each
user. operating system checks the
access list associated with that file.
If that user is listed for the
requested access, the access is
allowed.
 Capability list - is a list of objects
together with the operations
allowed on those objects. An
object is often represented by its
physical name or address

137

3.2 Protection in File Management Access Control

>

Access Control List

Pascal R/W R R -

Cygan R R/W R

Fabrigas R R R/W R

Senderos R/W R/W R

User File player.txt salary.doc image.jpg match.xls

• We can express the same access constraints given
in the above matrix with the by attaching the
following access control lists to the four files
shown

 Player -- Pascal:R/W, Cygan:R, Fabrigas:R
 Salary -- Pascal:R, Cygan:R/W, Fabrigas:R,

Senderos:R/W
 Image -- Pascal:R, Fabrigas:R/W,

Senderos:R/W
 Match -- Cygan:R, Fabrigas:R, Senderos:R

• With access control lists, that we only list users
who have access to some file, omitting from the
list those users who have no access

138

3.2 Protection in File Management Access Control

>

Capability List

Pascal R/W R R -

Cygan R R/W R

Fabrigas R R R/W R

Senderos R/W R/W R

User File player.txt salary.doc image.jpg match.xls

• The corresponding capability list representation
of this access matrix is:

 Pascal-- player:R/W, salary:R, image:R
 Cygan-- player:R, salary:R/W, match:R
 Fabrigas-- player:R, salary:R, image:R/W,

match:R
 Senderos-- salary:R/W, image:R/W,

match:R

• With capability lists, that we only list files that
can be access by the user, omitting from the list
those users who have no access

139

3.2 Protection in File Management

Prevent Data Loss

1 Backup techniques

• Store redundant copies of information
• 2 types of backup techniques

 Physical backups - duplicate a
storage device’s data at the bit level

 Logical backups - store file system
data and its logical structure,
determine which files need to be
backed up, then write these files to a
backup device in a common, often
compressed, archival format

2 Recovery techniques

• Enable the system to restore data after a
system failure

3 Physical safeguards

• Such as locks and fire alarms are the
lowest level of data protection.
Performing periodic backups is the
most common technique used to
ensure the continued availability of data

140


Click to View FlipBook Version