Operating System:: The Chapter Covers
Operating System:: The Chapter Covers
Overview
Operating System :
1 Overview NOTES
Application
Operating
Program
System
Utilities designer
Operating System
Computer Hardware
Figure1.1, layers or hierarchy of a computer system
l Graphical User Interface(GUI)- All the services are available in the graphi-
cal format in the screen. Using some pointing device user can select the NOTES
service. User need not remember the commands.
(ii) Program Creation : OS provides variety of facilities and services, such as
editor and debuggers to help the user in the program creation and is making
it error free. Actually these services are utility program that are not the part of
OS but are accessible through the OS.
(iii) Program Execution : To execute a program a number of tasks are needed
to be performed. Instructions and data must be loaded into main memory, I/
O devices and files must be initialized, and other resources must be prepared.
The OS handles all these tasks for the user.
(iv) Access to I/O devices : Each I/O device require its own peculiar set of
instruction, or control signals, for operation. O/S take care of details so that
the programmer can use the I/O devices simply by issuing reads and write
command.
(v) Controlled Access to files : In the case of file control, it must include an
understanding of not only the nature of the I/O device (disk drive, tape drive)
but also the file format in the storage medium. The OS deals with the details.
Furthermore, in the case of a system with multiple simultaneous user the OS
can provide protection mechanism to control access to the files.
(vi) Protection and security : In the case of a shared or public system, the
operating system controls access to the system as a whole and to specific
system resources. Each component H/W or S/W that helps in the functioning
of the OS is called its resource, such as Memory, I/O device, Processor,
Application system programs, CPU time, File storage space etc. The Operat-
ing System has mechanisms for protection of resources and data from unau-
thorized access.
(vii) Communications : In the OS any work is done in the form of process.
Process is the unit of work. A program in execution is called a process. Many
times, during the execution, a process may require some information from other Check Your Progress
process. This information exchange is done by the communication between the 1. What is meant by
processes. The OS takes care of how this communication will take place Program creation?
between processes.
2. What is Protection
(viii)Error detection and response : A variety of errors can occur while a com- and Security?
puter system is running. These include internal and external hardware errors,
such as a memory errors, or a device failure and various S/W errors, such as
arithmetic overflow, attempt to access forbidden memory location etc. In each
case, the operating system must make the response that clears the error con-
dition with the least impact on running applications. The response may range
from ending the program that caused the error, to retrying the operation, to 7
simply reporting the error to the application.
Operating Systems (ix) Resource Allocation : A computer system has many resources (hardware
and software) that may be required to solve a problem. CPU times, memory
space, file storage space, I/O devices, and so on. The operating system acts
as the manager of these resources and allocate them to specific programs and
NOTES users as necessary for tasks. Since there may be many possibly conflicting
request for resources, the operating system must decide which requests are
allocated resources to operate the computer system efficiently and fairly.
(x) Accounting : A good operating system collects usage statistics for various
resources and monitors performance parameters such as response time. On
any system, this information is useful in anticipating the need for future enhance-
ments and in tuning the system to improve performance.
1.3 THE EVOLUTION OF OPERATING SYSTEM
(TYPES OF OPERATING SYSTEM)
1.3.1 Serial Operating System (It is not an OS)
In late 1940’s to the mid 1950’s, there was no OS. The programmer interacted
directly with the computer hardware. Each system had a console consisting of
display lights, toggle switches, some form of input device and a printer for output.
The Programmer wrote its program in machine code and loaded it with an input
device e.g. a card reader. If an error occurred, the program was halted. The error
condition was indicated by the lights. The programmer had to examine various
registers and main memory to determine the cause of the errors. If the program
reached to its normal completion, the output was printed through printer.
With these systems we had to face two types of problems:
1. Scheduling : To reserve machine time for a program a sign-up sheet was used.
Generally a user could sign a block of time in the multiple of 30 minutes. The
problem with this is that, if your program did not finish within 30 minutes due
to some problem you had to stop your program without resolving the problem.
Also, if you finished well before 30 minutes the computer will be idle till the
remaining time.
2. Setup time : The setup of a program was done in a sequence. A setting up of
a single program included loading the compiler plus the high level language
program (source program) into memory. Saving the compiled program (object
program). And then loading and linking together the object program and com-
mon functions. Each of these steps could involve mounting or dismounting tapes
or setting up the program to run.
If any error occurs during the setup process then whole work must be restarted
from the beginning.
1.3.2 Simple Batch Processing System
To reduce wastage of time caused by scheduling and setup time, the concept of a
batch operating system was developed.
The central theme behind this type of operating system is that- there is a small
software known as the monitor, the user did not interact directly with the computer
system. Rather, the user prepared a job (which consists of the code, the data and
some control information about the nature of the job (control cards)) and submitted
it to the computer operator. To speed up processing computer operator grouped
8
together the jobs (programs) with similar requirements and as the computer become
available would run each batch. For example suppose op- Operating System :
Operating
erator received request to run 3 programs say ‘A’, ‘B’ and Overview
another ‘A’. If he runs them in that order, he would have system
to set up for ‘A’ then for ‘B’ and finally ‘A’ again. If he
user program
runs the two ‘A’ programs as a batch, however he could NOTES
set up only once for ‘A’ thus saving operator’s time. area
The operating system (i.e. monitor) was a very simple
Figure 1.2 : simple
program. Its major task was to transfer control automati- batch operating system
cally from one job to the next.
Much of the OS must always reside in main memory and available for execution.
The rest of the OS consists of utility programs and common functions that are
loaded as subroutines to user programs at the beginning of any job that requires
them. The OS reads in jobs one at a time from the input device (such as card
reader). As it is read, the current job is placed in the user program area and control
is passed to this job. When the job is completed, it returns control to the OS which
immediately reads in the next job. After some time the output appeared, which
consists of the results of the program, as well as a dump of memory and registers
in case of program error.
Although, problem of scheduling of serial processing system was solved as a batch
of job is queued up and jobs are executed inturn without any dely. The setup
problem is handled with the use of job control language (JCL), which is a special
type of programming language used to provide instruction to the OS.
But with these type of system there was a problem that during execution CPU is
often idle because of a big difference in speed between I/O devices and CPU. To
solve this problem, rather than the cards being read directly from the card reader
into memory and then the job being processed, cards are read directly from the
card reader onto the disk. The location of card is recorded in a table by the
operating system. When that job is required for execution, it is read from the disk.
Similarly, when the job requests the printer to print a line, that particular line is
copied into a system memory called buffer and at the completion of the job data
is read from the disk and printed by the printer. This whole process is called
spooling. Spooling uses the disk as a intermediate place to hold the data to and from
I/O devices.
Figure1.2 : Spooling
By Spooling more than one input and output devices can interact with disk simul-
taneously and provide an impression that these devices interact directly with CPU,
so it is called Simultaneous Peripheral Operation On Line(SPOOL).
With a batch operating system there are two sacrifices : some main memory is now
given to the OS (monitor) and some CPU time is consumed by the monitor. Both
of these are forms of overhead. Even with these overhead the simple batch system 9
improves the use of the computer.
Operating Systems
NOTES
Advantages :
l Jobs are submitted in batch and wait in a queue therefore no problem of
scheduling.
l Instructions written in Job Control Language controls the loading and unloading
of programs hence there is no problem of setup time.
Disadvantages :
l Some main memory is now given over the OS.
l Some CPU time is consumed by OS.
l CPU is often idle because I/O devices are slower than CPU.
1.3.3 Multiprogrammed Batch System
Though the simple batch operating system solved the problem of scheduling by
automatic job sequencing but the processor time was still not fully utilized. The
problem is that mechanical I/O devices are slow compared to electronic processor.
Hence instructions for I/O are accomplished by the I/O devices with very slow
speed and during this period the CUP remains idle. See the figure 1.3(a). This
inefficiency can be removed if we can keep many programs in memory that are
10 ready to execute. We try to understand this with the help of simple example.
Suppose that in memory there is an OS and two user programs say A and B. Now Operating System :
when A needs to wait for I/O the processor can switch to B which likely is not Overview
waiting for I/O. See figure 1.3(b). Furthermore if there are three programs say A,
B, C OS can switch from A to B if A is waiting and B is not waiting, if both A and
B are waiting for I/O OS can switch to C (see figure 1.3(c)). We can expand the NOTES
number of programs till the main memory is fully occupied and allow OS to switch
among programs. Multiprogramming significantly improves the CPU utilization but
it requires certain decisions must be taken by the OS such as
l Scheduling : if many programs are ready to execute which program will be
executed by the CPU next (Scheduling),
l Memory Management : since there are more than one program where will these
programs be placed and how OS will manage the locality information (Memory
management),
l Intersupt handling and DMA : how the I/O devices will convey message that
they have finished the assigned task to OS so that the execution of that program
can be resumed ( interrupt handling and DMA)
Advantages :
l Multiprogramming utilizes system resources effectively.
l It has no problem of scheduling and setup time.
Disadvantages :
l User cannot interact with the job when it is executing. He had to predict the
result of the earlier job if next one is dependent upon the result of earlier one.
In most of the cases it is difficult to predict all the possible cases and define what
to do in these cases.
l Programs must be debugged statically from snapshot dump. A programmer
cannot modify a program during its execution to study its behaviour.
l Experimentation with program requires long turnaround time.
1.3.4 Multitasking (Time Sharing System)
Timesharing is the term concern with the allotment of computer resources on a basis
of timeslice to various program at same time. Time sharing or multitasking is a logical
expansion of multiprogramming. CPU switches one job from multiple jobs that are
ready to execute, but it switches so rapidly that the user may interact with each
program during its execution.
Unlike multiprogramming, where programs are executed till an I/O is reached or
program is terminated, in timesharing the CPU time is divided among all the pro-
grams. The main idea is that all programs have a small slice of the CPU time in turn.
Each program, beginning from the first program and proceeding towards the last is
allocated a very short period of CPU time (known as time slice, time slot or time
quantum) one by one. The processing speed of the system allows the CPU to
switch from one user to another and to do a part of each job in the allocated time
slice until the job is completed. However since the human reaction time is too slow
because interactive I/O typically runs at people speeds (Input may be bounded by
the user’s typing speed) the response time on a properly designed system gives the
illusion to each user that he alone is using the computer, whereas actually one
computer is being shared by many users.
11
Operating Systems An interactive computer system provides an on-line communication to the
OS or to a program directly and receives an immediate response. Usually a key-
board is used to give input and a display screen is used for output. When the
operating system finishes the execution of one command it seeks the next command
NOTES not from a card reader, but rather from the user’s keyboard. The user gives a
command, waits for the response and decides the next command based on the
result of the previous one. The user can easily experiment and can see result imme-
diately.
Some new features like virtual memory, file system are introduced first time in the
time sharing system.
Advantages :
l It allows to interact with the program during execution.
l Programs can be easily debugged.
l It reduces CPU idle time.
Disadvantages :
l A very frequent switching of CPU from one process to another required special
CPU scheduling algorithm.
l Since a CPU can switch during the execution of a process special memory
protection mechanism is required to protect one process data from accessing by
other process.
1.3.5 Multiprocessing System (Parallel System)
These type of OS have multiple processor which shares their bus, clock, memory
and input/output devices. These systems are called parallel computers, multicomputers,
or multiprocessors. They are also called tightly coupled system because they have
more than one processor in close communication sharing the computer bus, the
clock, memory and peripheral devices. The term multiprocessing is defined as
computers with two or more independent CPUs all having the capability to execute
several programs at same time. In such a system, instructions from different and
independent programs can be processed at the same instant of time by different
CPUs or the CPUs may simultaneously execute different instructions from the same
program.
Multiprocessing system can be further classified into
l Symmetric multiprocessing l Asymmetric multiprocessing
Symmetric multiprocessing
Symmetric multiprocessing is one in which each processor runs an identical copy of
the operating system and these copies communicate with one another as needed.
The benefit of the symmetric multiprocessing is that many process can run at once
without decreasing the performance. The weakness of the system is that, we must
carefully control I/O to ensure that data reach the appropriate processor. Also, since
the CPUs are separate, and there is no controlling device it can happen that one
processor is idle while another is overloaded.
Asymmetric multiprocessing
Asymmetric multiprocessing is one in which each processor is assigned a specific
task. Processors have a master-slave relationship. The master processor sched-
12
ules and allocates works to the slave processor. It is more common in very big
systems, where one of the big task is processing I/O. In such systems there are Operating System :
multiple processors at the user end whose work is just to process user’s input, Overview
controlling to these processors and other processing work is done by one or more
central processors.
Advantages of parallel systems NOTES
fd=open(file,how,…)
Open a file for reading, writing or both. Returns a file descriptor (fd). NOTES
b. close( ):- The syntax is
s=close(fd)
Close an opened file specified by the fd. Returns a code s that is -1 if an
error has occurred.
c. read( ):- The syntax is
n = read(fd, buffer, nbytes)
Read n bytes of data from a file specified by fd into a buffer. Returns actual
number of bytes read.
d. write( ):- The syntax is
n = write(fd, buffer, nbytes)
write n bytes of data into a file specified by fd from a specified buffer.
Returns actual number of bytes written.
e. lseek( ):- The syntax is
position=lseek(fd, offset, from)
Move the file pointer of the file specified by fd, to number of bytes specified
by offset from beginning, current position or end as specified by the from.
Returns the new position of the file pointer.
f. stat( ):- The syntax is
s=stat(name, &buf)
Get status information in the buf of a file specified by the name.
3. System Calls for Directory and file system management
a. mkdir( ):- The syntax is
s=mkdir(name, mode)
Create a new directory of the specified name and mode (read, write, execute).
b. rmdir( ):- The syntax is
s=rmdir(name)
Remove an empty directory in which name is specified as argument.
c. link( ):- The syntax is
s=link(name1, name2)
Create a new entry, name2, pointing to name1. After this call name2 can be
used as a link to name1.
d. unlink( ):- The syntax is
s=unlink(name)
Remove a directory entry for a link file.
e. mount( ):- The syntax is
17
s=mount(special, name, flag)
Operating Systems Allows two file systems to be merged into one. ‘special’ specifies device major or
minor number of the file system to be mounted, ‘name’ specifies the location where
the file system will be mounted and flag specifies whether the file system is to be
mounted read-write or read-only.
NOTES
f. unmount( ):- The syntax is
s=unmount(special)
Unmount a mounted file system.
4. Miscellaneous System Calls
a. chdir( ):- The syntax is
s=chdir(dirname)
Change the working directory.
b. chmod ( ):- The syntax is
s=chmod(name, mode)
Change the file’s protection bits. Mode can be read, write or execute.
c. kill( ):- The syntax is
s=kill(pid, signal)
Send a signal to a process specified by pid.
1.6 SYSTEM PROGRAMS
As you can see in hierarchy utility/system programs appears just above the Oper-
ating System. They provide a convenient environment for program development and
execution. They are-
1. Text Editor : This program is used for creating and editing text files. Using this
program any text matter can be typed and saved on a disk file. This file can be
retrieved any time and can also be edited, corrected etc. Text editor program
supports special commands for text editing i.e., you can insert, delete, find and
replace characters, lines and paragraphs.
2. File management : So many programs are available to perform file manage-
ment tasks such as create, delete, copy, rename, print, dump, list, and generally
manipulate files and directories.
3. Language Processors : As we know programmers prefer to write their pro-
grams in one of the High Level Languages (Language that are similar to English
like languages). However, the computer does not understand any language other
than its own machine language (binary language) therefore, it becomes neces-
sary to process a High level language program so as to make it understandable
18 to the computer. The system programs which perform this job are language
processors. These language processors can also be divided into – Operating System :
Overview
i. Assembler ii. Interpreter iii. Compiler
Debugger is also a system program that is used to rectify the logical errors
NOTES
(bugs) in a program.
4. Loader, Linker : When a program is created it may have many address
references to other locations. Each such reference can be expressed only sym-
bolically. The linker combines all such references in one place. Once a program
is assembled or compiled, it must be loaded into memory to be executed. The
system program which perform this task is called Loader.
5. Status information : To provide information about system performance, log-
ging details, disk space, system hardware, power management, system configu-
ration, date, time, memory availability, users detail and for similar status infor-
mation some system programs are available.
6. Communications : These system programs are used for creating virtual con-
nections among processes, users, and computer systems. These program allows
users to send messages to one another’s screens, to browse web pages, to send
electronic-mail messages, to log in remotely, or to transfer files from one ma-
chine to another.Together with these system programs this layer also contains
the utility programs. These utility programs includes data backup, anti virus, disk
defragmentor, data compression etc.
1.7 SYSTEM STRUCTURE
The first OS developed was very simple and small in size. With the evaluation of
OS more and more features have been added and the underlying hardware became
more complex and versatile. This results in the operating system of greater size and
complexity. The size of a full-featured operating system and the difficulty of the task
it addresses have led to three unfortunate but common problems.
1. Operating systems are chronically late in being delivered.
2. The systems have latent bugs that show up in the field and must be fixed and
reworked.
3. Performance is often not as what was expected.
To manage the complexity of operating systems and to overcome these problems,
much attention has been given to the software structure of the operating system. In
the following section, we will examine different structures that have been tried.
1. Simple Structure or Monolithic Systems
The OS is written as a collection of procedures, each of which can call any of the
other ones whenever it needs to. Each procedure in the system has a well-defined
interface in terms of parameters and results, and each one is free to call any other 19
one, if the latter provides some useful computation that the former needs. However,
Operating Systems it is possible to have at least a little structure. The services (system calls) provided
by the operating system are requested by putting the parameters in a well-defined
place (e.g., on the stack) and then executing a trap instruction. This instruction
switches the machine from user mode to kernel mode and transfers control to the
NOTES
operating system. The operating system then fetches the parameters and determines
which system call is to be carried out. After that, it indexes into a table that contains
in slot k a pointer to the procedure that carries out system call k.
This organization suggests a basic structure for the operating system:
1. A main program that invokes the requested service procedure.
2. A set of service procedures that carry out the system calls.
3. A set of utility procedures that help the service procedures.
Main
Program
Service
Procedure
s
Utility
Procedure
s
Figure 1.4, structure of a monolithic system
Level n
Level 3
Level 2
Level 1
21
Operating Systems
NOTES
22
Operating System :
Overview
NOTES
Module 2 Module n
Module 1
26