You are on page 1of 73

Diyala University-College of Science-Computer Science Department

Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari


Lecture One OS

ONE
-1-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture One OS

Operating System – Overview


1-Introduction to 0/S
An Operating System (OS) is an interface between a computer user and computer
hardware. An operating system is a software which performs all the basic tasks like
file management, memory management, process management, handling input and
output, and controlling peripheral devices such as disk drives and printers. Some
popular Operating Systems include Linux, Windows, OS X, VMS, OS/400, AIX, z/OS,
etc.

1-1 0/S Definitions:


 An operating systems is a program that acts as an intermediary between a user
of a computer and the computer hardware .

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.

 Today we can define an 0/S as a set of programs implemented in either software


or firmware, that make the hardware useable .

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.

1.2 Computer System Components


An 0/S is an important part of almost every computer system. A Computer System
can be divided roughly into four components (Figure 1.1).:

1. The Hardware (CPU, memory, I/O devices).

2. Operating system (0/S).

3. Application programs (Assembler, data base compiler text. editor).

4. The users (people, machines, other computers).

-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

1.3 0/S Goals:


1. The primary goal of an 0/S is to make 0/S convenient to use.
2. A secondary goal is to use the computer H/W in an efficient manner.

1.4 The 0/S Functions and services:


1.4.1 0/S Functions:

Following are some of important functions of an operating System:-


1. Memory Management
2. Processor Management
3. Device Management
4. File Management
5. Security
6. Control over system performance
7. Job accounting
8. Error detecting aids
9. Coordination between other software and users

-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.

 Allocates the memory when a process requests it to do so.

 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.

 Allocates the processor (CPU) to a process.

 De-allocates processor when a process is no longer required.

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.

 Allocates the device in the efficient way.

 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.

An Operating System does the following activities for file management −

 Keeps track of information, location, uses, status etc. The collective facilities are
often known as file system.

 Decides who gets the resources.

 Allocates the resources.

 De-allocates the resources.

Other Important Activities


Following are some of the important activities that an Operating System
performs −

 Security − By means of password and similar other techniques, it prevents


unauthorized access to programs and data.

 Control over system performance − Recording delays between request for a


service and response from the 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

 Coordination between other softwares and users − Coordination and


assignment of compilers, interpreters, assemblers and other software to the various
users of the computer systems.

1.4.2 Operating System Services

An Operating System provides services to both the users and to the programs.

 It provides programs an environment to execute.

 It provides users the services to execute the programs in a convenient manner.

Following are a few common services provided by an operating system −

 Program execution

 I/O operations

 File System manipulation

 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.

A process includes the complete execution context (code to execute, data to


manipulate, registers, OS resources in use). Following are the major activities
of an operating system with respect to program management −

 Loads a program into memory.

 Executes the program.

 Handles program's execution.

 Provides a mechanism for process synchronization.

 Provides a mechanism for process communication.

 Provides a mechanism for deadlock handling.

-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.

An Operating System manages the communication between user and device


drivers.

 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.

File system manipulation


A file represents a collection of related information. Computers can store files
on the disk (secondary storage), for long-term storage purpose. Examples of
storage media include magnetic tape, magnetic disk and optical disk drives like
CD, DVD. Each of these media has its own properties like speed, capacity, data
transfer rate and data access methods.

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 −

 Program needs to read a file or write a file.

 The operating system gives the permission to the program for operation on file.

 Permission varies from read-only, read-write, denied and so on.

 Operating System provides an interface to the user to create/delete files.

 Operating System provides an interface to the user to create/delete directories.

 Operating System provides an interface to create the backup of file system.

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

The OS handles routing and connection strategies, and the problems of


contention and security. Following are the major activities of an operating
system with respect to communication −

 Two processes often require data to be transferred between them

 Both the processes can be on one computer or on different computers, but are
connected through a computer network.

 Communication may be implemented by two methods, either by Shared Memory or


by Message Passing.

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 −

 The OS constantly checks for possible errors.

 The OS takes an appropriate action to ensure correct and consistent computing.

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 −

 The OS manages all kinds of resources using schedulers.

 CPU scheduling algorithms are used for better utilization of CPU.

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

Protection refers to a mechanism or a way to control the access of programs,


