Operating System: Hari Raghava
Operating System: Hari Raghava
Hari Raghava
1
System Software – Operating System
• Software platform on which other programs run
• Provides a connection between application programs and the
computer hardware
• Major tasks
– Starting the computer
– Managing files
• Keeping track of where files are located
• Maintaining a table of file entries
– Managing Programs and Memory (RAM)
• Sending programs to the CPU
• Allocating primary storage (RAM) to programs
• Controlling devices that programs requires
– Ensuring security
– Providing a user interface
2
Operating System cont…
Important Task of an OS (Operating System)
Starting or booting of the computer
Managing memory or memory management
Managing process or Process Management
Handling input and output
Providing the user interface
Device Controlling or Device Management
Disk Management
Data Security
3
Operating System cont…
Memory Management
Memory management refers to management of Primary Memory or Main Memory.
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 main 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.
Process 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 process 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.
4
Operating System cont…
Device Management
An Operating System manages device communication via their respective drivers. It does the
following activities for device management −
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.
5
Operating System - Process Lifecycle
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.
6
Operating System - Process Lifecycle cont…
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.
3 Running
Once the process has been assigned to a processor by the OS scheduler, the
process state is set to running and the processor executes its instructions.
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.
7
Operating System - Process Management
Process Management
Process ? A process is a program under execution. The main objective
of the process management is to manage the process submitted to a
system to minimize the idle system of the processor.
History
A programmer write a program, operator punch the program and data
on the tape and load it manually into the system.
The operator also loads the complier or any other hardware setting
devices. It also clears the memory of the previous program if exist.
The operator run the program and submit or print the result for the
programmer to collect and check it.
Above was a manual loading mechanism
8
Operating System - Process Management cont…
Next a method of automatic job to job transition was devised to reduce
the idle time. In this method known as Batch processing when one job
finishes, system control is transferred back automatically to the
operating system that performs initially the house keeping job
( cleaning of the memory), then load and execute the next program.
Batch Processing
Batch processing reduce the idle time of a processor as job to job
transfer does not require any manual intervention. Another reduction in
time was a set up time. If the similar jobs are batched together, say all
FORTRAN program, the compiler needs to be loaded once.
Later JCL (Job control language) was also introduced to determine the
new program and what resources it will need to execute. E.g. name of
the job, its user name, hardware and software requirements etc
Disadvantage is issue in one batch job can affect/delay pending jobs
9
Operating System - Process Management cont…
Multiprogramming
In a multiprogramming system there are one or more programs loaded in
main memory which are ready to execute. Only one program at a time is able
to get the CPU for executing its instructions (i.e., there is at most one process
running on the system) while all the others are waiting their turn.
The main idea of multiprogramming is to maximize the use of CPU time.
Indeed, suppose the currently running process is performing an I/O task
(which, by definition, does not need the CPU to be accomplished). Then, the
OS may interrupt that process and give the control to one of the other in-
main-memory programs that are ready to execute (i.e. process context
switching). In this way, no CPU time is wasted by the system waiting for the
I/O task to be completed, and a running process keeps executing until either
it voluntarily releases the CPU or when it blocks for an I/O operation.
Therefore, the ultimate goal of multiprogramming is to keep the CPU busy
as long as there are processes ready to execute.
10
Operating System - Process Management cont…
Note that in order for such a system to function properly, the OS must be
able to load multiple programs into separate areas of the main memory
and provide the required protection to avoid the chance of one process
being modified by another one.
Finally, note that if there are N ready processes and all of those are
highly CPU-bound (i.e., they mostly execute CPU tasks and none or very
few I/O operations), in the very worst case one program might wait all
the other N-1 ones to complete before executing.
11
Operating System - Process Management cont…
Multitasking
Multitasking has the same meaning of multiprogramming but in a more
general sense, as it refers to having multiple (programs, processes, tasks)
running at the same time. This term is used in modern operating systems
when multiple tasks share a common processing resource (e.g., CPU and
Memory). At any time the CPU is executing one task only while other
tasks waiting their turn. The illusion of parallelism is achieved when the
CPU is reassigned to another task.
There are subtle differences between multitasking and multiprogramming.
A task in a multitasking operating system is not a whole application
program but it can also refer to a “thread of execution” when one process
is divided into sub-tasks. Each smaller task does not hijack the CPU until
it finishes like in the older multiprogramming but rather a fair share
amount of the CPU time called quantum.
12
Operating System - Process Management cont…
Just to make it easy to remember, both multiprogramming and
multitasking operating systems are (CPU) time sharing systems.
However, while in multiprogramming (older OSs) one program as a
whole keeps running until it blocks, in multitasking (modern OSs) time
sharing is best manifested because each running process takes only a
fair quantum of the CPU time.
13
Operating System - Process Management cont…
Multiprocessing
Multiprocessing sometimes refers to executing multiple processes
(programs) at the same time. This might be misleading because we have
discussed the term “multiprogramming” to describe that before.
14
Operating System - Memory Management
Memory Management
Memory management is the functionality of an operating system which
handles or manages primary memory and moves processes back and
forth between main memory and disk during execution. Memory
management keeps track of each and every memory location, regardless
of either it is allocated to some process or it is free. It checks how much
memory is to be allocated to processes. It decides which process will get
memory at what time. It tracks whenever some memory gets freed or
unallocated and correspondingly it updates the status.
Small program get fit into the memory but what Program
about when the program gets big ?
Immediate option is to increase the memory MAIN
size MEMORY
But what about when there is multiple program to
be executed ?? 15
Operating System - Memory Management cont…
To allow more than one program to
run at the same time, the memory is
Program1 Partition1
subdivided into FIXED
Partition2
PARTITIONS
Program No
To make this work, the Memory Partition3
2
manager needs to keep a Partition Int
Table to remember the status of all the fragmentation
Program Number
partitions. 3
Partition4
But This has a drawback of
accommodating variable memory Partition5
programs resulting into wastage of
memory. Selecting the correct set of
partition sizes is a Program No Partition6
4
tricky business, too small and larger
programs will be waiting forever to run
Int
or there is a lot of wasted space i.e. fragmentation
16
Internal fragmentations
Operating System - Memory Management cont…
An alternative solution is DYNAMIC Program1 Partition1
PARTITIONS Program 2 Partition2
Big
Program 3 Partition3
It helps accommodating variable size
programs, where the program is given Biggest
Program Partition4
space it requests, if there is space
Number 4
available for it. But it also results into
external fragmentations. One
of
the Partition5
How?? Biggest
Program
Number
5
17
Operating System - Memory Management cont…
Program1 Partition1
Program 2 Partition2
Big
New Partition3
Program 3
Program
Waiting
Biggest
Program Partition4
Number 4
One
of
the Partition5
Biggest
Program
Number
5
18
Operating System - Memory Management cont…
Program1 Partition1
Program 2 Partition2
Big
New Partition3
Program 3
Program Waiting
Biggest
Program Partition4
Number 4
19
Operating System - Memory Management cont…
Program1 Partition1
So importantly however we Program 2 Partition2
partition, we end up with Big
Partition3
Program 3
fragmentation, one way or the
New
other. Program Partition4
External
One fragmentation
of
the Partition5
Biggest
Program
Number
5
20
Operating System - Memory Management cont…
So how do we decide where to slot in a new program?
Program1 Partition1
So we can either add the new block to
First Fit Partition2
the first available slot (FIRST-FIT
ALGORITHM) or we can add the new Big
block to the most suitable available slot Program 3
(BEST-FIT ALGORITHM). Big
New Program Program Partition4
If the Memory Manager wants a 4
FIRST-FIT ALGORITHM then it
stores a table in order of memory Best Fit
locations. The
If the Memory Manager wants a Biggest
BEST-FIT ALGORITHM then it stores Program
a table in order of size of memory Number
locations. 5
21
Operating System - Memory Management cont…
Virtual Memory
Why?
It allows us to run more applications on the system than we have enough
physical memory to support. Virtual memory is simulated memory that
is written to a file on the hard drive. That file is often called page file or
swap file. It's used by operating systems to simulate physical RAM by
using hard disk space. Swap In is moving in data from secondary storage
to main memory and Swap out is moving out from main memory to
secondary storage 22
Operating System – File Management
File Management
Create
Delete
Open
Close
Read
Write
Seek : Used with Random Access File
Rename
Get Attribute
Set Attribute
Copy
24
Operating System – Device Mgmt and Security
Device Management
25
Thanks
26