R22_OS_Unit-I
R22_OS_Unit-I
UNIT-1
CH-1: OPERATING SYSTEM – I NTRODUCTION
CH-2: PROCESS
PREPARED BY GSK
Ch-1:
Operating System –
Introduction
PREPARED BY GSK
What is Operating System?
❖An Operating System (OS) is a software that acts as an interface
between computer hardware components and the user.
❖It 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.
❖An operating system is software that enables applications to
interact with a computer's hardware. The software that contains the
core components of the operating system is called the kernel.
PREPARED BY GSK
What is Operating System? Contd. .
PREPARED BY GSK
What is Operating System? Contd. .
➢Generally, a Computer System consists of the following components:
➢Application Software are the software which users use directly to perform
different activities. These software are simple and easy to use like Browsers,
Word, Excel, different Editors, Games etc. These are usually written in high-
level languages, such as Python, Java and C++.
➢System Software are the software which are more complex in nature. These
software are usually written in low-level languages like assembly language
and includes Operating Systems (Microsoft Windows, macOS, and Linux),
Compiler, and Assembler etc.
➢Computer Hardware includes Monitor, Keyboard, CPU, Disks, Memory, etc.
PREPARED BY GSK
❖If we consider a Computer Hardware is
body of the Computer System, then we can
In simple words.. say an Operating System is its soul which
brings it alive ie. operational.
The operating system is a soul to the
computer.
PREPARED BY GSK
Objectives of OS
PREPARED BY GSK
Objectives of OS Contd..
PREPARED BY GSK
History of OS
❖Operating systems were first developed in the late 1950s to
manage tape storage
❖In the mid-1960s, operating systems started to use disks
❖In the late 1960s, the first version of the Unix OS was
developed
❖The first OS built by Microsoft was DOS. It was built in 1981.
❖The Windows OS first came to existence in 1985 when a GUI
was created and paired with MS-DOS.
PREPARED BY GSK
Operating System with Market Share
PREPARED BY GSK
OS Structure…
Generic architecture diagram of an
Operating System
PREPARED BY GSK
PREPARED BY GSK
1. Batch Operating Systems
➢In the 1970s, Batch processing was very popular. In this technique,
similar types of jobs were batched together and executed in time.
People were used to having a single computer which was called a
mainframe.
➢In Batch operating system, operator has to collect the jobs and
submit jobs to the system for the execution.
➢The system put all of the jobs in a queue on the basis of first come
first serve and then executes the jobs one by one. The users collect
their respective output when all the jobs get executed.
PREPARED BY GSK
➢ In a Batch OS, users prepare tasks as jobs on offline devices like punch cards, which
are submitted to the computer operator.
➢ Similar job punch cards are grouped and processed as a batch to improve efficiency.
➢ Jobs include programs, input data, and control instructions.
PREPARED BY GSK
➢ The purpose of this operating system was mainly to transfer control from one job to
another as soon as the job was completed.
➢ It contained a small set of programs called the resident monitor that always resided in
one part of the main memory.
➢ The remaining part is used for servicing jobs.
PREPARED BY GSK
➢The batch processing system takes less time for
the execution of all the jobs.
Advantages
➢All jobs in a batch operating system are
Batch OS
repeated without the user's permission.
PREPARED BY GSK
▪The computer operator must be trained and provided
ample knowledge for handling the batch processing
operating system
Disadvantages ▪The users do not have direct interaction with the system
Batch OS Batch Processing is not suitable for jobs that are dependent
on the user's input. If a job requires the input of two
numbers from the console, then it will never get it in the
batch processing scenario since the user is not present at
the time of execution
▪If a job enters an infinite loop, other jobs might have to wait
for an unknown period of time. ( Called Starvation)
PREPARED BY GSK
2. Multiprogramming Operating System
Contd…
Example for Multiprogramming: On Android, iOS, and other mobile operating systems on the phone,
one can search on Google while sending and receiving text messages on what’s the app at one time.
This means these two programs are in the memory, and the CPU is switching between them.
PREPARED BY GSK
3. Multiprocessing Operating System
PREPARED BY GSK
❖Multi-processing operating system consists of multiple
CPUs. Each CPU is connected to the main memory.
Working of
❖The task to be performed is divided among all the
Multi-Processing processors.
Operating System
❖For faster execution and improved performance, each
processor is assigned a specific task.
❖Once all the tasks of each processor are completed they
are compiled together in order to produce a single output.
❖The allocation of resources for each processor is handled
by the operating system.
❖This process results in better utilization of the available
resources and improved performance.
PREPARED BY GSK
3. Multiprocessing Operating System
Contd…
PREPARED BY GSK
4. Time-Sharing Operating System
PREPARED BY GSK
4. Time-Sharing Operating System
Contd..
PREPARED BY GSK
4. Time-Sharing Operating System contd..
PREPARED BY GSK
5. Multitasking Operating systems
➢A multitasking operating system (OS) is a type
of multiprogramming OS that supports
multiple tasks or processes to run
concurrently
➢Single user’s multiple tasks are being
executed concurrently.
➢It is a logical extension of multiprogramming
➢For example – A mobile phone with multiple
apps running in the background while the user
interacts with another app in the foreground.
PREPARED BY GSK
Time sharing vs Multitasking
TIME SHARING MULTI TASKING
While time sharing allows multiple Multitasking allows a single user’s
users to use a computer system at a multiple tasks or processes to use a
time computer system at a time
PREPARED BY GSK
6. Distributed Operating System
PREPARED BY GSK
6. Distributed Operating System Contd..
PREPARED BY GSK
6. Distributed Operating System contd..
PREPARED BY GSK
Types of Distributed Operating System
I) Client-Server System:
❖This type of system requires
the client to request a
resource, after which the
server gives the requested
resource.
❖When a client connects to a
server, the server may serve
multiple clients at the same
time.
PREPARED BY GSK
Types of Distributed Operating System
PREPARED BY GSK
Types of Distributed Operating System
PREPARED BY GSK
Types of Distributed Operating System
PREPARED BY GSK
7. Real Time Operating System
PREPARED BY GSK
7. Real Time Operating System Contd..
PREPARED BY GSK
7. Real Time Operating System Contd..
PREPARED BY GSK
7. Real Time Operating System Contd..
❖FIRM RTOS: These types of RTOS are also required to adhere to the
deadlines because missing a deadline may not cause a catastrophic
affect but could cause undesired affects, like a huge reduction in
quality of a product which is highly undesired.
❖Soft RTOS: In these type of RTOS, missing a deadline is acceptable.
For example On-line Databases.
PREPARED BY GSK
8. Parallel Operating Systems
❖Parallel Operating Systems
help speed up the processing
time by dividing the task into
multiple sub-tasks or sub-
processes.
❖This way, numerous processors
can deal with various tasks
simultaneously.
PREPARED BY GSK
8. Parallel Operating Systems Contd..
❖It can be achieved using various processors in a single system.
❖Also, such systems can be used when multiple applications are to be
run simultaneously without interfering with each other.
❖A parallel operating system has many applications, such as database
and mining, various engineering fields, graphics, etc.
❖Some examples of parallel operating systems are
Linux with support for SMP (Symmetric Multi-Processing)
Windows Server for enterprise parallel processing
PREPARED BY GSK
Parallel Systems:
vs Distributed Systems:
Parallel Systems:
Definition: Parallel systems are designed to speed up program execution
by dividing programs into multiple fragments and processing these
fragments simultaneously.
Distributed Systems:
Definition: Distributed systems consist of multiple computers connected
by a network, where applications run on different computers.
PREPARED BY GSK
Functions of Operating System
1. Memory Management:
❖It is the management of the main or primary memory.
❖Whatever program is executed, it has to be present in the main
memory. Main memory is a quick storage area that may be accessed
directly by the CPU.
❖When the program is completed, the memory region is released and can
be used by other programs. Therefore, there can be more than one
program present at a time. Hence, it is required to manage the memory.
PREPARED BY GSK
Functions of Operating System
1. Memory Management:
As part of the memory management he operating system
❖Allocates and deallocates the memory.
❖Keeps a record of which part of primary memory is used by whom
and how much.
❖Distributes the memory while multiprocessing
PREPARED BY GSK
Functions of Operating System
2. Processor Management/Scheduling
❖Every software that runs on a computer, whether in the
background or in the frontend, is a process. Processor management
is an execution unit in which a program operates.
❖The operating system determines the status of the processor and
processes, selects a job and its processor, allocates the processor to
the process, and de-allocates the processor after the process is
completed.
PREPARED BY GSK
Functions of Operating System
2. Processor Management/Scheduling
❖When more than one process runs on the system the OS decides
how and when a process will use the CPU. Hence, the name is also
CPU Scheduling.
The OS:
❖Allocates and deallocates processor to the processes.
❖Keeps record of CPU status.
PREPARED BY GSK
Functions of Operating System
3. Device Management:
❖An operating system regulates device connection using drivers. The
processes may require devices for their use. This management is done by
the OS.
The OS:
❖Allocates and deallocates devices to different processes.
❖Keeps records of the devices.
❖Decides which process can use which device for how much time.
PREPARED BY GSK
Functions of Operating System
4. File Management
❖The operating system manages resource allocation and de-
allocation.
❖It specifies which process receives the file and for how long.
❖It also keeps track of information, location, uses, status, and so on.
❖ These groupings of resources are referred to as file systems. The
files on a system are stored in different directories
PREPARED BY GSK
Functions of Operating System
4. File Management
The OS:
❖Keeps records of the status and locations of files.
❖Allocates and deallocates resources.
❖Decides who gets the resources.
PREPARED BY GSK
Functions of Operating System
5. Storage Management
❖Storage management is a procedure that allows users to maximize
the utilization of storage devices.
❖The operating system is in charge of storing and accessing files. The
creation of files, the creation of directories, the reading and writing
of data from files and directories, as well as the copying of the
contents of files and directories from one location to another are all
included in storage management.
PREPARED BY GSK
Functions of Operating System
5. Storage Management
The OS uses storage management for:
❖Improving the performance of the data storage resources.
❖It optimizes the use of various storage devices.
❖Assists businesses in storing more data on existing hardware,
speeding up the data retrieval process, preventing data loss.
PREPARED BY GSK
Components of Operating System
❖An operating system is a large and complex system that can only be created by
partitioning into small parts. These pieces should be a well-defined part of the
system, carefully defining inputs, outputs, and functions.
❖Although Windows, Mac, UNIX, Linux, and other OS do not have the same
structure, most operating systems share similar OS system components, such as
file, memory, process, I/O device management.
PREPARED BY GSK
Functions of process management:
❖ Process creation and deletion.
❖ Suspension and resumption.
❖ Synchronization process
❖ Communication process
PREPARED BY GSK
2. File Management:
File is used to store related data permanently.
PREPARED BY GSK
3. Main Memory management
Functions for Memory Management:
❖ It helps you to keep track of primary memory.
❖ Determine what part of it are in use by whom, what
part is not in use.
❖ In a multiprogramming system, the OS decides which
process will get memory and how much.
❖ Allocates the memory when a process requests. It Main Memory management
also de-allocates the memory when a process no
longer requires or has been terminated.
PREPARED BY GSK
4. Secondary-Storage Management:
❑ The most important task of a computer system is to execute programs. These programs help
you to access the data from the main memory during execution.
❑ This memory of the computer is very small to store all data and programs permanently. The
computer system offers secondary storage to back up the main memory.
Functions of Secondary storage management:
❖ Storage allocation
❖ Free space management
❖ Disk scheduling
PREPARED BY GSK
5. I/O Device Management:
Functions of I/O management
❖ It offers a buffer caching system
❖ It provides drivers for particular hardware devices.
PREPARED BY GSK
6. Security Management:
➢ The various processes in an operating system need to be secured
from other activities. Therefore, various mechanisms can ensure
those processes that want to operate files, memory CPU, and other
hardware resources should have proper authorization from the
operating system.
➢ Security refers to a mechanism for controlling the access of programs,
processes, or users to the resources.
PREPARED BY GSK
7. Command Interpreter System:
PREPARED BY GSK
What is a Kernel?
❖The kernel is the central component of a computer operating systems. The only
job performed by the kernel is to the manage the communication between the
software and the hardware.
❖Kernel is the innermost part of an operating system, a shell is the outermost
one.
PREPARED BY GSK
System Calls
❖ Dual-mode operation provides a layer of protection between user programs and
the operating system
❖ User Mode: In this mode, execution is done on behalf of the user.
❖ Monitor/Kernel-Mode: In this mode, execution is done on behalf of OS.
❖ System calls are the interface between a user program and the operating
system, allowing the user program to request services from the operating
system. They provide a way for the user-level processes to communicate with
the kernel.
PREPARED BY GSK
How Does the System Call Work?
User need special resources :
❖Sometimes programs need to do some
special things which can’t be done
without the permission of OS like
reading from a file, writing to a file ,
getting any information from the
hardware or requesting a space in
memory.
PREPARED BY GSK
How Does the System Call Work? Contd…
❖Operating system sees the system call : When the OS sees the system call then
it recognizes that the program need help at this time so it temporarily stop the
program execution and give all the control to special part of itself called ‘Kernel’
Now ‘Kernel’ solve the need of program.
PREPARED BY GSK
How Does the System Call Work? Contd..
•Operating system performs the operations : Now the operating
system perform the operation which is requested by program .
Example : reading content from a file etc.
PREPARED BY GSK
Types of System Calls
PREPARED BY GSK
Types of System Calls Contd..
1. Process Control:
PREPARED BY GSK
Types of System Calls Contd..
2. Device Management:
❖For Example the system calls related to printer enable the OS to manage print
jobs and interact with printers for tasks such as queuing, pausing, and cancelling
print jobs. System calls related to scanners facilitate the communication
between the OS and scanning devices for document scanning.
PREPARED BY GSK
Types of System Calls Contd..
3. Information Maintenance:
❖Information maintenance system calls used to maintain (System)
information. There are some examples of information maintenance,
including getting system data, set time or date, get time or date etc.
❖These system calls ensure the accuracy and consistency of data stored in
the system, preventing corruption or loss.
❖They manage access controls and encryption, safeguarding sensitive
information from unauthorized access and potential breaches.
PREPARED BY GSK
Types of System Calls Contd..
File Management:
❖File management system calls allow the creation and deletion of
files and directories.
❖These system calls handle the setting and modification of file
access permissions.
❖System calls for file management are also responsible for modifying
file attributes such as ownership and timestamps.
PREPARED BY GSK
Types of System Calls Contd..
Communication:
❖Communication is a system call that is used for communication.
There are some examples of communication, including create the
communication connection, delete communication connections,
send the message through the communication media, receive
messages, etc.
❖Allows processes to communicate via phone-like conversations.
❖Enables processes to exchange messages through electronic mail.
❖Facilitates real-time video communication between processes.
PREPARED BY GSK
Examples of Windows and Unix system calls
Process Windows Unix
CreateProcess() fork()
Process Control ExitProcess() exit()
WaitForSingleObject() wait()
CreateFile() open()
File Manipulation ReadFile() read()
WriteFile() write()
CloseHandle() close()
SetConsoleMode() ioctl() (input output control)
Device Management ReadConsole() read()
WriteConsole() write()
GetCurrentProcessID() getpid()
Information Maintenance SetTimer() alarm()
Sleep() sleep()
CreatePipe() pipe()
Communication CreateFileMapping() shmget()
MapViewOfFile() mmap()
PREPARED BY GSK
Chapter-2
Process
PREPARED BY GSK
What is 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
PREPARED BY GSK
Difference between Program and Process
Program Process
Program contains a set of instructions designed
Process is an instance of an executing program.
to complete a specific task.
Program is a passive entity as it resides in the Process is a active entity as it is created during
secondary memory. execution and loaded into the main memory.
Program exists at a single place and continues Process exists for a limited span of time as it
to exist until it is deleted. gets terminated after the completion of task.
PREPARED BY GSK
Process in Memory
A process resides in memory through following section i.e.
1) Stack, 2) Heap, 3) Data and 4) Text
❖Stack section contains local variable
❖Data section contains global variable
❖Text section contains code or instruction.
❖Heap section contains memory which will be Dynamically allocated
during runtime.
PREPARED BY GSK
Process Life Cycle
PREPARED BY GSK
Start/new/born:
❖ This is the initial state when a process is first started/created.
❖ When the request is made by the user, the process is created
❖ The process resides in secondary memory through a queue named as job queue or
job pool.
PREPARED BY GSK
Process Life Cycle
Cont. .
Ready:
❖ Out of total newly created processes, specified processes are selected and
copied to temporary memory or main memory.
❖ In main memory they resides in a queue named as ready queue.
❖ The process is waiting to be assigned to a processor.
❖ 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.
PREPARED BY GSK
Process Life Cycle
Cont. .
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.
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.
PREPARED BY GSK
Process Life Cycle
Cont. .
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.
Sometimes operating system terminates the process due to the following
reasons.
❖Exceeding the time limit
❖ Input/output failure
PREPARED BY GSK
Process Control Block (PCB)
❖ 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
PREPARED BY GSK
Process Control Block (PCB) Contd..
Process State:
The current state of the process i.e., whether it is ready, running, waiting,
or whatever.
Process privileges:
This is required to allow/disallow access to system resources.
Process ID:
Unique identification for each of the process in the operating system.
PREPARED BY GSK
Process Control Block (PCB)
Cont. .
Pointer:
A pointer to parent process.
Program Counter:
Program Counter is a pointer to the address of the next instruction to be
executed for this process.
CPU registers:
Various CPU registers where process need to be stored for execution for
running state.
PREPARED BY GSK
Process Control Block (PCB)
Cont. .
CPU Scheduling Information:
Process priority and other scheduling information which is required to
schedule the process.
Accounting information:
This includes the amount of CPU used for process execution, time limits,
execution ID etc.
I/O status information:
This includes a list of I/O devices allocated to the process.
PREPARED BY GSK
Process Scheduling
PREPARED BY GSK
Process Scheduling Contd..
❑II. Scheduler
PREPARED BY GSK
Process Scheduling Contd..
PREPARED BY GSK
Process Scheduling Contd..
❖Ready Queue:
❖From the job queue, the processes which are ready for execution
are shifted to the main memory.
❖In the main memory the processes are kept in the ready queue.
❖In other words, the ready queue contains all those processes that
are waiting for the CPU
PREPARED BY GSK
Process Scheduling Contd..
❖3.Device Queue:
❖Device queue is a queue for which a list of processes waiting
for a particular I/O device.
❖Each device has its own device queue.
❖When a process required some I/O operation, it is then taken
out of the ready queue and kept under the device queue.
❖4.Suspended Queue: It stores the list of suspended process.
PREPARED BY GSK
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.
PREPARED BY GSK
Schedulers
PREPARED BY GSK
Long Term Scheduler
❖it is also called job scheduler; it works with the job queue.
❖ Job scheduler selects processes from the job queue and loads
them into the main memory for execution.
❖It executes much less frequently, as there may be long time gap
between the creation of new process in the system.
❖The primary objective of the job scheduler is to control the degree
of multiprogramming.
PREPARED BY GSK
Short Term Scheduler
PREPARED BY GSK
Medium Term Scheduler
❖It is also known as Swapper.
❖Sometimes the processes are removed from the memory and from CPU
to reduce the degree of multiprogramming.
❖Then after sometime the processes can be reintroduced into memory
and execution can be continued where it is left off. This scheme is known
as swapping.
❖The Medium Term Scheduler selects a process among the partially
executed or unexecuted swapped out processes and swaps it in the main
memory
PREPARED BY GSK
PREPARED BY GSK
Context Switch
PREPARED BY GSK
Cooperating Process in Operating System
Processes are classified into 2 categories.
Independent Process:
❖It is defined as a process that does not share any data and does not
communicate with other process.
❖In other words we can say that modification made to an
independent process does not affect the functioning of other
processes
PREPARED BY GSK
Cooperating Process in Operating System
Cooperating Process:
❖It is defined as a process, which gets affected by any other process.
❖These processes are used for resource sharing and to speed up a
computation procedure.
PREPARED BY GSK
Advantages of process cooperation
Information sharing: Since several users may be interested in the same piece
of information (for instance, a shared file), we must provide an environment
to allow concurrent access to these types of resources.
Computation speedup: If we want a particular task to run faster, we must
break it into subtasks, each of which will be executing in parallel with the
others. Such a speedup can be achieved only if the computer has multiple
processing elements (such as CPUS or I/O channels).
Modularity: We may want to construct the system in a modular fashion,
dividing the system functions into separate processes or threads.
PREPARED BY GSK
Methods of Cooperating Process in OS
PREPARED BY GSK
Cooperation by Sharing
PREPARED BY GSK
Cooperation by Message Passing
PREPARED BY GSK
What is Thread?
PREPARED BY GSK
Difference between Process and Thread
S.N. Process Thread
Thread is light weight, taking lesser resources
1 Process is heavy weight or resource intensive.
than a process.
Process switching needs interaction with operating Thread switching does not need to interact with
2
system. operating system.
In multiple processing environments, each process
All threads can share same set of open files,
3 executes the same code but has its own memory
child processes.
and file resources.
If one process is blocked, then no other process can While one thread is blocked and waiting, a
4
execute until the first process is unblocked. second thread in the same task can run.
Multiple processes without using threads use more Multiple threaded processes use fewer
5
resources. resources.
In multiple processes each process operates One thread can read, write or change another
6
independently of the others. thread's data.
PREPARED BY GSK
Types of Thread in Operating System
PREPARED BY GSK
Types of Thread in Operating System
PREPARED BY GSK
What is Multi-Threading?
PREPARED BY GSK
What is Multi-Threading? Contd..
PREPARED BY GSK
Unit-1: Important Questions
1. Describe the system components of an operating system and explain them briefly.
2. Discuss the Functionalities of Operating Systems in detail.
3. What is a System call? Discuss major System calls of Operating Systems.
4. Describe the differences among short-term, medium-term, and long-term scheduling
5. Explain about time-sharing operating systems.
6. Define real time system. Explain about real time operating system
7. Discuss about Process Control Block with a neat diagram
8. Distinguish between client-server and peer-to-peer models of distributed systems.
9. Differentiate between Multi Programming, Multi Tasking and Multi processing systems
10.List out the types of operating system and explain batch OS and time sharing OS in brief.
11.Explain about the system calls fork, exit, wait, waitpid and exec
PREPARED BY GSK