processes, or users to the resources defined by a computer system. Following
are the major activities of an operating system with respect to protection −

 The OS ensures that all access to system resources is controlled.

 The OS ensures that external I/O devices are protected from invalid access
attempts.

 The OS provides authentication features for each user by means of passwords.

1.5 The 0/S development history:


Operating system have developed over the last 50 years through a number of
distinct phases or generations to the decades:-

• Early history (The 1940's and 1950's) In this lime the earliest Electronic digital
computers had no 0/S.

• Machines of that period were Primitive.

• The programs were often entered one Bit at a time on rows of mechanical
switches.

• Eventually machine language programs were entered on punched cards, and


assembly languages were developed to speed the programming process.

• 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.

• This type of 0/S called single-stream Batch processing system, because


program and data were submitted in groups or batches.

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

• The 0/S designer developed the concept of multiprogramming, and software


engineering field was appeared.

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.

• Microprocessor technology it became possible to build desktop computers as


powerful as the mainframe of the 1970's.

• 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.

• Application software packages are available such as:-

1. Spread sheet programs.


2. Word processors.
3. Data base packages.
4. Graphics packages.
5. Transfer information between computers in computers in computer network
(E-mail, Remate DB access application....etc) were widely used.

- 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.

0/s 1990's and beyond


• In the 1990's we enter the area of true distribute computing in which
computations will be divided into sub-computation that can be executed on
other processors in multiprocessor computer network.
• Networks will be dynamically configured, they will continue operating even
as new devices and S/W are added or removed by using registration procedure.

0/s 2000 and Beyond


 Middleware
– Links two separate applications
• Often over a network and between incompatible
machines
– Particularly important for Web services
• Simplifies communication across multiple architectures
 Web services
– Encompass set of related standards
– Ready-to-use pieces of software on the Internet
– Enable any two applications to communicate and exchange
data

- 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

1.6 Types of Operating System


Operating systems are there from the very first computer generation and they
keep evolving with time. In this chapter, we will discuss some of the important
types of operating systems which are most commonly used.

1. Batch operating system

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

• Advantages of batch system is very simple.

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.

2. Time-sharing operating systems

Time-sharing is a technique which enables many people, located at various


terminals, to use a particular computer system at the same time. Time-sharing
or multitasking is a logical extension of multiprogramming. Processor's time
which is shared among multiple users simultaneously is termed as time-sharing.

The main difference between Multiprogrammed Batch Systems and Time-Sharing


Systems is that in case of Multiprogrammed batch systems, the objective is to
maximize processor use, whereas in Time-Sharing Systems, the objective is to
minimize response time.

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

TIME-SHARING SYSTEM FIG.1.3

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.

The operating system uses CPU scheduling and multiprogramming to provide


each user with a small portion of a time. Computer systems that were designed
primarily as batch systems have been modified to time-sharing systems.

Advantages of Timesharing operating systems are as follows −

 Provides the advantage of quick response.

 Avoids duplication of software.

 Reduces CPU idle time.

Disadvantages of Time-sharing operating systems are as follows −

 Problem of reliability.

 Question of security and integrity of user programs and data.

-4-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS

3. Real Time operating System


A real-time system is defined as a data processing system in which the time
interval required to process and respond to inputs is so small that it controls the
environment. The time taken by the system to respond to an input and display
of required updated information is termed as the response time. So in this
method, the response time is very less as compared to online processing.

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.

There are two types of real-time operating systems.

Hard real-time systems


Hard real-time systems guarantee that critical tasks complete on time. In hard
real-time systems, secondary storage is limited or missing and the data is stored
in ROM. In these systems, virtual memory is almost never found.

Soft real-time systems


Soft real-time systems are less restrictive. A critical real-time task gets priority
over other tasks and retains the priority until it completes. Soft real-time
systems have limited utility than hard real-time systems. For example,
multimedia, virtual reality, Advanced Scientific Projects like undersea
exploration and planetary rovers, 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

4. Distributed operating System


Distributed systems use multiple central processors to serve multiple real-time
applications and multiple users. Data processing jobs are distributed among the
processors accordingly.

The processors communicate with one another through various communication


lines (such as high-speed buses or telephone lines). These are referred
as loosely coupled systems or distributed systems. Processors in a distributed
system may vary in size and function. These processors are referred as sites,
nodes, computers, and so on.

