Unit 1
Unit 1
LECTURE NOTES
i
UNIT-I
Operating System-Introduction, Structures-Simple Batch, Multi-programmed, Time-shared, Personal
Computer,Parallel, Distributed Systems, Real-Time Systems , System components, Operating System
services.
Process - Process concepts and scheduling, Operations on processes, Cooperating Processes, Threads
Operating System-Introduction:
A computer system has many resources (hardware and software), which may be required to complete a
task. The commonly required resources are input/output devices, memory, file storage space, CPU,
etc. The operating system acts as a manager of the above resources and allocates them to specific
programs and users, whenever necessary to perform a particular task. Therefore the operating system
is the resource manager i.e. it can manage the resource of a computer system internally. The resources
are processor, memory, files, and I/O devices.
In simple terms, an operating system is an interface between the computer user and the machine.
It is very important for you that every computer must have an operating system in order to run other
programs. The operating system mainly coordinates the use of the hardware among the various system
programs and application programs for various users.
An operating system acts similarly like government means an operating system performs no useful
function by itself; though it provides an environment within which other programs can do useful work.
Below we have an abstract view of the components of the computer
system:
In the above picture:
The Computer Hardware contains a central processing unit(CPU), the memory, and the
input/output (I/O) devices and it provides the basic computing resources for the system.
1
The Application programs like spreadsheets, Web browsers, word processors, etc. are used
to define the ways in which these resources are used to solve the computing problems of the users.
And the System program mainly consists of compilers, loaders, editors, OS, etc.
The Operating System is mainly used to control the hardware and coordinate its use among the
various application programs for the different users.
Basically, Computer System mainly consists of hardware, software, and
data. OS is mainly designed in order to serve two basic purposes:
1. The operating system mainly controls the allocation and use of the computing System’s resources
among the various user and tasks.
2. It mainly provides an interface between the computer hardware and the programmer that
simplifies and makes feasible for coding, creation of application programs and debugging
Two Views of Operating System
1. User's View
2. System View
Operating System: User View
The user view of the computer refers to the interface being used. Such systems are designed for one
user to monopolize its resources, to maximize the work that the user is performing. In these cases,
the operating system is designed mostly for ease of use, with some attention paid to performance,
and none paid to resource utilization.
Operating System: System View
The operating system can be viewed as a resource allocator also. A computer system consists of
many resources like - hardware and software - that must be managed efficiently. The operating
system acts as the manager of the resources, decides between conflicting requests, controls the
execution of programs, etc.
Types of Operating System
Given below are different types of Operating System:
1. Simple Batch System
2. Multiprogrammed
3. Time-Shared
4. Personal Computer
5. Parallel
6. Distributed Systems
7. Real Time Systems
2
1. Simple Batch System os
In a Batch Operating System, the similar jobs are grouped together into batches with the help of
some operator and these batches are executed one by one. For example, let us assume that we have
10 programs that need to be executed. Some programs are written in C++, some in C and rest in
Java. Now, every time when we run these programmes individually then we will have to load the
compiler of that particular language and then execute the code. But what if we make a batch of
these 10 programmes. The benefit with this approach is that, for the C++ batch, you need to load
the compiler only once. Similarly, for Java and C, the compiler needs to be loaded only once and
the whole batch gets executed. The following image describes the working of a Batch Operating
System.
Advantages:
1. The overall time taken by the system to execute all the programmes will be reduced.
2. The Batch Operating System can be shared between multiple users.
Disadvantages:
1. Manual interventions are required between two batches.
2. The CPU utilization is low because the time taken in loading and unloading of batches is very
high as compared to execution time.
2 Multiprogramming OS
Sharing the processor, when two or more programs reside in memory at the same time, is referred
as multiprogramming. Multiprogramming assumes a single shared processor. Multiprogramming
increases CPU utilization by organizing jobs so that the CPU always has one to execute.
3
The following figure shows the memory layout for a multiprogramming
system.
An OS does the following activities related to multiprogramming.
• The operating system keeps several jobs in memory at a time.
• This set of jobs is a subset of the jobs kept in the job pool.
• The operating system picks and begins to execute one of the jobs in the memory.
• Multiprogramming operating systems monitor the state of all active programs
and system resources using memory management programs to ensures that the CPU is
never idle, unless there are no jobs to process.
Advantages
• High and efficient CPU utilization.
• User feels that many programs are allotted CPU almost simultaneously.
Disadvantages
• CPU scheduling is required.
• To accommodate many jobs in memory, memory management is required.
3 Time-Sharing Operating System
In a Multi-tasking Operating System, more than one processes are being executed at a particular
time with the help of the time-sharing concept. So, in the time-sharing environment, we decide a
time that is called time quantum and when the process starts its execution then the execution
continues for only that amount of time and after that, other processes will be given chance for that
amount of time only. In the next cycle, the first process will again come for its execution and it
will be executed for that time quantum only and again next process will come. This process will
continue. The following image describes the working of a Time-Sharing Operating System.
4
Advantages:
1. Since equal time quantum is given to each process, so each process gets equal opportunity to
execute.
2. The CPU will be busy in most of the cases and this is good to have case.
Disadvantages:
1. Process having higher priority will not get the chance to be executed first because the equal
opportunity is given to each process.
4 Personal Computers os
Personal computer operating system provides a good interface to a single user.
Personal computer operating systems are widely used for word processing, spreadsheets and Internet
access.
Personal computer operating system are made only for personal.You can say that your laptops,
computer systems, tablets etc. are your personal computers and the operating system such as
windows 7, windows 10, android, etc. are your personal computer operating system.
And you can use your personal computer operating system for your personal purposes, for example,
to chatting with your friends using some social media sites, reading some articles from internet,
making some projects through microsoft powerpoint or any other, designing your website,
programming something, watching some videos and movies, listening to some songs and many
more.
5
5. Parallel Processing OS
Parallel processing requires multiple processors and all the processor works simultaneously in
the system. Here, the task is divided into subparts and these subparts are then distributed
among the available processors in the system. Parallel processing completes the job on the
shortest possible time. All the processors in the parallel processing environment should run on the same
operatingsystem. All the processors in the system share the common secondary storage like the hard disk.
There is one more thing that all the processors in the system share i.e. the user terminal (from
where the user interact with the system). The user need not to be aware of the inner architecture of
the machine. He should feel that he is dealing with the single processor only and his interaction with
the system would be the same as in a single processor,
Advantages
1. It saves time and money as many resources working together will reduce the time and cut
potential costs.
2. It can be impractical to solve larger problems on Serial Computing.
3. It can take advantage of non-local resources when the local resources are finite.
4. Serial Computing ‘wastes’ the potential computing power, thus Parallel Computing makes
better work of the hardware.
Disadvantages
1. It addresses such as communication and synchronization between multiple sub-tasks and
processes which is difficult to achieve.
2. The algorithms must be managed in such a way that they can be handled in a parallel
mechanism.
6
3. The algorithms or programs must have low coupling and high cohesion. But it’s difficult to
create such programs.
4. More technically skilled and expert programmers can code a parallelism-based program well.
6 Distributed Operating System
These types of the operating system is a recent advancement in the world of computer technology
and are being widely accepted all over the world and, that too, with a great pace. Various
autonomous interconnected computers communicate with each other using a shared
communication network. Independent systems possess their own memory unit and CPU. These are
referred to as loosely coupled systems or distributed systems. These system’s processors differ in
size and function. The major benefit of working with these types of the operating system is that it
is always possible that one user can access the files or software which are not actually present on
his system but some other system connected within this network i.e., remote access is enabled
within the devices connected in that network.
7
7 Real Time Operating System:
It is developed for real-time applications where data should be processed in a fixed, small duration
of time. It is used in an environment where multiple processes are supposed to be accepted and
processed in a short time. RTOS requires quick input and immediate response, this system is used to
control scientific instruments, missile launch systems, traffic lights control systems, air traffic
control systems, etc.
This system is further divided into two types based on the time constraints:
Hard Real-Time Systems:
These are used for the applications where timing is critical or response time is a major factor; even a
delay of a fraction of the second can result in a disaster. For example, airbags and automatic
parachutes that open instantly in case of an accident. Besides this, these systems lack virtual
memory.
Soft Real-Time Systems:
These are used for application where timing or response time is less critical. Here, the failure to meet
the deadline may result in a degraded performance instead of a disaster. For example, video
surveillance (cctv), video player, virtual reality, etc. Here, the deadlines are not critical for every task
every time.
Advantages of real-time operating system:
o The output is more and quick owing to the maximum utilization of devices and system
o Task shifting is very quick, e.g., 3 microseconds, due to which it seems that several tasks are
executed simultaneously
o Gives more importance to the currently running applications than the queued application
o It can be used in embedded systems like in transport and others.
o It is free of errors.
8
o Memory is allocated appropriately.
Disadvantages of real-time operating system:
o A fewer number of tasks can run simultaneously to avoid errors.
o It is not easy for a designer to write complex and difficult algorithms or proficient programs
required to get the desired output.
o Specific drivers and interrupt signals are required to respond to interrupts quickly.
o It may be very expensive due to the involvement of the resources required to work.
1) Program Execution
An operating system must be able to load many kinds of activities into the memory and to run it.
The program must be able to end its execution, either normally or abnormally.
A process includes the complete execution of the written program or code. There are some of the
activities which are performed by the operating system:
9
o The operating system Loads program into memory
o It also Executes the program
o It Handles the program’s execution
o It Provides a mechanism for process synchronization
o It Provides a mechanism for process communication
2) I/O Operations
The communication between the user and devices drivers are managed by the operating system.
I/O devices are required for any running process. In I/O a file or an I/O devices can be involved.
I/O operations are the read or write operations which are done with the help of input-output
devices.
Operating system give the access to the I/O devices when it required.
3) File system manipulation
The collection of related information which represent some content is known as a file. The
computer can store files on the secondary storage devices. For long-term storage purpose. examples
of storage media include magnetic tape, magnetic disk and optical disk drives like CD, DVD.
A file system is a collection of directories for easy understand and usage. These directories
contain some files. There are some major activities which are performed by an operating system
with respect to file management.
o The operating system gives an access to the program for performing an operation on the
file.
o Programs need to read and write a file.
o The user can create/delete a file by using an interface provided by the operating system.
o The operating system provides an interface to the user creates/ delete directories.
o The backup of the file system can be created by using an interface provided by the
operating system.
4) Communication
In the computer system, there is a collection of processors which do not share memory peripherals
devices or a clock, the operating system manages communication between all the processes.
Multiple processes can communicate with every process through communication lines in the
network. There are some major activities that are carried by an operating system with respect to
communication.
Two processes may require data to be transferred between the process.
10
Both the processes can be on one computer or a different computer, but are connected through a
computer network.
5) Error handling
An error is one part of the system that may cause malfunctioning of the complete system. The
operating system constantly monitors the system for detecting errors to avoid some situations. This
give relives to the user of the worry of getting an error in the various parts of the system causing
malfunctioning.
The error can occur anytime and anywhere. The error may occur anywhere in the computer system
like in CPU, in I/O devices or in the memory hardware. There are some activities that are performed
by an operating system:
The OS continuously checks for the possible errors.
The OS takes an appropriate action to correct errors and consistent computing.
6) Resource management
When there are multiple users or multiple jobs running at the same time resources must be allocated
to each of them. There are some major activities that are performed by an operating system:
The OS manages all kinds of resources using schedulers.
CPU scheduling algorithm is used for better utilization of CPU.
1. Process Management
2. File Management
3. Network Management
4. Main Memory Management
5. I/O Device Management
11
1. Process Management
The process management component is a procedure for managing many processes running simultaneously on the operating
system. Every running software application program has one or more processes associated with them.
2. File management:
3. Network Management
12
4 Main Memory Management
It is mainly based on the hardware design of the system. Each algorithm requires
corresponding hardware support. Main memory offers fast storage that can be accessed directly
by the CPU. It is costly and hence has a lower storage capacity. However, for a program to be
executed, it must be in the main memory.
13
Process Concepts
A process is a program at the time of execution.
Differences between Process and Program
Process Program
Process is a dynamic object Program is a static object
Process States
When a process executed, it changes the state, generally the state of process is
determined by the current activity of the process. Each process may be in one of the
following states:
1. New : The process is being created.
2. Running : The process is being executed.
3. Waiting : The process is waiting for some event to occur.
4. Ready : The process is waiting to be assigned to a processor.
5. Terminated : The Process has finished execution.
Only one process can be running in any processor at any time, But many process may be
inready and waiting states. The ready processes are loaded into a “ready queue”.
Diagram of process state
14
a) New ->Ready : OS creates process and prepares the process to be executed, then OS
moved the process into ready queue.
b) Ready->Running : OS selects one of the Jobs from ready Queue and move themfrom ready
to Running.
c) Running->Terminated : When the Execution of a process has Completed, OS terminates that process
from running state. Sometimes OS terminates the process for some other reasons including Time exceeded,
memory unavailable, access violation, protection Error, I/O failure and soon.
d) Running->Ready : When the time slot of the processor expired (or) If the processor received any
interrupt signal, the OS shifted Running -> Ready State.
e) Running -> Waiting : A process is put into the waiting state, if the process need anevent occur (or) an
I/O Device require.
f) Waiting->Ready : A process in the waiting state is moved to readystate when the event for which it
has been Completed.
Process Control Block:
It is also called Task Control Block. It contains many pieces of information associated with a specific
Process.
Process State
Program Counter
CPU Registers
Accounting Information
15
4. CPU-Scheduling Info : includes a process pointer,
pointers to scheduling Queues,
other scheduling parameters etc.
5. Memory management Info: includes page tables, segmentation
tables, value ofbase and limit registers.
6. Accounting Information: includes amount of CPU used, time limits,
Jobs(or)Process numbers.
7. I/O Status Information: Includes the list of I/O Devices
Allocated to the processes, list ofopen files.
PROCESS SCHEDULING:
CPU is always busy in Multiprogramming. Because CPU switches from one job
to another job. But in simple computers CPU sit idle until the I/O request granted.
scheduling is a important OS function. All resources are scheduled before use.
(cpu, memory, devices…..) Process scheduling is an essential part of a
Multiprogramming operating systems. Such operating systems allow more than
one process to be loaded into the executable memory ata time and the loaded
process shares the CPU using time multiplexing.
Scheduler duties:
Operations on processes
The processes in most systems can execute concurrently and they may be
created and deleted dynamically.these system must orovides a mechanisam for
process creation and termination.
There are Two operations :
1 Process creation
Process creation means the construction of a new process for execution. This
might be performed by the system, the user, or the old process itself. There are
several events that lead to the process creation. Some of the such events are the
following:
1. we start the computer, the system creates several background processes.
2. A user may request to create a new process.
3. A process can create a new process itself while executing.
4. The batch system takes initiation of a batch job.
2. Process Termination
Process termination is the activity of ending the process. In other words, process
termination is the relaxation of computer resources taken by the process for the execution.
Like creation, in termination also there may be several events that may lead to the process
of termination. Some of them are:
1. The process completes its execution fully and it indicates to the OS that it has
finished.
2. The operating system itself terminates the process due to service errors.
3. There may be a problem in hardware that terminates the process.
4. One process can be terminated by another process.
17
Threads:
A process is divide into number of light weight process, each light weight process is said to be a
Thread. The Thread has a program counter (Keeps track of which instruction to execute next),
registers (holds its current working variables), stack (execution History).
Thread States:
Process Thread
Process takes more time to create. Thread takes less time to create.
it takes more time to complete execution & Less time to terminate.
terminate.
Execution is very slow. Execution is very fast.
It takes more time to switch b/w two It takes less time to switch b/w two
processes. threads.
Communication b/w two processes is difficult Communication b/w two threads is
. easy.
Process can’t share the same memory area. Threads can share same memory area.
System calls are requested to communicate System calls are not required.
each other.
Process is loosely coupled. Threads are tightly coupled.
It requires more resources to execute. Requires few resources to execute.
Multithreading
A process is divided into number of smaller tasks each task is called a Thread. Number
ofThreads with in a Process execute at a time is called Multithreading.
If a program, is multithreaded, even when some portion of it is blocked, the whole
program is not blocked. The rest of the program continues working If multiple CPU’s are
available.Multithreading gives best performance. If we have only a single thread,
number of CPU’s available, No performance benefits achieved.
Process creation is heavy-weight while thread creation is light-weight Can simplify
code, increase efficiency
18
19