Professional Documents
Culture Documents
ONE
-1-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS
In the 1950's one might have defined 0/S as the software that control the hardware
An operating system is a program that acts as an interface between the user and
the computer hardware and controls the execution of all kinds of programs.
The 0/S is primary resources manager, where the main resource it manage is
computer HAY ( in the form of processor, storage, I/O devices, communication
devices), and data.
-2-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS
Fig 1.1
-3-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS
Memory Management
Memory management refers to management of Primary Memory or Main
Memory. Main memory is a large array of words or bytes where each word or
byte has its own address.
Main memory provides a fast storage that can be accessed directly by the CPU.
For a program to be executed, it must in the main memory. An Operating
System does the following activities for memory management −
Keeps tracks of primary memory, i.e., what part of it are in use by whom, what part
are not in use.
In multiprogramming, the OS decides which process will get memory when and how
much.
De-allocates the memory when a process no longer needs it or has been terminated.
Processor Management
In multiprogramming environment, the OS decides which process gets the
processor when and for how much time. This function is called process
scheduling. An Operating System does the following activities for processor
management −
Keeps tracks of processor and status of process. The program responsible for this
task is known as traffic controller.
Device Management
An Operating System manages device communication via their respective
drivers. It does the following activities for device management −
-4-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS
Keeps tracks of all devices. Program responsible for this task is known as the I/O
controller.
Decides which process gets the device when and for how much time.
De-allocates devices.
File Management
A file system is normally organized into directories for easy navigation and
usage. These directories may contain files and other directions.
Keeps track of information, location, uses, status etc. The collective facilities are
often known as file system.
Job accounting − Keeping track of time and resources used by various jobs and
users.
Error detecting aids − Production of dumps, traces, error messages, and other
debugging and error detecting aids.
-5-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS
An Operating System provides services to both the users and to the programs.
Program execution
I/O operations
Communication
Error Detection
Resource Allocation
Protection
Program execution
Operating systems handle many kinds of activities from user programs to
system programs like printer spooler, name servers, file server, etc. Each of
these activities is encapsulated as a process.
-6-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS
I/O Operation
An I/O subsystem comprises of I/O devices and their corresponding driver
software. Drivers hide the peculiarities of specific hardware devices from the
users.
I/O operation means read or write operation with any file or any specific I/O device.
Operating system provides the access to the required I/O device when required.
A file system is normally organized into directories for easy navigation and
usage. These directories may contain files and other directions. Following are
the major activities of an operating system with respect to file management −
The operating system gives the permission to the program for operation on file.
Communication
In case of distributed systems which are a collection of processors that do not
share memory, peripheral devices, or a clock, the operating system manages
communications between all the processes. Multiple processes communicate
with one another through communication lines in the network.
-7-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS
Both the processes can be on one computer or on different computers, but are
connected through a computer network.
Error handling
Errors can occur anytime and anywhere. An error may occur in CPU, in I/O
devices or in the memory hardware. Following are the major activities of an
operating system with respect to error handling −
Resource Management
In case of multi-user or multi-tasking environment, resources such as main
memory, CPU cycles and files storage are to be allocated to each user or job.
Following are the major activities of an operating system with respect to
resource management −
Protection
Considering a computer system having multiple users and concurrent execution
of multiple processes, the various processes must be protected from each
other's activities.
-8-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS
The OS ensures that external I/O devices are protected from invalid access
attempts.
• Early history (The 1940's and 1950's) In this lime the earliest Electronic digital
computers had no 0/S.
• The programs were often entered one Bit at a time on rows of mechanical
switches.
• The 1' 0/S implemented in the early 1950's, this system ran one job at a time
and smoothed the transition between jobs to get maximum utilization of the
computer system.
0/S 1960's
• They were also batch processing system, but they were able to take advantage
of computers resources by running several jobs at once.
-9-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS
0/S 1970's
• They were multimode time — sharing system that supported batch processing,
time-sharing, and real-time application.
• The P.0 was in its first development stage.
• Communication between C/S became widely used.
• Communication in local area net works (LAN) was made practical and
economical by Ethernet standard.
0/S 1980's
• The 1980's was a decade of P.0 and the workstation.
• Individuals could have their own computers for performing their work and
they could use communication facilities for transmitting data between systems.
• Computing was distributed to the sites which it was needed rather than
bringing the data to be processed to some central-scale computer installation.
- 10 -
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS
6. The client/server model became wide spread : Clients are network users that
need various services performed; servers are FI/W, S/W and network
components that perform these services.
- 11 -
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
TWO
-1-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
The users of a batch operating system do not interact with the computer
directly (figure 1.2). Each user prepares his job on an off-line device like punch
cards and submits it to the computer operator. To speed up processing, jobs with
similar needs are batched together and run as a group. The programmers leave
their programs with the operator and the operator then sorts the programs with
similar requirements into batches.
The problems with Batch Systems are as follows −
Lack of interaction between the user and the job.
CPU is often idle, because the speed of the mechanical I/O devices
is slower than the CPU.
Difficult to provide the desired priority.
Operating
system
User program
area
Fig 1.2
-2-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
Disadvantages
• There is no direct interaction between the user and the job while the job is
executing.
• The delay between the job submission and the job completion (called
turnaround time) may result from amount of computing time needed.
CPU TERMINAL
SINGLE-USER INTERACTIVE
-3-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
TERMINAL
CPU
TERMINAL
TERMINAL
Multiple jobs are executed by the CPU by switching between them, but the
switches occur so frequently. Thus, the user can receive an immediate response.
For example, in a transaction processing, the processor executes each user
program in a short burst or quantum of computation. That is, if n users are
present, then each user can get a time quantum. When the user submits the
command, the response time is in few seconds at most.
Problem of reliability.
-4-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
Real-time systems are used when there are rigid time requirements on the
operation of a processor or the flow of data and real-time systems can be used
as a control device in a dedicated application. A real-time operating system must
have well-defined, fixed time constraints, otherwise the system will fail. For
example, Scientific experiments, medical imaging systems, industrial control
systems, weapon systems, robots, air traffic control systems, etc.
-5-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
CPU
INPUT
OUTPUT
FIG 1.4
With resource sharing facility, a user at one site may be able to use the
resources available at another.
Speedup the exchange of data with one another via electronic mail.
If one site fails in a distributed system, the remaining sites can potentially
continue operating.
-6-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
Upgrades to new technologies and hardware can be easily integrated into the
system.
-7-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
CPU L/P
C/R
On-line operation
-8-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
The main advantage of off-line operation was that, the CPU was no longer
constrained by the speed of C/R and UP, but limited by only the speed of MIT
unit.
1.7.2 Buffering
A buffer is an area of primary storage for holding data during I/O transfers,
where the I/O transfer speed depends on many factors related to the I/O
Hardware but normally unrelated to processor operation.
On input the data placed in the buffer by an I/O channel when the transfer is
complete the data may be accessed the processor.
There are two types of buffering:
1. The single-buffered:
The channel deposits data in a buffer the processor will access that data the
channel deposits the next data, etc. while the channel is depositing data no
processing on that data may occur.
2. The double-buffering:
This system allows overlap of I/O operation with processing; while the channel
is depositing data in one buffer the processor may be processing data in the other
buffer. When the processor is finished processing data in one buffer it may
process data in the second buffer. In buffering the CPU and I/O are both busy.
-9-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
1. Spooling uses the disk as a very large buffer for reading as far a head as
possible on input devices and for storing output files until the output devices are
able to accept them.
2. Spooling is now a standard feature of most O.S.
3. Spooling allows the computation of one job can overlap with the 1/0 of
another jobs, therefore spooling can keep both CPU and the I/O devices working
as much higher rates.
4. The figure below show the spooling layout.
1.7.4. Multiprogramming
I. Spooling provides an important data structure called a job pool kept on disk.
The 0/S picks one job from the pool and begin to execute it.
2. In multiprogramming system, when the job may have to wait for any reason
such as an I/O regrets, the OIS simply switches to and executes another job.
When the second job need to wait the CPU is switches to another job and so on.
Then the CPU will never be idle.
3. The figure below show the multiprogramming layout where the 0/S keeps
several jobs in memory at a time. This set of jobs is a subset of the jobs kept in
the job pool.
- 10 -
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
1. Most systems to date are single-processor systems that is they have one main
CPU.
2. There is a trend to have multiprocessor system, where such systems have more
than one processor in close communication sharing the computer Bus, the clock,
and sometimes memory and peripheral devices, in the figure below.
3. The advantage of this type of systems to increase the throughput (the number
of jobs completed in unit of time).
- 11 -
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS
- 12 -
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
THREE
1
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
2
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
To start an I/O operation the CPU loads the appropriate registers within
the device controller. The controller examines the contents of these
registers to determine what action to take. For example if it finds a read
request the controller will start the transfer of data from the device to its
local buffer. Once the transfer of data is complete the device controller
informs the CPU that it has finished its operation.
2.3 DMA
To solve this problem 'Direet Memory Access (DMA) is used for high—
speed I/O devices. After setting up buffer, pointers, and counters for I/O
device; the device controller transfers an entire block of data directly to or
from its own buffer storage to memory with no intervention by the CPU.
Only one interrupt is generated per block rather than one interrupt per byte
(or word) generated for low—speed devices.
The DMA controller interrupts the CPU when the transfer has been
completed.
3
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
a. Main memory is usually too small to stare all needed programs and data
permanently.
b. Main memory is a volatile storage device that loses its contents when
power is turned off or otherwise lost.
4
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
5
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
FOUR
1
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
To ensure proper operation we must protect the 0/S and all programs and
their data from any malfunctioning program. Protection is needed for any
shared resource. The approach taken is to provide H/W support to allow
as to differentiate among various modes of executions.
A bit called mode bit is added to HAV to indicate the current mode; monitor
(0) or user (1). With the mode bit we are able to distinguish between an
execution that is done on behalf of the 0/S, and one that is done on behalf
of the user.
The dual mode of operation provides us with the means for protecting the
O/S from errant users and errant users from one another. The HAV allows
privileged instructions to be executed in only monitor mode.
To prevent a user from performing illegal 1/0 we define all I/O instructions
to be privileged instructions. Thus users cannot issue I/O instructions
directly they must do it through the 0/S.
For 1/0 protection to be complete we must be sure that a user program
can never gain control of the Computer in monitor mode.
2
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
3
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
This scheme prevents the user program from modifying the code or data
structures of either the 0/S or others users
The base and limit registers can be loaded by only the 0/S which uses a
special privileged instruction. Since privileged instructions can be
executed in only monitor mode, therefore only O/S can load the base and
limit registers. This scheme allows the monitor to change the value of the
registers but prevents user programs from changing the registers contents.
The third piece of the protection is ensuring that the 0/S maintains control,
we must prevent a user program from an infinite loop, and never returning "
control to the O/S. To achieve this goal we can use a timer.
A timer can be set to interrupt the computer after a specified period. The period
may be fixed (1/60 second) or variable (from 1 millisecond to I second). To
control the timer the O'S sets the counter, according to fixed—rate clock. Every
time that the clock ticks the counter is decremented. When the counter reaches
(0) on interrupt occurs, and control transfers automatically to the 0/S, which_
may treat the interrupt as a fatal error or may give the program more time
The H/W has two modes: user mode and monitor mode various instructions
(such as 1/0 instruction and halting are privileged and can be executed in only
4
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
monitor mode. To do I/O a user program executes a system call to request that
the 0/S perform I/O on its behalf (see figure 2.5 below). The 0/S executing in
monitor mode checks that the request is valid and (if it is valid) does the I/O
requested. The O/S then returns to the user
— Running program may require I10. This I/O may involve a file or on
I/O devices, such as rewind a tape drive, or blank a screen on CRT.
Therefore the 0/S must provide some mean to do I/0.
5
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
d. Error detection
e. Resource allocation
— Resources must be allocated to each of multiple jobs that are running
at the same time.
— Many_different types of resources are managed by the 0/S.
f. Accounting
We want to keep track of which users use how much and what kinds of
computer resources.
g. Protection
The owners of information stored in a multiples computer system may want
to control its use protection involves ensuring that all access to system
resources is control.
System call provide the interface between a running program and 0/S, and
it grouped into the major categories as follows:
6
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
End, abort, load, execute, .create, terminate, wait for tithe, wait Omni,
allocate and free memory.
b. File manipulation
Create and delete file, open and close file, get file attributes and set file
attributes.
c. Device manipulation
Request and release device, read, write reposition, get device attributes
and set device attributes, logically attach or detach devices.
d. Information maintenance
- Get time or date and set time or date.
- Get system data and set system data.
- Get or set process, file or device attributes.
e. Communication
Create, delete communication connection send, and receive messages
transfer status information attach or detach remote devices.
7
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
- 0/S is -event—driven programs. 'If there are no jobs to execute, no I/O devices
to service, and no users to respond to, and 0/S will sit quietly waiting for
something to happen.
- Events are always signaled by the occurrence of an interrupt or a trap. Thus
an 0/S is interrupt driven. When an interrupt (or trap) occurs the H/w transfer
control to 0/S.
- The figure 2.8 shows the 0/S general flow.
8
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
FIVE
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
3 - Information Management
C/S can store information on several different types of physical media
such as:
a- Magnetic tape.
b. Disk or drum.
c. Optical disk.
Each of these media has its own characteristics and physical organization.
- The data cannot be written to secondary storage unless they are within
a file.
- Commonly files represent programs (Both source and object forms) and
data. -
- All disk I/O is units of one block (physical record) and all blocks are the
same size
1
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Name, Type, location, Size, Protection, Time and Date, User identification
When a file is open there are several pieces of information associated with
an open file:
a. File pointer. The 0/S must track the last read/ write location as a cullern-
file—position pointer. This pointer is unique to each process operating on
the file.
b. File open count. This counter tracks the number of opens and closes of
each file.
c. Disk location of the file. The information needed to locate the file on
disk is kept in memory to avoid having to read it from disk for each
operation
2
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
The locating an offset within a file can be complicated for the 0/S. All disk
I/O is performed in units of one block (physical record) and all blocks are
the same size. It is unlikely that the physical record size will exactly match
the length of the logical record logical records may even vary in length
The logical record size, physical block size, and packing technique
determine how many logical records are in each physical block. The
packing can be done either by the user's application program or by the
0/S_ In either case the file may be considered to be a sequence of blocks.
All the basic I/O functions operate in terms of blocks
3
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
3-7-1 Sequential
The simplest access method is sequential access information in the file is
processed in order, one record after the other. This mode of access is by
far the most common, for example, editors and compilers usually access
files in this fashion.
The bulk of the operations on a file are reads and writes. A read operation
reads the next portion of the file and automatically advance a file pointer
which tracks the 1/0 location. A write appends to the end of the file and
advance, to the new end of file.
See figure 3.1, This method is based on a tape mode of a file and works
as well on sequential—access devices as it does on random—access
ones
4
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
We first make a binary search on the master index which provides the
block number of the secondary index. This block is read in and again a
binary search is used to find the block containing the desired record.
Finally this block is searched sequentially. In this way any record can be
located from its key by at most two direct—access reads
5
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
6
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
SIX
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
The directory can he viewed as a symbol table that translates file names
into their directory entries. The following operation that are to performed
on a directory: search 'Or a file, create a file, delete a file, list a directory,
rename a file, and transverse the file system. The most common schemes
for defining the logical structure of a directory are :
It is the simplest structure. All files contained in the same directory, see
figure 3.5
1
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Advantages:
It is easy to support and understand
Disadvantages:
When the number of files increases or when there is more than user. Since
all files in the same directory they must have unique names
When a user logs in the system's master file directory, (MFD) is search.
The MFD is indexed by user name or by account number, and each entry
points to the UFD for that user.
Advantages:
1. It is solves the name—collision problem.
2. It fasts to locate certain file name.
3. We can use the same file name in two different UFD.
Disadvantages:
It requires a complicate search procedure where we need to join the user
name with file name.
2
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
The two—level directory is a two level tree we can extend this structure
to a tree of arbitrary height. See figure 3.8.
- This generalization allows user to create their own sub—directories and
to organize their file accordingly. The MS-DOS system for example is
structured as tree
- The tree has a root directory. Every file in the system has a unique path
name. A path name is the path from the root through all the
subdirectories to a specified file.
3
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
This organization provide more than one user to share all file or
subdirectory.
A share file or subdirectory will exist in the file system in two (or more )
places at once, see figure 3.9
4
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
5
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
SEVEN
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Disks provide the bulk of secondary storage on which a file system is maintained. To
improve I/O efficiency, I/O transfers between memory and disk are performed in units of
blocks. Each block is one of more sectors. Depending on disk drive, sectors vary from 32
bytes to 4096 bytes. Disks have two important characteristics that make them a convenient
medium for storing multiple files:
a. They can be rewritten in place, it is possible to read a block from the disk, to modify
the block and to write it back into the same place.
b. We can access directly any given block of information on the disk.
- Since there is only a limited amount of disk space it is necessary to reuse the space from
deleted files for new files if possible.
- To keep track of free disk space, the system maintains a free—space list (FSL).
- FSL records all disk blocks that are free. To create a file we search the FSL for the required
amount of space, and allocate that space to new file. This space is then removed from the
FSL. When the file deleted its disk space is added to the FSL.
There arc many methods used to organized the FSL, some of these are :
Example .
Consider a disk where blocks 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 17, 18, 25, 26, and 27 are free
and the rest of the blocks arc allocated. The FSL bit map (vector) would be.
0 0 1 1 I 1 0 0 1 1 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 1 1 1 0 0 ....
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Advantages
It is simple and efficient to find the first free block, or n consecutive free blocks on disk.
Many computers supply bit—manipulation instruction that can be used effectively, for that
purpose the calculation of the block number is
(number of bits per word) x (number of 0 — value words) + offset of first I bit
Disadvantages
The Bit—vectors are inefficient unless the entire vector is kept in main memory (and is
written to disk occasionally for recovery needs ).
- 1t is inefficient for large disks.
Another approach is to 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. This first block contains a
pointer to the next free disk block and so on, see figure 4.1.
Advantages
Disadvantages
It is not efficient to traverse the list we require to read each block so it needs more I/O time.
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
4.7.3 Grouping
A modification of the free—list is to store the addresses of n free blocks in the first free
block.
The first n-I of these blocks are actually free. The last block contains the addresses of
another n free blocks and so on.
Advantages
4.1.4 Counting
Another approach is to take advantage of the fact generally several contiguous blocks may be
allocated or freed simultaneously.
Thus rather than keeping a list of n free disk addresses, we can keep the address of the first
free block and the number n of free contiguous blocks that follow the first block.
Each entry in the FSL then consists of a disk address and a count, therefore the overall list
will be shorter as long as the count is generally greater than I see the following example of
counting list to the free blocks in the example in page (2).
Advantage
It is shorter than linked list and useful for contiguous allocation methods
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
EIGHT
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
- there are three major methods of allocating disk space are in wide use:
Contiguous, linked, and indexed allocation methods. Each has its advantages and disadvantages.
- The disk address and length (in blocks) define contiguous allocation of a file. If the file is (n) blocks long
and start at location (b) then it occupy blocks. b, b+1, b+2, , b + n - 1.
- The directory entry for each file indicates the address of the starting block and the length of the area
allocated for the file.
Advantages
Accessing a file is easy where sequential and direct access can be sported.
Disadvantages
Finding space for a new file.
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Advantages
- Creating file is easy by creating a new entry in the directory, where there is no need to declare the file size
when its created.
Disadvantages
- It can be used effectively for only sequential—access file. To find the block we must start at the beginning
of that file and follow the pointers until we get to the ith block.
This simple but efficient method of disk space allocation is used by the MS—DOS and OS/2 operating
system.
A section of disk at the beginning of each partition is set a side to contain a table. The directory entry
contains the block number of the block of the file.
The table entry indexed by that block number then contain the block number of the next block in the file.
This chain continues until the last block which has a special—end—of—file, see figure 4.4 below.
Advantage
Disadvantage
It needs significant number of disk head seeks unless the FAT is cached.
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
-Each file has its own index block which is one array of disk block addresses, the in' entry in the index block
point to ill' block of the file.
- The directory contains the address of the index block, when the file is created all pointers in the index
block are set to nil.
Advantage
Disadvantage
- It does suffer from wasted space.
- The pointer overhead of index block is generally greater than the pointer overhead of linked allocation.
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
NINE
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
5. Process Management
Early C/S allowed only one program to be executed at a time. This program had complete control of
the system and had access to all of the system's resources. Today C/S allow multiple programs to be
loaded into memory and to be executed concurrently.
The more complex the 0/S the more it is expected to do on behalf of its users. A system therefore
consists of a collection of processes:
O/S processes executing system code, and user processes executing user code. By switching the CPU
between processes the 0/S can make the C/S more productive.
CPU registers:
They include accumulators, index registers, stack pointers, and any general—purpose registers plus
and condition—code information.
• Accounting information:
It includes the amount of CPU and real time used, time limits, account numbers, job or process
numbers, and so on.
- A new process is initially put in the ready queue waits until it is selected for execution (or
dispatched) and is given the CPU.
- Once the process is allocated the CPU and is executing one of several events could occur:
a. The process could issue an I/O request and then be placed in an I/O queue.
b. The process could create a new sub—process and wait for its termination.
c. The process could be removed forcibly from the CPU as a result of an interrupt and be put
back in the ready queue.
The first two cases the process switches from the waiting state (queue) and is then put back in the
ready queue. A process continue this cycle until it's terminates at which time it is removed from all
queues and has its PCB and resources deal located.
Figure 5.5 shows the process scheduling.
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
TEN
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
When a process create a new process two possibilities exist in terms of execution:
a. The parent continues to execute concurrently with its children.
b. The parent waits until some or all of its children have terminated.
A process terminates when it finishes executing its last statement and asks the 0/S to delete it by using
the exist system call.
A parent may terminate the execution of one of its children for a variety at reasons such as:
• The child has exceeded its usage of some of the resources it has been allocated.
• The task assigned to the child is no longer required.
• The parent is existing and the 0/S does not allow a child to continue if its parent terminated.
A process is cooperating if it can affect or be affected by the other processes executing in the system
or any process that share data with other processes is a cooperating process.
There are several reasons for providing an environment that allows process cooperation:
1. Information sharing.
2. Computation speedup.
3. Modularity: Dividing the system functions into separate processes.
4. Convenience, Many tasks to work on at one time, a user may be editing printing and compiling in
parallel.
To illustrate the concept of cooperating processes let us consider the producer—consumer problem as
an example of cooperating processes.
A produce process produces information that is consumed by a consumer process.
For example, a print program produces characters that are consumed by the printer driver.
To allow producer and consumer to run concurrently we must have a buffer of item that can be filled
by the producer and emptied by the consumer.
A producer can produce one item while the consumer is consuming another item. The producer and
consumer must be synchronized. The consumer must wait until an item is produced (the buffer is
empty) and the producer must wait if the buffer is full.
In the bounded—buffer and be one solution for the producer and consumer processes share the
following variables:
var n;
type item = ……;
var buffer: array [0…n-I] of item;
in, out: 0..n-1
with in. out initialized to the value 0. The shared buffer is implemented as a circular array with two
logical pointer: in and out.
in points to the next free position in the buffer; out points to the first full position in the buffer.
The buffer is empty when in—out; the Suffer is full when in+1 mod n=out.
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
5.10Thread structure
- A thread sometimes called light weight process (LWP) is a basic unit of CPU utilization and consists
of a program counter, a register set, and a stack space.
It shares with peer threads its code section, data section and 0/S resources such as open files and signals
collectively known as a task.
A traditional or heavy weight process is equal to a tasks with one thread.
Threads can be in one of several states ready, blocked, running, or terminated. Threads can create child
threads if one thread is blocked another thread can run.
Unlike processes threads are not independent of one another, because all threads can access in the
task.