The advantages of distributed systems are as follows −

 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.

 Better service to the customers.

 Reduction of the load on the host computer.

 Reduction of delays in data processing.

-6-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS

5. Network operating System


A Network Operating System runs on a server and provides the server the
capability to manage data, users, groups, security, applications, and other
networking functions. The primary purpose of the network operating system is
to allow shared file and printer access among multiple computers in a network,
typically a local area network (LAN), a private network or to other networks.

Examples of network operating systems include Microsoft Windows Server 2003,


Microsoft Windows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, and
BSD.

The advantages of network operating systems are as follows −

 Centralized servers are highly stable.

 Security is server managed.

 Upgrades to new technologies and hardware can be easily integrated into the
system.

 Remote access to servers is possible from different locations and types of


systems.

-7-
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari
Lecture Two OS

The disadvantages of network operating systems are as follows −

 High cost of buying and running a server.

 Dependency on a central location for most operations.

 Regular maintenance and updates are required.

1.7 Performance Development


0/S attempted to schedule computational activities to ensure good
performance, where many facilities had been added to 0/S some of these are:

1.7.1 On-Line and Off-Line operation


A special subroutine was written for each I/O device called a device-driver, and
some peripherals (1/0 devices) has been equipped for either On-Line operation,
in which they are connected to the processor, or off-line operations in which
they are run by control units not connected to the central C/S card-to-tape or
Tape-to-Print Operations are performed by off-line units. The figure 1.5
illustrate the on-line and off-line operation.

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.7.3 Spooling: (Simultaneous Peripheral Operation On-Line)

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.7.5. Parallel systems

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. Computer System Operation


A modern general—purpose o/s consists of a CPU and a number of device
controllers that are connected through a common bus that provide access
to. shared memory (figure 2.1).

When the computer to start running, it is powered up or rebooted, it needs


to have an initial program to run. This initial program, or bootstrap program
tends to be simple. It initializes all aspects of the system from CPU
registers to device controllers to memory contents. The bootstrap program
must know how to load the 0/S and how to start executing that system.
The bootstrap program must locate and load into memory, the 0/S-. The
0/S. then start executing the first process such as "init" and wait for some
event to occur. The occurrence of an event is usually signaled by an
interrupt from either HAV or S/\V. The Hardware may trigger an interrupt
at any time by sending a signal to the CPU by way of the system bus.
Software may trigger an interrupt by executing a special operation called
a system call.

2
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

2.1 I/O Structure


Each I/O device connected to the c/s through its controller. A device
controller maintains some local buffer storage and a set of special—
purpose registers. It is responsible for moving the data between the
peripheral devices that is controls and its local buffer storage.

2.2 I/O Interrupts

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

Structure A high—Speed device such as a tape, disk, or communication


network may be able to transmit information at close to memory speeds;
the CPU would need 2 microseconds to respond to each interrupt. That
would not leave much time for process execution.

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.

2.4 Storage Structure

3
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

The programs must be in main memory to be executed. Main memory is


the only large storage area that the processor can access directly. Each
word in memory has its own address. Interaction is achieved through a
sequence of load or store instruction to specific memory addresses. The
load instruction moves a word from main memory to an internal register
within the CPU whereas the store instruction moves the content of a
register to main memory.
We want the programs and data to reside in main memory permanently.

This arrangement is not possible for the following two reasons:

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.

Therefore most C/S provide secondary storage as an extension of main


memory. It be able to hold large quantities of data permanently. The most
common secondary—storage device is a magnetic disk which provides
storage of both programs and data: There are other many media such as
floppy disks, CD-ROM's, and DVD's.

2.5 Storage Hierarchy

The variety of storage systems in a CIS can be organized in a hierarchy


according to speed and their cost figure 2.2. The higher levels are
expensive, but are fast.

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

2.6 Hardware Protection

To improve system utilization, the O/S began to share system resources


among several programs simultaneously. Multi programming put several
programs in memory at the same time. This sharing created both improved
utilization and increased problems. When the system was run without
sharing an error in a program could cause problems for only the one
program that was running. With sharing many processes could be affected
by a bug in one program.

2.6.1 Dual-Mode Operation

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.

Therefore we need two separate modes of operation: user mode and


