Overview of Operating Systems Functions
Overview of Operating Systems Functions
1
OPERATING SYSTEM
• 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.
• 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, etc.
2
3
• A computer system can be divided roughly into 4
components- hardware, OS, application programs
and the users.
• Hardware- CPU, memory, I/O devices provides the
basic computing resources.
• Application programs-Microsoft excel, outlook,
google chrome, compilers define the way in which
these resources are used to solve the computing
problems of the users.
• The OS controls and co-ordinates the use of the
hardware among the various application programs
for the various users.
4
Important functions of an operating
System.
• Memory Management
• Processor Management
• Device Management
• File Management
• Secondary storage management
5
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
be in the main memory.
• An Operating System does the following activities for
memory management −
1) Keeps tracks of primary memory, i.e., what part of it are
in use by whom, what part are not in use.
2) In multiprogramming, the OS decides which process will
get memory when and how much.
3) Allocates the memory when a process requests it to do
so.
4) De-allocates the memory when a process no longer
needs it or has been terminated. 6
Processor Management
• A process needs certain resources-including CPU time, memory
files and I/O devices to accomplish its task. These resources are
either given to the process when it is created or allocated to it
while it is running.
• A process is the unit of work in a system.
• Program is a passive entity, such as the contents of a file stored on
disk, whereas a process is an active entity, with a program counter
specifying the next instruction to execute. Execution of a process
must be sequential.
• The CPU executes one instruction after another, until the process
completes.
• An Operating System does the following activities for processor
management −
1) Keeps tracks of processor and status of process. The program
responsible for this task is known as traffic controller.
2) Allocates the processor (CPU) to a process.
3) De-allocates processor when a process is no longer required.
7
Device Management
• An Operating System manages device
communication via their respective drivers.
• It does the following activities for device
management −
1) Keeps tracks of all devices. Program responsible
for this task is known as the I/O controller.
2) Decides which process gets the device when
and for how much time.
3) Allocates the device in the efficient way.
4) De-allocates devices.
8
File Management
9
Other Important Activities:
• 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 error messages,
and other debugging and error detecting aids.
• Coordination between other softwares and users −
Coordination and assignment of compilers,
interpreters, assemblers and other software to the
various users of the computer systems.
10
Other Important Activities:
• Resource Allocation:-
1) When multiple users are logged on the
system or multiple jobs are running at the
same time, resources must be allocated to
them.
2) Many different types of resources are
managed by the OS like CPU scheduling etc.,
11
Types of operating systems
• Batch OS
• Time sharing OS
• Distributed OS
• Network OS
• Real time OS( hard and soft)
12
Batch OS
• The users of a batch operating system do not interact with
the computer directly.
• 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 −
1) Lack of interaction between the user and the job.
2) CPU is often idle, because the speed of the
mechanical I/O devices is slower than the CPU.
3) Difficult to provide the desired priority.
13
Time sharing OS
• 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
14
Time sharing OS
15
Time sharing OS
• 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 :
1) Provides the advantage of quick response.
2) Reduces CPU idle time.
16
Distributed OS
• 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.
17
Distributed OS
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.
18
Network OS
• 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
19
Network OS
• The advantages of network operating systems are as follows −
20
Real Time operating System
• A real-time operating system (RTOS) is an
operating system (OS) intended to serve real-time
application process data as it comes in, typically
without buffering delays.
• Processing time requirements (including any OS
delay) are measured in tenths of seconds or
shorter increments of time.
• They are either event driven or time sharing.
Event driven system switches between task based
on their priorities while time sharing switch the
task based on clock interrupts.
21
Real time OS
• Real-time systems are used when there are rigid
time requirements on the operation of a
processor or the flow of data and real-time
systems can be used as a control device in a
dedicated application.
• A real-time operating system must have well-
defined, fixed time constraints, otherwise the
system will fail.
• For example, Scientific experiments, medical
imaging systems, industrial control systems,
weapon systems, robots, air traffic control
systems, etc.
22
Real time OS
• There are two types of real-time operating systems.
1) 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.
2) 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.
23
OS-properties
Batch processing
• Batch processing is a technique in which an Operating
System collects the programs and data together in a
batch before processing starts.
• The OS defines a job which has predefined sequence
of commands, programs and data as a single unit.
• The OS keeps a number a jobs in memory and
executes them without any manual information.
• Jobs are processed in the order of submission, i.e., first
come first served fashion.
• When a job completes its execution, its memory is
released and the output for the job gets copied into an
output spool for later printing or processing.
24
OS-properties
• Batch processing: Advantages
• Batch processing takes much of the work of the operator to the
computer.
• Increased performance as a new job get started as soon as the
previous job is finished, without any manual intervention.
Disadvantages
• Difficult to debug program.
• A job could enter an infinite loop.
• Due to lack of protection scheme, one batch job can affect pending
jobs.
25
OS-properties
Multitasking
• Multitasking is when multiple jobs are executed by the CPU simultaneously by
switching between them. Switches occur so frequently that the users may
interact with each program while it is running.
• The user gives instructions to the operating system or to a program directly,
and receives an immediate response.
• The OS handles multitasking in the way that it can handle multiple
operations/executes multiple programs at a time.
• Multitasking Operating Systems are also known as Time-sharing systems.
• These Operating Systems were developed to provide interactive use of a
computer system at a reasonable cost.
• A time-shared operating system uses the concept of CPU scheduling and
multiprogramming to provide each user with a small portion of a time-shared
CPU.
• Each user has at least one separate program in memory.
26
OS-properties(multi tasking)
➢A program that is loaded into memory and is executing is commonly referred to as a
process.
➢When a process executes, it typically executes for only a very short time before it either
finishes or needs to perform I/O.
➢Since interactive I/O typically runs at slower speeds, it may take a long time to complete.
During this time, a CPU can be utilized by another process.
➢The operating system allows the users to share the computer simultaneously. Since each
action or command in a time-shared system tends to be short, only a little CPU time is needed
for each user.
➢As the system switches CPU rapidly from one user/program to the next, each user is given
the impression that he/she has his/her own CPU, whereas actually one CPU is being shared
among many users.
27
OS-properties(multiprogramming)
Multiprogramming
❖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.
28
Multiprogramming
29
Multiprogramming
An OS does the following activities related to multiprogramming:
30
Operating System - Processes
Process
• A process is basically a program in execution.
• The execution of a process must progress in a sequential fashion.
• A process is defined as an entity which represents the basic unit of
work to be implemented in the system.
• To put it in simple terms, we write our computer programs in a
text file and when we execute this program, it becomes a process
which performs all the tasks mentioned in the program.
• When a program is loaded into the memory and it becomes a
process, it can be divided into four sections ─ stack, heap, text and
data.
• The following image shows a simplified layout of a process inside
main memory −
31
Operating System - Processes
32
OS-process
1) Stack: The process Stack contains the temporary
data such as method/function parameters,
return address and local variables.
2) Heap: This is dynamically allocated memory to a
process during its run time.
3) Text: This includes the current activity
represented by the value of Program Counter and
the contents of the processor's registers.
4) Data: This section contains the global and static
variables.
33
Process life cycle
34
Process life cycle
• When a process executes, it passes through different
states. These stages may differ in different operating
systems, and the names of these states are also not
standardized.
• In general, a process can have one of the following five
states at a time.
1) Start: This is the initial state when a process is first
started/created.
2) Ready: The process is waiting to be assigned to a
processor. Ready processes are waiting to have the
processor allocated to them by the operating system
so that they can run. Process may come into this state
after Start state or while running it by but interrupted
by the scheduler to assign CPU to some other process.
35
Process life cycle
3) Running: Instructions are being executed.
4) Waiting: Process moves into the waiting state if it
needs to wait for a resource, such as waiting for
user input, or waiting for a file to become
available.
5) Terminated or Exit: Once the process finishes its
execution, or it is terminated by the operating
system, it is moved to the terminated state where
it waits to be removed from main memory.
36
Process control block-A Process Control Block is a data structure
maintained by the Operating System for every process. The PCB
is identified by an integer process ID (PID).
• A PCB keeps all the information needed to keep track of a
process as listed below in the table −
1) Process State: The current state of the process i.e.,
whether it is ready, running, waiting, or whatever.
2) Process privileges: This is required to allow/disallow access
to system resources.
3) Process ID: Unique identification for each of the process in
the operating system.
4) Pointer: A pointer to parent process.
5) Program Counter: Program Counter is a pointer to the
address of the next instruction to be executed for this
process.
37
Process control block
6) CPU registers: Various CPU registers where process need to
be stored for execution for running state.
7) CPU Scheduling Information: Process priority and other
scheduling information which is required to schedule the
process.
8) Memory management information: This includes the
information of page table, memory limits, Segment table
depending on memory used by the operating system.
9) Accounting information: This includes the amount of CPU
used for process execution, time limits, execution ID etc.
10) IO status information: This includes a list of I/O devices
allocated to the process.
38
The architecture of a PCB is completely dependent on Operating
System and may contain different information in different
operating systems. Here is a simplified diagram of a PCB −
39
OS-process scheduling
• The process scheduling is the activity of the process
manager that handles the removal of the running
process from the CPU and the selection of another
process on the basis of a particular strategy.
• 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 at a time and the loaded
process shares the CPU using time multiplexing.
• A process migrates between the various scheduling
queues throughout its lifetime. The OS must select for
scheduling purposes and the selection process is
carried out by a Scheduler.
40
Process scheduling
Process Scheduling Queues
• The OS maintains all PCBs in Process Scheduling Queues.
• The OS maintains a separate queue for each of the process states
and PCBs of all processes in the same execution state are placed in
the same queue. When the state of a process is changed, its PCB is
unlinked from its current queue and moved to its new state
queue.
• The Operating System maintains the following important process
scheduling queues −
• Job queue − This queue keeps all the processes in the system.
• Ready queue − This queue keeps a set of all processes residing in
main memory, ready and waiting to execute. A new process is
always put in this queue.
• Device queues − The processes which are blocked due to
unavailability of an I/O device constitute this queue.
41
Process scheduling
▪The OS can use different policies to manage each queue (FIFO, Round Robin, Priority,
etc.).
▪The OS scheduler determines how to move processes between the ready and run queues
which can only have one entry per processor core on the system; in the above diagram, it
has been merged with the CPU.
42
Two-State Process Model
• Two-state process model refers to running and non-
running states which are described below −
1) Running: When a new process is created, it enters
into the system as in the running state.
2) Not Running: Processes that are not running are kept
in queue, waiting for their turn to execute.
➢ Each entry in the queue is a pointer to a
particular process. Queue is implemented by using
linked list.
➢ Use of dispatcher is as follows: When a process is
interrupted, that process is transferred in the waiting
queue. If the process has completed or aborted, the
process is discarded. In either case, the dispatcher
then selects a process from the queue to execute.
43
Schedulers
44
Long term scheduler
• It is also called a job scheduler. A long-term scheduler determines
which programs are admitted to the system for processing.
• It selects processes from the queue and loads them into memory
for execution. Process loads into the memory for CPU scheduling.
46
Medium term scheduler
• Medium-term scheduling is a part of swapping.
47
Comparison b/w schedulers
S. Long-Term Scheduler Short-Term Scheduler Medium-Term
N. Scheduler
It is a process
1 It is a job scheduler It is a CPU scheduler
swapping scheduler.
Speed is in between
Speed is lesser than Speed is fastest
2 both short and long
short term scheduler among other two
term scheduler.
It provides lesser
It controls the degree of It reduces the degree
3 control over degree of
multiprogramming of multiprogramming.
multiprogramming
It is almost absent or
It is also minimal in It is a part of Time
4 minimal in time sharing
time sharing system sharing systems.
system
It can re-introduce
It selects processes from It selects those the process into
5 pool and loads them into processes which are memory and
memory for execution ready to execute execution can be
continued.
48
Context switch
50
context switch
• Context switches are computationally intensive since register and
memory state must be saved and restored.
• To avoid the amount of context switching time, some hardware
systems employ two or more sets of processor registers.
• When the process is switched, the following information is stored
for later use.
• Program Counter
• Scheduling information
• Base and limit register value
• Currently used register
• Changed State
• I/O State information
• Accounting information
51
Scheduling Algorithms
• Context switches are computationally intensive since
register and memory state must be saved and
restored. To avoid the amount of context switching
time, some hardware systems employ two or more
sets of processor registers. When the process is
switched, the following information is stored for later
use.
• Program Counter
• Scheduling information
• Base and limit register value
• Currently used register
• Changed State
• I/O State information
• Accounting information
52
Scheduling algorithms
• These algorithms are either non-preemptive or
preemptive.
• Non-preemptive algorithms are designed so that
once a process enters the running state, it cannot
be preempted until it completes its allotted time
• whereas the preemptive scheduling is based on
priority where a scheduler may preempt a low
priority running process anytime when a high
priority process enters into a ready state.
53
Types of Scheduling Algorithms
1) First come first serve(FCFS)
2) Short job next(SJN)
3) Priority based scheduling
4) Round Robin Scheduling
54
First Come First Serve (FCFS)
55
Short job next(SJN)
56
Priority based scheduling
• Priority scheduling can be either preemptive or
non-preemptive algorithm and one of the most
common scheduling algorithms in batch systems.
• Each process is assigned a priority. Process with
highest priority is to be executed first and so on.
• Processes with same priority are executed on first
come first served basis.
• Priority can be decided based on memory
requirements, time requirements or any other
resource requirement.
57
Priority scheduling
• When a process arrives at the ready queue, its
priority is compared with the priority of the
current running process.
• A preemptive priority scheduling algorithm will
preempt the CPU if the priority of the newly
arrived process is higher than the priority of the
currently running process.
• A non preemptive algorithm will simply put the
new process at the head of the ready queue.
58
Shortest remaining time
• Shortest remaining time (SRT) is the preemptive
version of the SJN algorithm.
• The processor is allocated to the job closest to
completion but it can be preempted by a newer
ready job with shorter time to completion.
• Impossible to implement in interactive systems
where required CPU time is not known.
• It is often used in batch environments where
short jobs need to give preference.
59
Round robin scheduling
60
Multiple-Level Queues Scheduling
• Multiple-level queues are not an independent
scheduling algorithm. They make use of other existing
algorithms to group and schedule jobs with common
characteristics.
• Multiple queues are maintained for processes with
common characteristics.
• Each queue can have its own scheduling algorithms.
• Priorities are assigned to each queue.
• For example, CPU-bound jobs can be scheduled in one
queue and all I/O-bound jobs in another queue. The
Process Scheduler then alternately selects jobs from
each queue and assigns them to the CPU based on the
algorithm assigned to the queue.
61
Thread
• A thread is the smallest unit of processing that can be
performed in an OS.
• In most modern operating systems, a thread exists
within a process - that is, a single process may contain
multiple threads
• Multitasking allows processes to run concurrently,
while multithreading allows sub-processes to run
concurrently.
• Basically, an operating system with multitasking
capabilities allows programs (or processes) to run
seemingly at the same time. On the other hand, a
single program with multithreading capabilities allows
individual sub-processes (or threads) to run seemingly
at the same time.
62
Thread
➢ Each thread belongs to exactly one process and
no thread can exist outside a process.
➢ Each thread represents a separate flow of control.
➢ Threads have been successfully used in
implementing network servers and web server.
➢ They also provide a suitable foundation for
parallel execution of applications on shared
memory multiprocessors.
➢ The following figure shows the working of a
single-threaded and a multithreaded process.
63
Thread
64
Difference b/w process and thread
S. Process Thread
N.
Process is heavy weight or resource Thread is light weight, taking lesser
1
intensive. resources than a process.
Process switching needs interaction Thread switching does not need to
2
with operating system. interact with operating system.
If one process is blocked, then no While one thread is blocked and
3 other process can execute until the waiting, a second thread in the
first process is unblocked. same task can run.
Multiple processes without using Multiple threaded processes use
4
threads use more resources. fewer resources.
In multiple processes each process
One thread can read, write or
5 operates independently of the
change another thread's data.
others.
65
Advantages of Thread
• Threads minimize the context switching time.
• Use of threads provides concurrency within a
process.
• Efficient communication.
• It is more economical to create and context switch
threads.
• Threads allow utilization of multiprocessor
architectures to a greater scale and efficiency.
66
Types of Thread
67
User level threads-In this case, the thread management kernel is
not aware of the existence of threads. The thread library
contains code for creating and destroying threads, for passing
message and data between threads, for scheduling thread
execution and for saving and restoring thread contexts. The
application starts with a single thread.
68
User level threads
Advantages
• Thread switching does not require Kernel mode privileges.
• User level thread can run on any operating system.
• Scheduling can be application specific in the user level
thread.
• User level threads are fast to create and manage.
Disadvantages
• In a typical operating system, most system calls are
blocking.
• Multithreaded application cannot take advantage of
multiprocessing.
69
Kernel level threads
• In this case, thread management is done by the Kernel. There is no
thread management code in the application area.
• Kernel threads are supported directly by the operating system.
Any application can be programmed to be multithreaded.
• All of the threads within an application are supported within a
single process.
• The Kernel maintains context information for the process as a
whole and for individuals threads within the process.
• Scheduling by the Kernel is done on a thread basis. The Kernel
performs thread creation, scheduling and management in Kernel
space. Kernel threads are generally slower to create and manage
than the user threads.
70
Kernel level threads
Advantages
• Kernel can simultaneously schedule multiple threads
from the same process on multiple processes.
• If one thread in a process is blocked, the Kernel can
schedule another thread of the same process.
• Kernel routines themselves can be multithreaded.
Disadvantages
• Kernel threads are generally slower to create and
manage than the user threads.
• Transfer of control from one thread to another within
the same process requires a mode switch to the
Kernel.
71
Multithreading Models
• Some operating system provide a combined user
level thread and Kernel level thread facility. Solaris
is a good example of this combined approach. In a
combined system, multiple threads within the
same application can run in parallel on multiple
processors and a blocking system call need not
block the entire process. Multithreading models
are three types
• Many to many relationship.
• Many to one relationship.
• One to one relationship.
72
Many to Many Model
• The many-to-many model multiplexes any number
of user threads onto an equal or smaller number
of kernel threads.
• The following diagram shows the many-to-many
threading model where 6 user level
• In this model, developers can create as many user
threads as necessary and the corresponding
Kernel threads can run in parallel on a
multiprocessor machine.
• This model provides the best accuracy on
concurrency and when a thread performs a
blocking system call, the kernel can schedule
another thread for execution.
73
Many to many model
74
Many to One model
• Many-to-one model maps many user level threads
to one Kernel-level thread. Thread management is
done in user space by the thread library.
• When thread makes a blocking system call, the
entire process will be blocked. Only one thread
can access the Kernel at a time, so multiple
threads are unable to run in parallel on
multiprocessors.
• If the user-level thread libraries are implemented
in the operating system in such a way that the
system does not support them, then the Kernel
threads use the many-to-one relationship modes.
75
Many to One model
76
One to One Model
• There is one-to-one relationship of user-level
thread to the kernel-level thread.
• This model provides more concurrency than the
many-to-one model.
• It also allows another thread to run when a
thread makes a blocking system call.
• It supports multiple threads to execute in parallel
on microprocessors.
• Disadvantage of this model is that creating user
thread requires the corresponding Kernel thread.
OS/2, windows NT and windows 2000 use one to
one relationship model.
77
One to One model
78
Difference between User-Level &
Kernel-Level Thread
S.N. User-Level Threads Kernel-Level Thread
79