monitor mode (also called supervisor mode, system mode, or privileged
mode).

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.

2.6.2 I/O Protection

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.6.3 Memory Protection

2
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

To ensure correct operation we must protect the interrupt vector from


modification by a user program. Also we must protect the interrupt service
routines in the 0/S from modification.

What we need to separate each program's memory space is an ability to


determine the range of legal addresses that the program may access, and
to protect the memory outside that space. We can provide this protection
by using two registers usually a base and a limit as illustrated in figure 2.3.
The base register holds the smallest legal physical memory address; the
limit register contains the size of the range. For example if the base register
holds 300040 and limit register is 120900 then the program can legally
access all addresses from 300040 through 420940 inclusive.

This protection is accomplished by the CPU HAV comparing every address


generated in user mode with registers. Any attempt by a program
executing in user mode to access monitor memory or other user's memory
results in a trap to the monitor which treats the attempt as a fatal error
(figure 2.4 below).

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.

2.6.4 CPU Protection:

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

2.7 General Systen Architecture

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

2.8 Operating System Services


An 0/S provides an environment for the execution of programs, and to the
users of these programs. There are some common classes of services;

a.Program execution End normal

Load program > Run

b. 1/0 operations A b normal

— 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.

C. File system mainpulation

— The programs want to read and write.files.

5
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

— The user want to create and delete files by name.

d. Error detection

— CPU and memory HAI errors.


— I/O devices errors.

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.

2.9 The User View


There are two methods of providing services:
- System calls.
- System programs.

2.9.1 System Calls

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

a. Process and lob control

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.

2.9.2 System Programs


Most modem 0/S supply a large collection of system programs to solve
common problems, and it can be divides into the following categories:
a. File manipulation
b. Status information
c. File modification
d. Programming languages support.
e. Program loading and execution
f. Communications

2.10. The 0/S View

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 0/S provides a uniform logical view of information storage.

3-1 The File System


The file system consists of three distinct parts.:

a. A collection of files, each storing related data.

B. A directory structure, which organizes and provides information about


all the files in the system.

c. A partitions which are used to separate physically or logically large


collections of directories

3-2 File Concept


A file is a named collection of related information that is recorded on
secondary storage.

- 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

3-3 Files Attributes


In addition to file name, a file has certain other attributes which vary from'
one 0/S to another but typically consists of these:

Name, Type, location, Size, Protection, Time and Date, User identification

3-4 File Operations


A file is an abstract data type, the 0/S provides system calls to create,
write, read, reposition, delete, and truncate files, appending, renaming,
and copying.

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

3-5 File Types


A common technique for implementing file types is to include the type as
a part of the file name. The name is split into two party a name and an
extension usually separated by a period character. In this was the user
and the 0/S can tell from the name alone what the type of a file is, see
Table 3.1

2
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

3-6 File Structure.


The file types may be used to indicate the internal structure of the file. If
the 0/S support multiple file structures the resulting size of 0/S must be
increased to contain the code to support these file structure.

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

Packing a number of logical records into physical record is a common


Solution to this problem. For example, the UNIX 0/S defines all files to be
simply a stream of bytes. Each byte is individually addressable by its offset
form the beginning (or end) of the file. in this ease the logical record is 1
byte.

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 Access Methods


Files store information. When is used this information must be accessed
and read into computer memory. There are several ways that the
information in the file can be accessed:

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

3-7-2 Direct access


Another method is direct access (or relative access). A file is made up of
fixed length logical records that allow programs to read and write records
rapidly in no particular order. This method is based on a disk model of a
file since disks allow random access to any file block. A direct access allows
arbitrary to be read or written. Thus we may read block 14 then read block
53 and then write block 7.
The operations must be modified to include the block number as a
parameter. Thus we have read n where n is the block number rather than
read next and write next.
The block number provided by the user to the 0/S is relative block
number. A relative block number is an index relative to the beginning of
the file, see Table 3.2

3.7.3 Other access Methods


These methods can be built on top of a direct access method. They involve
the construction of an index for the file. The index like an index in the
block of a book contain pointer to the various blocks. To find an entry in
the file we first search the index and then use the pointer to access the
file directly and to find the desired entry, see figure 3.3

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

3.8 Directory structure


Some file systems store thousands of files on hundreds of giga bytes of
disk. To manage all these data we need to organization them. This
organization is usually done in two parts:
a. The file system is broken into partitions (mini disks), each disk on a
system contains at least one partition some areas within one disk
defined in one partition, each treated a separate storage device, where
as other systems allow partitions to be larger than a disk to group disks
into one logical structure
b.Each partition contain information about files within it. This information
is kept in entries in a device directory or volume table of contents. The
device directory records information such as name, location, size, and
type for all files on that partition. See figure 3.4 shows the typical file—
system organization

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 :

3-8-1 Single—level Directory

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

3-8-2 Two-level Directory


In the two level directory structure, each user has his own user file
directory (UFD).
Each UFD a similar structure, but lists only the files of a single user, see
figure 3.0

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

3.8.3 Tree -Structured Directories

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.

- A directory (or subdirectory) contains a set of files or subdirectories. A


directory is simply another file but it is treated in a special way. One bit in
each directory defines the entry as a file (0) or as a subdirectory (1)

3
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

3-8-4 Acyclic—Graph Directories

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

4. Free-space list and allocation methods

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.

4.1 Free-space list (FSL)

- 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 :

4-1-1 Bit vector

The FSL is implemented as a Bit—mac or Bit—vector. Each block if represented by I bit. If


the block is free the bit is set to 1 if the block is allocated the bit is set to 0.

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.

4.1.2 Linked List

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

We can flow the link (pointer) to allocate blocks to the file.

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

The addresses of a large number of free blocks can be found quickly.


Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

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

4-2 Allocation methods


The direct—access nature of disks allows us flexibility in the implementation of files, many files will be
stored on the same disk.
- The main problem is how to allocate space to these files, so that disk space is utilized effective! and files
can be accessed quickly.

- 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.

4.2.1 Contiguous allocation


- This method requires each file to occupy a set of contiguous block.
- Disk address defines a linear ordering on the disk.

- 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

4.2.2 Linked allocation


- Linked allocation solves all problems of contiguous allocation.
- Each file is a linked list of disk blocks; the disk blocks may be scatterd any where on the disk.
- The directory contains a pointers to the first and last blocks of the file.
- The start pointer is initialized to nil to signify an empty file.

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.

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


- There is no need to compact disk space.
There is no external fragmentation with linked list.

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.

- Pointers require additional space.


- There is a problem when the pointer may lost or damages.
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

File allocation table (FAT):


An important application on the linked allocation method is the use of a file allocation table (FAT).

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

Simple and efficient.

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

4.2.3 Indexed Allocation


- Indexed allocation solved the problem lost pointvi in linked allocation by
bringing all the pointers together into one location, the indexed block.

-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.

-For large tile several inaex me may oe LISCC.


- Figure 4.5 show the indexed allocation structure.
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

Advantage

-It supports direct access without suffering from E—Fragmentation.


- Any free block where on the disk may satisfy a request for more space

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.

5.1 Process Concept


A user may be able to run several programs at one time: one interactive and several batch programs.
The 0/S need to support its own internal programmed activities. In many aspects all of these activities
are similar. So we call all of them processes.
A process is a program in execution. The execution of a process must progress in a sequential fashion.
A process is more than the program code: sometimes known as the Text section. The value of program
counter and the contents of the processor's registers.

5.2 Process states


As a process executes, it changes state. The state of a process is defined in part by the current activity
of that process. Each process may be in one of the following states:
• New: the process is being created.
. Ready: the process is waiting to be assigned to a processor
• Running: Instructions are being executed.
• Waiting: The process is waiting for some event to occur (such as an 1/0"
completion or reception of a signal).
• Terminated: The process has finished execution. The following diagram shows the process states
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

5.3 Process Control Block


Each process is represented in the 0/S by a Process Control Block (PCB)—also called a task control
block. A PCB is shown in the following figures.
It contains many pieces of information associated with a specific process including these:
• Process state: It may be new, ready, running, waiting, halted and so on.
• Program counter: The address of the next instruction to be executed for this process.

CPU registers:
They include accumulators, index registers, stack pointers, and any general—purpose registers plus
and condition—code information.

• CPU scheduling Information:


It includes a process priority, pointers to scheduling queues.

• Memory Information management:


It may include the value of the base and limit registers, the page tables... etc.

• Accounting information:
It includes the amount of CPU and real time used, time limits, account numbers, job or process
numbers, and so on.

• I/0 status information:


It includes the list of I/O devices allocated to this process, a list of open files, and so on.
The PCB simply serves as the repository for any information that may vary from process to process .
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

5.4 Process Scheduling


The objective of multi programming is to have some process running at all times to maximize CPU
utilization. The objective of time—sharing system is to switch the CPU among processes so
frequently that users can interact with each program while it is running.
For the uni processor system there will never be more than one running process. If there arc more
processes the rest will have to wait until the CPU is free

5.5 Scheduling Queue


As processes enter the system, they are put into a job queue. This queue consists of all processes in
the system.
- The processes that are residing in memory and are ready and waiting to ' execute are kept on a list
called the Ready queue.
- The queue is generally stored as a linked list the queue header contains pointers to the first and last
PCB's in that list. Each PCB has a pointer field that points to the next process in the queue.
- There are also other queues in the system, such as a list of processes waiting for a particular I/O
device is called a device queue.
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

- 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

5.6 Scheduling levels


A process migrates between the various scheduling queues throughout its life time. The 0/S must
select processes from these queues in some fashion
The selection process is carried out by the appropriate scheduler.
There are three levels (terms) of scheduling:

5.6.1 Long—term scheduler


The long—term scheduler or (job scheduler) selects processes from the job pool on the disk and
loads them into memory for execution. The long—term scheduler execute much ten frequently there
may be minutes between the creation of new processes in the system.
• The L.T.S control the degree of multi programming (The number of processes in memory).
If the degree of multi programming is stable than the average rate of processes creation must be
equal to the-average departure rate of processes leaving the system
It is important that the L.T.S make a careful selection. In general most processes can be described as
either I/0 bound or CPU bound.
* An I/O bound process is one that spends more of its time doing I/O than it spends doing
computations.
* A CPU—bound process is one that generates I/O requests infrequently, using more of its time doing
computation than an 1/0—bound process. The L.T.S select a good process mix of I/O—bound and
CPU—bound processes.

5.6.2 The short—tern scheduler (or CPU Scheduler)


It is selects from among the processes that are ready to execute and allocates the CPU to one of them.
The S.T.S must select a new process for the CPU quite frequently. Often the S.T.S must be very fast.
If it takes 10 milliseconds to decide to executes a process for 100 milliseconds then 10/(100+10) —
9% of the CPU used (wasted) for scheduling the work. If all processes are I/O bound the ready queue
will almost be empty and the S.T.S will have little to do. If all processes are CPU—bound the waiting
queue will almost be empty.
The system with the best performance will have a combination of CPU—bound and I/O—bound
processes.

5.6.3 The medium term scheduler


Some 0/S such as time—sharing systems may introduce an additional intermediate level of scheduling.
The key behind the M.T.S is that sometimes it can be advantageous to remove processes from memory
and thus to reduce the degree of multi programming. The process can be swapped out and swapped in
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

5,7 Context switch


- Switching the CPU to another process requires saving the state of the old process and loading the
saved state for the new process. The task is known as a context switch.
- Context—switch time is pure overhead because the system does no useful work while switching.
- The more complex the 0/S the more work must be done during a context switch.

5.8 Operations on Processes


- O/S that mange processes must be able to perform certain operation on and with processes. These
include: create, destroy, suspend, resume, change a process priority, block a process, wake up a
process dispatch a process, and enable a process to communicate with another process.
- Creating a process involves many operations including: name a process, insert it in the ready queue,
determine the process initial priority, create the PCB, and allocate the process's initial resources.
A process may create a new process. If it does the creating process is called the parent process and
the created process is called the child process. Such creation yields a hierarchical process structure as
in the figure 5.7.
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.

5.9 Cooperating Processes


The concurrent processes executing in the 0/S may be either independent processes of cooperating
processes.
A process is independent if it cannot affect or be affected by the tither processes executing in the
system. Any process that does not share or any data (temporary or persistent) with any other process
is independent.
Diyala University-College of Science-Computer Science Department
Operating System 4th Class Assist.Prof.Dr. Jamal Mustafa Al-Tuwaijari

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.

You might also like