Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Ii BSC - Operating System Material

Download as pdf or txt
Download as pdf or txt
You are on page 1of 87

II BSC OPERATING SYSTEMS

UNIT I: What is Operating System? History and Evolution of OS, Basic OS functions,
Resource Abstraction, Types of Operating Systems– Multiprogramming Systems,
Batch Systems, Time Sharing Systems; Operating Systems for Personal Computers,
Workstations and Hand-held Devices, Process Control & Real time Systems.

UNIT II: Processor and User Modes, Kernels, System Calls and System Programs,
System View of the Process and Resources, Process Abstraction, Process Hierarchy,
Threads, Threading Issues, Thread Libraries; Process Scheduling, Non-Preemptive and
Preemptive Scheduling Algorithms.

UNIT III: Process Management: Deadlock, Deadlock Characterization, Necessary


andSufficient Conditions for Deadlock, Deadlock Handling Approaches: Deadlock
Prevention, Deadlock Avoidance and Deadlock Detection and Recovery. Concurrent
and Dependent Processes, Critical Section, Semaphores, Methods for Inter- process
Communication; Process Synchronization, Classical Process Synchronization
Problems: Producer-Consumer, Reader-Writer.

UNIT IV: Memory Management: Physical and Virtual Address Space;


MemoryAllocation Strategies– Fixed and -Variable Partitions, Paging, Segmentation,
Virtual Memory.

UNIT V: File and I/O Management, OSsecurity : Directory Structure, File Operations,
File Allocation Methods, Device Management, Pipes, Buffer, Shared Memory,
Security Policy Mechanism, Protection, Authentication and Internal Access
Authorization Introduction to Android Operating System, Android Development
Framework, AndroidApplication Architecture, Android Process Management and File
System, SmallApplication Development using Android Development Framework.

1 P.Sharmila,Lecturer in computer science


UNIT-1

1. What is Operating System?

An Operating System (OS) is an interface between a user and computer hardware.


An operating system is a system 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.

Generally, a Computer System consists of the following components:

 Computer Users are the users who use the overall computer system.
 Application Softwares are the softwares which users use directly to
perform different activities. These softwares are simple and easy to use like
Browsers, Word, Excel, different Editors, Games etc.
 System Softwares are the softwares which are more complex in nature and
they are more near to computer hardware.Operating Systems (Microsoft
Windows, macOS, and Linux).
 Computer Hardware includes Monitor, Keyboard, CPU, Disks, Memory,
etc.

Objectives of Operating System


1.To make the computer system convenient to use in an efficient manner.
2.To hide the details of the hardware resources from the users.
3.To provide users a convenient interface to use the computer system.

2 P.Sharmila,Lecturer in computer science


4.To act as an intermediary between the hardware and its users, making it
easier for the users to access and use other resources.
5.To manage the resources of a computer system.
6.To provide efficient and fair sharing of resources among users and
programs.

2. Write about History and Evolution of operating system?

The History of the Operating System is divided into four generations. let us
explore all of them in detail, one by one, in the following sections:

First-generation of Operating System: UNIX Operating System

The UNIX Operating System was the first generation of modern computer
operating systems. It was designed in 1969 by Ken Thompson and Dennis Ritchie
at Bell Labs, a research division of AT&T Corporation. UNIX was originally
written in assembly language.

Limitations of First-generation Operating System:

The first-generation operating systems were severely limited in their capabilities.


They could only run on a single type of computer, and they couldn’t multitask-
meaning that users could only run one program at a time.

The second generation of Operating System: OS/360

The OS/360 operating system was developed in the early 1960s for IBM
mainframes. It was a comprehensive, multi-user, multitasking system that
supported virtual memory and provided an interface to a wide variety of
peripherals.

Third generation of Operating System: MS-DOS

Microsoft came up with their MS-DOS operating system in 1981. This was a
single-user, single-tasking operating system that ran on IBM personal computers.

The fourth generation of Operating System: Windows

Microsoft released their first version of Windows, Windows NT, in 1993. This
was a multi-user, multitasking operating system that replaced MS-DOS on IBM
personal computers. Windows NT was based on the UNIX operating system and
provided a graphical user interface (GUI) and support for networking.

3 P.Sharmila,Lecturer in computer science


In today’s world, we use Microsoft Windows as our standard operating system.

Advantages of Operating System:

-Allows multiple users to access the computer simultaneously

-Organizes and manages files

-Provides a platform for software applications

-Enables communication between computers and peripheral devices.

Disadvantages of Operating System:

-Can be expensive

-Can require significant hardware resources

-Vulnerable to malicious software attacks.

3. Explain the Functions of operating System?

An Operating System (OS) is an interface between a user and computer hardware.

Functions of Operating System

4 P.Sharmila,Lecturer in computer science


1. File Management
An operating system’s (OS) primary function is to manage files and folders.
Operating systems are responsible for managing the files on a computer. This
includes creating, opening, closing, and deleting files. The operating system is also
responsible for organizing the files on the disk.
2. Device management
Operating systems provide essential functions for managing devices connected to a
computer. These functions include allocating memory, processing input and output
requests, and managing storage devices. This device could be a keyboard, mouse,
printer, or any other devices you may have connected.
3. Process management
The operating system’s responsibility is to manage the processes running on your
computer. This includes starting and stopping programs, allocating resources, and
managing memory usage.
How do Operating systems manage all processes?
Each process is given a certain amount of time to execute, called a quantum. Once
a process has used its quantum, the operating system interrupts it and provides
another process with a turn. This ensures that each process gets a fair share of the
CPU time.
4. Memory management
One of the most critical functions of an operating system is memory
management.
 Allocating memory to store programs.
 Deciding the amount of memory that should be allocated to the program.
 Memory distribution while multiprocessing.

5.Job Accounting
An operating system’s (OS) job accounting feature is a powerful tool for tracking
how your computer’s resources are being used. This information can help you
pinpoint and troubleshoot any performance issues and identify unauthorized
software installations.

6.Security – For security, modern operating systems employ a firewall. A firewall


is a type of security system that monitors all computer activity and blocks it if it
detects a threat.

5 P.Sharmila,Lecturer in computer science


4. Explain Types of operating systems?

There are various types of operating system:

1. Simple Batch Operating System


2. Multiprogramming batch Operating System
3. Time-sharing Operating System
4. Multiprocessor Operating System
5. Distributed Operating System
6. Network Operating System
7. Real-time Operating System
8. Mobile Operating System

1.Batch operating system


This type of operating system does not interact with the computer directly.
There is an operator which takes similar jobs having the same
requirement and group them into batches. It is the responsibility of the
operator to sort jobs with similar needs.

6 P.Sharmila,Lecturer in computer science


Advantages of Batch Operating System:
 It is very difficult to guess or know the time required for any job to complete.
 Multiple users can share the batch systems
 The idle time for the batch system is very less
 It is easy to manage large work repeatedly in batch systems
Disadvantages of Batch Operating System:
 The computer operators should be well known with batch systems
 Batch systems are hard to debug
 It is sometimes costly
 The other jobs will have to wait for an unknown time if any job fails

Examples of Batch based Operating System: Payroll System, Bank Statements, etc.

2.Time-SharingOperatingSystems
Each task is given some time to execute so that all the tasks work smoothly. Each
user gets the time of CPU as they use a single system. These systems are also
known as Multitasking Systems. The task can be from a single user or different
users also. The time that each task gets to execute is called quantum. After this
time interval is over OS switches over to the next task.

7 P.Sharmila,Lecturer in computer science


Advantages of Time-Sharing OS:
 Each task gets an equal opportunity
 CPU idle time can be reduced
 Resource Sharing
Disadvantages of Time-Sharing OS:
 Data communication problem
 Security Risks: With multiple users sharing resources, the risk of security
breaches increases.

Examples of Time-Sharing OSs are: Multics, Unix, etc.

3.Distributed operating system

A distributed operating system is an operating system that is designed to


operate on a network of computers. Distributed systems are usually used to
distribute software applications and data. Distributed systems are also used to
manage the resources of multiple computers. Multiple computers are connected via
a single communication channel.Every system have its own processor and
memory. Resources like disk,computer,CPU,network interface, nodes, etc are
shared among different computer at different locations.It increases data availability
in the entire system.

Advantages

 It is more reliable as a failure of one system will not impact the other
computers or the overall system.
 All computers work independently.
 Resources are shared so there is less cost overall.
 The system works at a higher speed as resources are shared

8 P.Sharmila,Lecturer in computer science


Disadvantages

 Costly setup.
 If the server is failed, then the whole system will fail.
 Complex software is used for such a system

Examples of Distributed Operating System are- LOCUS, etc.

4.Network Operating system

A Network Operating system (NOS) is a type of operating system that enables


multiple users to connect to a single computer or server. The main server is
typically connected to a number of client servers, which allows for secure and
efficient sharing of files, applications and other resources. A NOS is a critical
component of any networked environment and is responsible for managing traffic,
security and communication between users and servers.

Types of Network Operating Systems

Network operating systems are of two types:

 Peer-to-peer Network Operating System


 Client Server Network Operating System

Advantages
 Centralized servers are highly stable.
 Security is server managed.

Disadvantages
 High cost of buying and running a server.
 Dependency on a central location for most operations.

9 P.Sharmila,Lecturer in computer science


Examples of Network Operating System are: Microsoft Windows Server
2003, Microsoft Windows Server 2008, UNIX, Linux, Mac OS X etc.

5.Real time OS
A real time operating system time interval to process and respond to inputs is very
small.

Examples: Military Software Systems, Space Software Systems are the Real time
OS example.

The quick response of the process is a must in real-time operating systems. There
is no chance of any delay in completing any process because a little delay can
cause several dangerous issues.

Advantages of Real-time operating system:

o In a Real-time operating system, the maximum utilization of devices and


systems.
o Easy to layout, develop and execute real-time applications under the real-
time operating system.

Disadvantages of Real-time operating system:

o Real-time operating systems have complicated layout principles and are very
costly to develop.
o Real-time operating systems are very complex and can consume critical
CPU cycles.

6. Multiprocessor OS
This operating system is commonly found on computer systems with more than
one CPU. Multiprocessor systems improve system performance by allowing the
execution of tasks on multiple processors simultaneously.

10 P.Sharmila,Lecturer in computer science


Advantages

 It allows the system to run multiple programs simultaneously.


 Beneficial for tasks that need to use all of the processor’s resources, such as
games, scientific calculations, and financial simulations.

Disadvantages

 They require additional hardware, such as processors and memory, making a


system more expensive.

7.Multi-programming OS
 The operating system which can run multiple processes on a single processor
is called a multiprogramming operating system.

Advantages

1.It may help to run various jobs in a single application simultaneously.

2.The resources are utilized smartly.

11 P.Sharmila,Lecturer in computer science


Disadvantages

1.It is highly complicated.

2.If it has a large number of jobs, then long-term jobs will require a long wait.

Examples

Apps like office, chrome, etc.

8.Mobile Operating System

A mobile operating system is an operating system that helps run application


software on mobile devices.

The operating systems found on smartphones include Symbian OS, IOS,


BlackBerryOS, Windows Mobile, Palm WebOS, Android, and Maemo.

Advantages

 Convenience inoperability.
 It also includes open-source platforms.
 Gives notification ease.

Disadvantages

 Instability.
 It also includes poor battery quality.
 Not sufficient computational power.

Examples

 Android
 IOS
 HarmonyOS
 PalmOS

12 P.Sharmila,Lecturer in computer science


5.Explain Resource abstraction?

 An abstraction is software that hides lower level details and provides a set
of higher- level functions
 Resource include the Central processing unit(CPU), memory, file storage,
I/O devices and network connections.
 The fundamental operation of the operating system is to abstract the
hardware to the programmer and user. The OS provides generic interfaces
to services provided by the underlying hardware
 Resource abstraction is the process of “hiding the details of how the
hardware operates, thereby making computer hardware relatively easy for
an application programmer to use.
 Such an abstraction saves the programmer from needing to learn the
details of bother hardware interfaces.

6. Explain Operating system for personal computers?

 Most of the OS relating to personal computers and other gadgets started


in 4th Generation (1980s)
 The cost of personal computers was very high at that time, there were
small fractions of mini computers costs.
 A major factor related to creating personal computers was the birth of
Microsoft and the windows Operating System
 Microsoft created the first window OS in 1975.
 Personal computers OS provides a good interface to a single user.
 We can say that our laptops, computer systems, tablets etc., are your
personal computers and the OS such as windows 7, Windows 10, android
etc., are personal computer Operating System.
 We can use our personal computer OS for our personal purposes, for
Example, to chatting with your friends using some social media sites,
accessing internet, making some projects or any other; designing web
sites, programming something, watching videos and movies and many
more.

13 P.Sharmila,Lecturer in computer science


7.Write about Workstations and Hand-held Devices?

1.Workstations are computers that are specifically configured to meet the most
demanding technical computing requirements.

2.To be considered a workstation, systems must include key capabilities related to


performance, reliability, data integrity, scalability, and expandability.

3.Workstations are most frequently used in creative, engineering, scientific, and


financial services industries.

Features of a Workstation
1.Specialized Performance
2.Reliability

3.Data integrity

4.scalability

5.expandability.

Hand-held Devices:

A handheld device is a pocket-sized computing device with a display screen and


input/output interface like an external or touch screen keyboard.

A mobile device is a general term for any type of handheld


computer. These devices are designed to be extremely portable, and they can often
fit in your hand.

Example: smartphones

Smartphones

A smartphone is a more powerful version of a traditional cell phone. In addition to


the same basic features—phone calls, voicemail, text messaging—smartphones
can connect to the Internet over Wi-Fi or a cellular network (which requires
purchasing a monthly data plan). This means you can use a smartphone for the

14 P.Sharmila,Lecturer in computer science


same things you would normally do on a computer, such as checking your email,
browsing the Web, or shopping online.

Features of Handheld Operating System:


1. Its work is to provide real-time operations.
2. There is direct usage of interrupts.
3. Input/Output device flexibility.
4. Configurability.

Types of Handheld Operating Systems:


1. Palm OS
2. Symbian OS
3. Linux OS
4. Windows
5. Android

Advantages of Handheld Operating System:


Some advantages of a Handheld Operating System are as follows:
1. Less Cost.
2. Less weight and size.
3. Less heat generation.
4. More reliability.
Disadvantages of Handheld Operating System:
Some disadvantages of Handheld Operating Systems are as follows:
1. Less Speed.
2. Small Size.
3. Input / Output System (memory issue or less memory is available).

8.Explain Process Control and Real time Systems?

Process Control : Process control is the ability to monitor and adjust a process
to give a desired output. It is used in industry to maintain quality and improve
performance.

An example of a simple process that is controlled is keeping the temperature of a


room at a certain temperature using a heater and a thermostat. When the
temperature of the room is too low, the thermostat will turn on a heating source
until the temperature reaches the desired level at which point the heater is turned
off. As the room cools, this process repeats itself to keep the room at the desired

15 P.Sharmila,Lecturer in computer science


set point.

In this example, the set point is the temperature setting on the thermostat and the
heater turns on and off to maintain temperature. Hence, this simplest form of
process control is called on/off or deadband control.

Real time system

 In real time system, large number of events, mostly external to the


computer system, must be accepted and processed in a short time or within
certain deadlines.
 Such applications are industrial control, telephone switching equipment,
flight control.
 Realtime OS are 3 types
o Hard realtime OS : These OS guarantee that critical tasks be
completed within a range of time.
o Soft realtime OS : This OS provides some relaxation in the time
limit.
o Firm Realtime OS : RTOS of this type have to follow deadlines as
well. Inspite of its small impact, missing a deadline can have
unintended consequences.
UNIT-2
1. Write about User Modes and Kernel Modes?
 A processor in a computer running Windows has two different
modes: user mode and kernel mode.
 The processor switches between the two modes depending on what type
of code is running on the processor. Applications run in user mode, and
core operating system components run in kernel mode.

USER Mode
If CPU is executing the user applications then CPU will be in the user mode. The
User applications are games, media players, text editor, MS Office etc.

Executing code in user mode has no ability to directly access some resources like
Hard Disk, memory, Printer and other I/O devices. Because, To access these
resources we have to use kernel mode through System Call.

Note: User mode is also known as safe mode and Restricted mode.

16 P.Sharmila,Lecturer in computer science


Kernel Mode
Kernel mode contains OS which has full functionality to access and maintain all
the hardware components. Hardware components are RAM, HARD, CPU, printer
and other I/O devices.

Whenever the system call generate, CPU switch to kernel mode from user mode.
System call is executed in kernel mode. After execution of system call it returns
back to user mode.

Note: kernel mode also known as system, private or supervisory mode, protected
mode because user can’t access this area directly

User Mode vs Kernel Mode with examples

17 P.Sharmila,Lecturer in computer science


Watching Movie in windows OS

If we want To play movie then we have to double click on that particular video.
As, that video exist in main memory and main memory is hardware.So, CPU
cannot access the hardware in user mode. System have to request through system
call to open the file in main memory. So, OPEN () system call is generated and
CPU switch to Kernel mode. Now OS in kernel, open that particular file from main
memory. After opening the file CPU switch back to user mode. Now we are
watching the movie in user mode. When user want to close the file then CLOSE
system call again generated.

Real Life example


If we go for back to withdraw money. Then the staff of bank is kernel and our
command in user mode is withdraw the money. This request is executed by bank
staff to withdraw the money. So, without kernel, user can’t proceed.
System Call
System calls are the calls (functions) that are required to invoke the services
provided by the operating system. These calls provide an interface between
the user program and the operating system. We call this interface as
Application Program Interface.

Explanation of System Call


As in above diagram, User Applications run in user mode, and operating system
run in kernel mode. As OS control all the hardware’s so User cannot access
hardware without kernel mode. To access kernel mode user application generate a
system call because System call is a source to go to kernel mode.
CPU switch in two modes, while working
 User mode
 Kernel mode

18 P.Sharmila,Lecturer in computer science


Services Provided by System Calls:

1. Process creation and management


2. Main memory management
3. File Access, Directory and File system management
4. Device handling(I/O)
5. Protection
6. Networking, etc

Types of System Call

Process control
The process control system call is used to create and manage the processes in the
operating system.

File management
The file management system call controls the file and directory system of the
computer.

Device management
The device management system call is required to control and manage the devices
attached to the computer system.

Information maintenance
The information maintenance system call maintains the information of the
computer such as system time, date, etc.

Communications
A communication call is required to connect your computer over the network.

System Programs

1. Creates an environment for program to develop and execute.


2. Defines a user interface of operating system.
3. It satisfies the high-level request of the user program.
4. Initiates a sequence of system calls for to satisfy a user request.
5. System program are written in high-level languages only.

Types of the System Program

There are mainly six types of system programs. These are classified as follows:

19 P.Sharmila,Lecturer in computer science


1. File Management
2. Status Information
3. File Modification
4. Programming-Language support
5. Program Loading and Execution
6. Communication

2.Explain System view of the Process and Resources?

User View – The user viewpoint focuses on how the user interacts with the
operating system through the usage of various application programs. In contrast,
the system viewpoint focuses on how the hardware interacts with the operating
system to complete various tasks.
System View

The goal of the operating system in this viewpoint is to maximize the performance.
In this viewpoint, the operating system is more involved with hardware services –
CPU time, memory space, I/O operation, and so on. The operating system is
involved in managing the hardware resources and allocation them to programs and
users for maximum performance.

20 P.Sharmila,Lecturer in computer science


3.What is Process abstraction?

 Abstraction means hiding the working complexity of the system. The operating
system provides a layer of abstraction with the help of OSAL.
 OSAL stands for Operating System Abstraction Layer, a set of APIs that a
developer can use to quickly develop an application without considering the
type of operating system, hardware, and background complexity of the
operating system.
 The main purpose of abstraction provided by the operating system is to hide the
working complexity or technical details of the system. With the help of
abstraction, the Operating System provides a separation between hardware and
software.
 Operating system provides hardware abstraction which allows the system users
or developers to develop system-independent applications.
 Using a hardware abstraction layer the user processes or system processes can
simply use the hardware devices with the help of specific system calls.

4.Explain process Hierarchy? Write about the process and the process state
and Process Control Block(PCB)

When a process creates another process, then the parent and the child processes
tend to associate with each other in certain ways and further. The child process can

21 P.Sharmila,Lecturer in computer science


also create other processes if required. This parent-child like structure of processes
form a hierarchy, called Process Hierarchy.

Process:

An active program which running now on the Operating System is known as the
process.

For example, when you want to search something on web then you start a
browser. So, this can be process.

 Stack – A process stores temporary data onto the stack.


 Heap- Heap is a memory allocated to the process during execution.
 Data – The data section stores the global variable.
 Text – The text section includes the program code that has to be executed.

22 P.Sharmila,Lecturer in computer science


Process State :

Processes may be in one of 5 states

o New - The process is in the stage of being created.


o Ready - The process has all the resources available that it needs to run
o Running - The CPU is working on this process's instructions.
o Waiting - The process cannot run at the moment, because it is waiting for
some resource to become available or for some event to occur. For
example the process may be waiting for keyboard input, disk access
request, inter-process messages, a timer to go off, or a child process to
finish.
o Terminated - The process has completed.

Process Control Block (PCB)

Process Control block (PCB) is a data structure that stores information of a


process.

Structure of Process Control Block

The process control block contains many attributes such as process ID, process
state, process priority, accounting information, program counter, CPU registers`,
etc for each process.

23 P.Sharmila,Lecturer in computer science


1. Process ID:

When a new process is created by the user, the operating system assigns a unique
ID

So, process-ID will get the values from 0 to N-1.

 First process will be given ID0.


 Second process will be given ID 1.
 It continues till N-1.

2. Process State:

A process, from its creation to completion goes through different states. Generally,
a process may be present in one of the 5 states during its execution:

24 P.Sharmila,Lecturer in computer science


3.Process Priority:

Process priority is a numeric value that represents the priority of each process.

4. Process Accounting Information:

This attribute gives the information of the resources used by that process in its
lifetime. For Example: CPU time connection time, etc.

5. Program Counter:

The program counter is a pointer that points to the next instruction in the program
to be executed.

6.CPU registers:

A CPU register is a quickly accessible small-sized location available to the CPU.


These registers are stored in virtual memory(RAM).

7. Context Switching:

A context switching is a process that involves switching the CPU from one process
or task to another.

8. PCB pointer:

This field contains the address of the next PCB, which is in ready state. This helps
the operating system to hierarchically maintain an easy control flow between
parent processes and child processes.

9. List of open files:

As the name suggests, It contains information on all the files that are used by that
process.

10. Process I/O information:

In this field, the list of all the input/output devices which are required by that
process during its execution is mentioned.

25 P.Sharmila,Lecturer in computer science


5.What is Thread? Types of Threads?

Threads:

Thread is the smallest executable unit of a process. For example, when you run a
notepad program, operating system creates a process and starts the execution of
main thread of that process.

A process can have multiple threads. Each thread will have their own task and own
path of execution in a process. For example, in a notepad program, one thread will
be taking user inputs and another thread will be printing a document .

Types of Threads
1. Kernel level thread.
2. User-level thread.

User-level thread

User threads can be easily implemented and it is implemented by the user.


If a user performs a user-level thread blocking operation, the whole process
is blocked. The kernel level thread does not know nothing about the user
level thread.

26 P.Sharmila,Lecturer in computer science


Kernel level thread

The kernel-level thread is implemented by the operating system. The kernel knows
about all the threads and manages them. The kernel-level thread offers a system
call to create and manage the threads from user-space.

Components of Thread

A thread has the following three components:

1. Program Counter
2. Register Set
3. Stack space

27 P.Sharmila,Lecturer in computer science


Types of Threaded process

6.Write about Thread Issues?

Threading Issues
Following threading issues are:

 The fork() and exec() system call


 Signal handling
 Thread cancelation
 Thread Pool
1. fork( ) and exec( ) system calls: The fork() call is used to create a duplicate child
process. During a fork( ) call the issue that arises is whether the whole process should
be duplicated or just the thread which made the fork( ) call should be duplicated. The
exec ( ) call replaces the whole process that called it including all the threads in the
process with a new program.

2.Thread cancellation: The termination of a thread before its completion is called


thread cancellation and the terminated thread is termed as target thread. Thread
cancellation is of two types:

1. Asynchronous Cancellation: In asynchronous cancellation, one


thread immediately terminates the target thread.
2. Deferred Cancellation: In deferred cancellation, the target thread
periodically checks if it should be terminated.

28 P.Sharmila,Lecturer in computer science


3.Signal handling: In UNIX systems, a signal is used to notify a process that a
particular event has happened.

Asynchronous Signal: The signal which is generated outside the process which
receives it.

Synchronous Signal: The signal which is generated and delivered in the same
process.

4.Thread pool

The time require to create a new thread is more than the time required by the
thread to service the request and then getting discarded as it would result in
wastage of CPU time.

The solution to this issue is the thread pool.

Whenever the request arrives at the server, it invokes a thread from the pool and
assigns it the request to be serviced. The thread completes its service and return
back to the pool and wait for the next request.

7. Explain Thread Libraries?


Thread Library
A thread library provides the programmer with an Application program interface for creating and
managing thread.
There are two primary ways of implementing a thread library. The first approach is to
provide a library entirely in user space.
The second approach is to implement a kernel-level library supported directly by
the operating system.

29 P.Sharmila,Lecturer in computer science


The main thread libraries which are used are given below −
 POSIX threads − Pthreads, the threads extension of the POSIX standard,
may be provided as either a user level or a kernel level library.
 WIN 32 thread − The windows thread library is a kernel level library
available on windows systems.
 JAVA thread − The JAVA thread API allows threads to be created and
managed directly as JAVA programs.

8.Explain process scheduling?Types of CPU Scheduling Algorithms?

Process scheduling is an important part of multiprogramming operating systems. It


is the process of removing the running task from the processor and selecting
another task for processing.

Process Scheduling Queues

1. Job Queue – Whenever any process enters the system its there in job Queue
2. Ready Queue – Processes in the ready queue waiting for run time are in the
ready queue.
3. Device Queue – Some processes may be waiting some I/O operation, such
processes are in the device queue.

Different Types of Schedulers

1. Long-term Scheduler
2. Short-term Scheduler

30 P.Sharmila,Lecturer in computer science


3. Medium-term Scheduler

Types of Process Scheduling Algorithms

We divided Process Scheduling into following two

 Preemptive Scheduling –The scheduling in which a running process can be


interrupted if a high priority process enters the queue and is allocated to the
CPU is called preemptive scheduling. In this case, the current process
switches from the running queue to ready queue and the high priority
process utilizes the CPU cycle.

Examples: –Round Robin,preemptive priority, Shortest Remaining Time


First(SRTF), etc.

1.Round Robin(RR) scheduling algorithm


 Round Robin is the preemptive process scheduling algorithm.

 Each process is provided a fix time to execute, it is called a quantum.

 Once a process is executed for a given time period, it is preempted and other

process executes for a given time period.

 Context switching is used to save states of preempted processes.

31 P.Sharmila,Lecturer in computer science


32 P.Sharmila,Lecturer in computer science
2. preemptive priority scheduling

1.It is a method of scheduling processes that is based on priority

2.selects the tasks to work as per the priority.

3.Lowest integer value is highest priority.

4.Highest integer value is low priority.

EXAMPLE:

PID( PROCESS ID),BT(BURST TIME),AT(ARRIVAL TIME),CT(PROCESS COMPLETION


TIME),TAT(TURN AROUND TIME),WT(WAITING TIME),RT(RESPONSE TIME)

PID PRIORITY AT BT CT TAT=CT-AT WT=TAT-BT RT=QUEUEFIRSTVALUE-AT

P0 3 0 6-1=5-1=4-1=3 7 7-0=7 7-6=1 0-0=0

P1 6 1 2 13 13-1=12 12-2=10 11-1=10

P2 4 2 4 11 11-2=9 9-4=5 7-2=5

P3 2 3 1 4 4-3=1 1-1=0 3-3=0

Gantt Chart
P0 P0 P0 P3 P0 P2 P1
0 1 2 3 4 7 11 13
Average TurnAroundTime=sum of TAT/4
=7+12+9+1/4
=28.25
Average Waiting Time=sum of wt/4
=1+10+5+0/4
=16

33 P.Sharmila,Lecturer in computer science


3.Shortest Remaining Time First (SRTF) Scheduling Algorithm

The SRTF scheduling algorithm is the preemptive version of the SJF scheduling
algorithm in OS. This calls for the job with the shortest burst time remaining to be
executed first, and it keeps preempting jobs on the basis of burst time remaining in
ascending order.

34 P.Sharmila,Lecturer in computer science


 Non Preemptive Scheduling – The scheduling in which a running process
cannot be interrupted by any other process is called non-preemptive
scheduling. Any other process which enters the queue has to wait until the
current process finishes its CPU cycle

Examples: First Come First Serve, Shortest Job First, Priority Scheduling, etc.

1. First Come First Serve (FCFS)


 Jobs are executed on first come, first serve basis.
 It is a non-preemptive, pre-emptive scheduling algorithm.
 Easy to understand and implement.
 Its implementation is based on FIFO queue.
 Poor in performance as average wait time is high.

Wait time of each process is as follows −

Process Wait Time : Service Time - Arrival Time

P0 0-0=0

P1 5-1=4

P2 8-2=6

P3 16 - 3 = 13

Average Wait Time: (0+4+6+13) / 4 = 5.75

35 P.Sharmila,Lecturer in computer science


2.Shortest Job Next (SJN)
 This is also known as shortest job first, or SJF
 This is a non-preemptive, pre-emptive scheduling algorithm.
 Best approach to minimize waiting time.
 Easy to implement in Batch systems where required CPU time is known in advance.
 Impossible to implement in interactive systems where required CPU time is not known.
 The processer should know in advance how much time process will take.
Given: Table of processes, and their Arrival time, Execution time

Process Arrival Time Execution Time Service Time

P0 0 5 0

P1 1 3 5

P2 2 8 14

P3 3 6 8

Waiting time of each process is as follows −

Process Waiting Time

P0 0-0=0

P1 5-1=4

36 P.Sharmila,Lecturer in computer science


P2 14 - 2 = 12

P3 8-3=5

Average Wait Time: (0 + 4 + 12 + 5)/4 = 21 / 4 = 5.25

3.Non- Preemptive priority Scheduling

A non-preemptive algorithm in which processes are executed according to the


priority assigned. The priority is decided o the basis of time and memory
requirements. If two processes have the same priority, then check the arrival time.
The process with a lower arrival time will be picked for execution in that case.

Example

37 P.Sharmila,Lecturer in computer science


UNIT-3

PROCESS MANAGEMENT

1. What is Deadlock? Explain Deadlock Characterization?

A process in operating system uses resources in the following way.


1. Requests a resource
2. Use the resource
3. Releases the resource

A deadlock is a situation where a set of processes are blocked because each


process is holding a resource and waiting for another resource acquired by some
other process.

For example, in the below diagram, Process 1 is holding Resource 1 and


waiting for resource 2 which is acquired by process 2, and process 2 is
waiting for resource 1.

Necessary conditions for Deadlocks(Deadlock Characterization)


1. Mutual Exclusion

A resource can only be shared in mutually exclusive manner. It implies, if two


process cannot use the same resource at the same time. In the diagram below, there
is a single instance of Resource 1 and it is held by Process 1 only.

38 P.Sharmila,Lecturer in computer science


2. Hold and Wait
A process waits for some resources while holding another resource at the
same time.

In the diagram given below, Process 2 holds Resource 2 and Resource 3 and
is requesting the Resource 1 which is held by Process 1.

3.No preemption: The resource can be released by a process voluntarily i.e. after
execution of the process.

4.Circular Wait
All the processes must be waiting for the resources in a cyclic manner so
that the last process is waiting for the resource which is being held by the
first process.

39 P.Sharmila,Lecturer in computer science


2.Explain methods/Approaches for Handling Deadlocks?
A deadlock is a situation where a set of processes are blocked because each
process is holding a resource and waiting for another resource acquired by some
other process.

For example, in the below diagram, Process 1 is holding Resource 1 and


waiting for resource 2 which is acquired by process 2, and process 2 is
waiting for resource 1.

Methods for handling deadlock:


1. Deadlock Prevention

40 P.Sharmila,Lecturer in computer science


2. Deadlock Avoidance
3. Deadlock Detection and Recovery
4. Deadlock Ignorance

1.Deadlock Prevention

let us take an example of a chair, as we know that chair always stands on its four
legs. Likewise, for the deadlock problem, all the above given four conditions are
needed. If anyone leg of the chair gets broken, then definitely it will fall. The same
is the situation with the deadlock if we become able to violate any condition
among the four and do not let them occur together then there can be prevented
from the deadlock problem.

1.Mutual Exclusion
A resource can only be shared in mutually exclusive manner.
2.Hold and Wait
A process waits for some resources while holding another resource at the same time.
3.No preemption:
The resource can be released by a process voluntarily i.e. after execution of the
process.
4.Circular Wait
All the processes must be waiting for the resources in a cyclic manner

2. Deadlock Avoidance
When a process requests a resource, the deadlock avoidance algorithm
examines the resource-allocation state. If allocating that resource sends
the system into an unsafe state, the request is got granted.

Therefore, it requires additional information such as how many resources


of each type is required by a process. If the system enters into an unsafe
state, it has to take a step back to avoid deadlock.

3.Deadlock Detection and Recovery


We let the system fall into a deadlock and if it happens, we detect it using
a detection algorithm and try to recover.

41 P.Sharmila,Lecturer in computer science


Some ways of recovery are as follows.

Aborting all the deadlocked processes.

Abort one process at a time until the system recovers from the deadlock.

Resource Preemption: Resources are taken one by one from a


process and assigned to higher priority processes until the deadlock
is resolved.

4. Deadlock Ignorance

In the method, the system assumes that deadlock never occurs. Since the
problem of deadlock situation is not frequent, some systems simply ignore
it. Operating systems such as UNIX and Windows follow this approach.
However, if a deadlock occurs we can reboot our system and the
deadlock is resolved automatically.

3. Explain Concurrent and dependent Pocesses ?

 Concurrent Processes are those processes that are executed


simultaneously or parallel and might or might not be dependent
on other processes.
 Process Synchronization can be defined as the coordination
between two processes that have access to common materials
such as a common section of code, resources ordata etc.
 For example: There may be some resource that is shared by 3
different processes, and none of the processes at a certain time
can change the resource, since that might ruin the results of the
other processes sharing the same resource.
 Now this Process Synchronization is required for concurrent
processes. For any number of processes that are executing
simultaneously, let's say all of them need to access a section of
the code. This section is called the Critical Section.

42 P.Sharmila,Lecturer in computer science


Advantages of concurrency
1. Improved performance − Concurrency allows multiple tasks to be
executed simultaneously, improving the overall performance of the system.
2. Resource utilization − Concurrency allows better utilization of system
resources, such as CPU, memory, and I/O devices.
3. Responsiveness − Concurrency can improve system responsiveness by
allowing multiple tasks to be executed concurrently
4. Fault tolerance − Concurrency can improve the fault tolerance of the
system by allowing tasks to be executed independently. If one task fails, it
does not affect the execution of other tasks.

4.Explain Critical Section?


Critical Section is a segment of code that can be accessed by only one
process at a time. It contains shared resources that need to be accessed by
all processes. If one process is executing in Critical Section, then, other
process has to wait until the first one finishes

Since only one process can access critical section, all other process must
be stopped from accessing it. There should be some requirements that
must be fulfilled while accessing it.

43 P.Sharmila,Lecturer in computer science


Critical Section problem must satisfy three requirements –

1. Mutual Exclusion: If process Pi is executing in its Critical Section,


then, no other process can be executing in their Critical Sections.
2. Progress: If no process is executing in its Critical Section and there
exist some process that wish to enter their Critical Section, then the
selection of the processes that will enter the Critical Section can’t be
postponed indefinitely.
3. Bounded Waiting: After a process makes a request for getting into
its Critical Section, there is a limit for how many other processes can
get into their Critical Section, before this process’s request is
granted. So, after the limit is reached, system must grant the process
permission to get into its Critical Section.

5.Explain Semaphores in Operating System?


Semaphores are integer variables that are used to solve the critical section problem
by using two atomic operations, wait and signal that are used for process
synchronization.
The definitions of wait and signal are as follows −
 Wait
The wait operation decrements the value of its argument S, if it is positive. If
S is negative or zero, then no operation is performed.
wait(S)
{
while (S<=0);
S--;
}
 Signal
The signal operation increments the value of its argument S.
signal(S)
{

44 P.Sharmila,Lecturer in computer science


S++;
}
Types of Semaphores
1.Binary Semaphores

2.Counting Semaphores

1.Binary Semaphores

In these types of Semaphores the integer value of the semaphore can only be
either 0 or 1. If the value of the Semaphore is 1, it means that the process can
proceed to the critical section. if the value of the binary semaphore is 0, then the
process cannot continue to the critical section of the code.

2.Counting Semaphores

Counting semaphores are signaling integers that can take on any integer value.

45 P.Sharmila,Lecturer in computer science


6.write about Methods for Inter- process Communication?

Inter-process communication: A mechanism which is used to provide


communications among several processes is known as inter-process
communication or IPC and it is provided by the OS or operating system.

This type of communication is very helpful in data exchanging among several


threads in single or multiple programs or processes which run on single or several
computers connected through a network.

There are different modes of inter-process communication like pipes, socket, file,
signal, shared memory message queue & message passing.The working of IPC
mainly depends on a few important methods or approaches which are discussed
below.

1.Pipes
A Pipe is one type of data channel, extensively used for communication in between
two processes is unidirectional.

2.Socket

This is the endpoint to transmit or receive data within a network. This is true for
data transmitted between processes on a similar computer otherwise between
various computers on a similar network. Sockets are used by most of the operating
systems for IPC or interprocess communication.

46 P.Sharmila,Lecturer in computer science


3.File
A file is a data record that is stored on a disk on demand through a file server.
Several processes can access a file as necessary. All operating systems utilize files
for storing data.

4.Signal
The signal is very useful in IPC in a restricted way. They are system messages
transmitted from one process to another.

5.Message Queues
A linked list of messages is known as a message queue that is stored in the kernel.
It can be simply recognized through a message queue identifier. So this technique
provides communication in between single.

Message Queue

6.Shared Memory

Multiple processes can access a common shared memory. Multiple


processes communicate by shared memory, where one process makes
changes at a time and then others view the change. Shared memory does
not use kernel.

47 P.Sharmila,Lecturer in computer science


7. Explain Process Synchronization?

Process synchronization is very helpful when multiple processes are running at the
same time and more than one process has access to the same data or resources at
the same time. Process synchronization is generally used in the multi-process
system. When more than two processes have access to the same data or resources
at the same time it can cause data inconsistency so to remove this data
inconsistency processes should be synchronized with each other.

In the above picture, We take an example of a bank account that has a current
balance of 500 and there are two users which have access to that account. User 1
and User 2 both are trying to access the balance. If process 1 is for withdrawal and
process 2 is for checking the balance both will occur at the same time then user 1
might get the wrong current balance. To avoid this kind of data inconsistency
process synchronization in os is very helpful.

How Process Synchronization in OS works with an example?

We will learn how process synchronization in os works with help of an example.


We will see an example of different processes trying to access the same data at the
same time.

48 P.Sharmila,Lecturer in computer science


In the above example, there are three processes, Process 1 is trying to write the
shared data while Process 2 and Process 3 are trying to read the same data so there
are huge changes in Process 2, and Process 3 might get the wrong data.

Let’s understand some different sections of a program.

 Entry Section:- This section is used to decide the entry of the process

 Critical Section:- This section is used to make sure that only one process access
and modifies the shared data or resources.

 Exit Section:- This section is used to allow a process that is waiting in the entry
section and make sure that finished processes are also removed from the critical
section.

 Remainder Section:- The remainder section contains other parts of the code
which are not in the Critical or Exit sections.

8.Explain Classical Process Synchronization Problem?

Semaphore can be used in other synchronization problems besides Mutual


Exclusion.

We will discuss the following problems:

1. Bounded Buffer (Producer-Consumer) Problem


2. The Readers Writers Problem
3. The Dining Philosophers Problem

1. The Bounded Buffer Problem(Producer Consumer Problem):

Consider,
• a buffer which can store n items
• a producer process which creates the items (1 at a time)
• a consumer process which processes them (1 at a time)
A producer cannot produce unless there is an empty buffer slot to fill.
A consumer cannot consume unless there is at least one produced item.

49 P.Sharmila,Lecturer in computer science


Semaphore empty=N, full=0, mutex=1;

process producer
{
while (true)
{
empty.acquire( );
mutex.acquire( );
// produce
mutex.release( );
full.release( );
}
}

process consumer
{
while (true)
{
full.acquire( );
mutex.acquire( );
// consume
mutex.release( );
empty.release( );
}
}
The semaphore mutex provides mutual exclusion for access to the buffer

50 P.Sharmila,Lecturer in computer science


2.The Readers-Writers Problem

A data item such as a file is shared among several processes.


Each process is classified as either a reader or writer.Multiple readers may access
the file simultaneously.
readers' priority: no reader is kept waiting unless a writer has already obtained
permission to access the database
• writers' priority: if a writer is waiting to access the database, no new readers can
start reading.
A solution to either version may cause starvation in the readers' priority version,
writers may starving the writers' priority version, readers may starve
A semaphore solution to the readers' priority version (without addressing starvation):
Semaphore mutex = 1;
Semaphore db = 1;
int readerCount = 0;
process writer
{
db.acquire( );
// write
db.release( );
}
process reader
{
// protecting readerCount
mutex.acquire( );
++readerCount;
if (readerCount == 1)
db.acquire( );
mutex.release( );
// read

51 P.Sharmila,Lecturer in computer science


// protecting readerCount
mutex.acquire( );
--readerCount;
if (readerCount == 0)
db.release;
mutex.release( );
}

readerCount is a <cs> over which we must maintain control and we use mutex to
do so.
3. The Dining Philosophers Problem
n philosophers sit around a table thinking and eating. When a philosopher thinks
she does not interact with her colleagues. Periodically, a philosopher gets hungry
and tries to pick up the chopstick on his left and on his right. A philosopher may
only pick up one chopstick at a time and, obviously, cannot pick up a chopstick
already in the hand of neighbor philosopher.
The dining philosophers problems is an example of a large class or concurrency
control problems; it is a simple representation of the need to allocate several
resources among several processes in a deadlock-free and starvation-free manner.

52 P.Sharmila,Lecturer in computer science


Unit-4
Memory Management
1. What is Memory Management?
Memory management is allocating, freeing, and re-organizing memory in a
computer system to optimize the available memory or to make more
memory available. It keeps track of every memory location(if its is free or
occupied).
Paging, and swapping, segmentation and compaction are modern
computers four main memory management techniques. Swapping is the best
technique for memory management because it provides the most efficient
use of system resources.
Memory allocation schemes
1. Contiguous memory management schemes:
Contiguous memory allocation means assigning continuous blocks of
memory to the process. The best example of i is Array.
2. Non-Contiguous memory management schemes:
In this, the program is divided into blocks(fixed size or variable size)and
loaded at different portions of memory. That means program blocks are not
stored adjacent to each other.

2. Explain Physical and Virtual Address Space?


An logical address is generated by the CPU is commonly referred as logical address and
it is found in the memory unit is called as physical address.
The collection of logical address that generates a program is called as logical
address space and the collection of physical addresses corresponding to the logical
address is called as physical address space.

53 P.Sharmila,Lecturer in computer science


Comparison between Logical Address and Physical Address

Logical Address Physical Address

 It is a virtual address.  It is the actual location in the memory.

 It is visible to the user.  It is not visible to the user.

 It is generated by the CPU.  It is computed by the MMU.

 It is used by the user to


access the physical address  It is not accessible directly by the user.
inside the memory.

 The set of all logical  The set of all physical addresses


addresses generated by the corresponding to the logical addresses in
CPU is called the logical the logical address space is called the
address space. physical address space.

3. Explain Memory Allocation Strategies?

Memory allocation is a process by which computer programs and services


are assigned with physical or virtual memory space. Programs and services
are assigned with a specific memory as per their requirements when they are
executed. Once the program has finished its operation or is idle, the memory
is released and allocated to another program.

Memory allocation has two core types;

 Static Memory Allocation: The program is allocated memory at compile time.


 Dynamic Memory Allocation: The programs are allocated with memory at run
time.

1.Contiguous memory allocation


i. Fixed memory Partitions
ii. Variable memory Partitions

54 P.Sharmila,Lecturer in computer science


2. Non Contiguous memory allocation
i. Paging
ii. Multilevel Paging
iii. Inverted paging
iv. Segmentation

Types of Partitions
Contiguous memory allocation can be achieved when we divide the memory into
the following types of partitions:
1. Fixed-Sized Partitions
Another name for this is static partitioning. In this case, the system gets divided
into multiple fixed-sized partitions. In this type of scheme, every partition may
consist of exactly one process. This very process limits the extent at which
multiprogramming would occur, since the total number of partitions decides the
total number of processes.

2. Variable-Sized Partitions
Dynamic partitioning is another name for this. The scheme allocation in this type
of partition is done dynamically. Here, the size of every partition isn’t declared
initially. Only once we know the process size, will we know the size of the

55 P.Sharmila,Lecturer in computer science


partitions. But in this case, the size of the process and the partition is equal; thus, it
helps in preventing internal fragmentation.
On the other hand, when a process is smaller than its partition, some size of the
partition gets wasted (internal fragmentation). It occurs in static partitioning, and
dynamic partitioning solves this issue.

Non-Contiguous Memory Allocation-


 Non-contiguous memory allocation is a memory allocation technique.
 It allows to store parts of a single process in a non-contiguous fashion.
 Thus, different parts of the same process can be stored at different places in the
main memory.
Paging-
 Paging is a fixed size partitioning scheme.
 In paging, secondary memory and main memory are divided into equal fixed
size partitions.
 The partitions of secondary memory are called as pages.
 The partitions of main memory are called as frames.
 Each process is divided into parts where size of each part is same as page
size.
 The size of the last part may be less than the page size.
 The pages of process are stored in the frames of main memory depending
upon their availability.
Example-
 Consider a process is divided into 4 pages P0, P1, P2 and P3.
 Depending upon the availability, these pages may be stored in the main
memory frames in a non-contiguous fashion as shown-

56 P.Sharmila,Lecturer in computer science


Translating Logical Address into Physical Address-
 CPU always generates a logical address.
 A physical address is needed to access the main memory.
Step-01:
CPU generates a logical address consisting of two parts-
1. Page Number
2. Page Offset
Step-02:
For the page number generated by the CPU,
 Page Table provides the corresponding frame number (base address of the frame)
where that page is stored in the main memory.
Step-03:
 The frame number combined with the page offset forms the required physical
address.

 Frame number specifies the specific frame where the required page is stored.
 Page Offset specifies the specific word that has to be read from that page.

57 P.Sharmila,Lecturer in computer science


2.Multilevel Paging-
Multilevel Paging is a paging scheme that consists of two or more levels of page tables in
a hierarchical manner. It is also known as hierarchical paging.

Advantages of multilevel Paging in Operating System:

 Reduced memory overhead


 Faster page table lookup
 Flexibility

58 P.Sharmila,Lecturer in computer science


3.Inverted paging: An alternate approach is to use the Inverted Page
Table structure that consists of a one-page table entry for every frame of
the main memory. So the number of page table entries in the Inverted
Page Table reduces to the number of frames in physical memory and a
single page table is used to represent the paging information of all the
processes.

SEGMENTATION:

Segmentation is a memory-management scheme that supports user view of


memory. A program is a collection of segments. A segment is a logical unit such as
main program, procedure, function, method, object, local variables, global
variables, common block, stack, symbol table and arrays.

In the segmentation the logical memory can be divided into fixed sized blocks
these blocks are called as segments. Segmentation is a memory management
functionality that supports the user view of memory. In this, the logical memory is
divided into segments and each segment consists of segments number and offset

For example the segments in the user view of memory (logical address)is
represented as follows.

59 P.Sharmila,Lecturer in computer science


The segment table is used to mapping between the logical memory and physical
memory the segment table consists of two columns

1.base

2.limit

a) base – contains the starting physical address where the segments reside in
memory.

b) limit – specifies the length of the segment.

The mapping is represented as follows

For example,

60 P.Sharmila,Lecturer in computer science


Demand Paging(virtual memory)

Demand paging is a process of swapping in the Virtual Memory system. In this


process, all data is not moved from hard drive to main memory because while
using this demand paging, when some programs are getting demand then data will
be transferred. But, if required data is already existed into memory then not need to
copy of data. The demand paging system is done with swapping from auxiliary
storage to primary memory.

61 P.Sharmila,Lecturer in computer science


Some Page Replacement Algorithms are used in the demand paging concept to
replace different pages – such as FIFO, LIFO, Optimal Algorithm, LRU
Page, and Random Replacement Page Replacement Algorithms.

Page Replacement Algorithms in Operating Systems

1. FIFO Page Replacement Algorithm

FIFO algorithm is the simplest of all the page replacement algorithms. In


this, we maintain a queue of all the pages that are in the memory currently.
The oldest page in the memory is at the front-end of the queue and the
most recent page is at the back or rear-end of the queue.

Whenever a page fault occurs, the operating system looks at the front-end
of the queue to know the page to be replaced by the newly requested
page.

Example: Consider the page reference string as 3, 1, 2, 1, 6, 5, 1, 3 with 3-page


frames. Let’s try to find the number of page faults:

Total page faults = 7

Total Hits=1

2. LIFO Page Replacement Algorithm

This is the Last in First Out algorithm and works on LIFO principles. In this
algorithm, the newest page is replaced by the requested page. Usually, this is done

62 P.Sharmila,Lecturer in computer science


through a stack, where we maintain a stack of pages currently in the memory with
the newest page being at the top. Whenever a page fault occurs, the page at the top
of the stack is replaced.

Example: Let’s see how the LIFO performs for our example string of 3, 1, 2, 1, 6,
5, 1, 3 with 3-page frames:

Total faults=5

Hits=3

3. LRU Page Replacement Algorithm in OS

This algorithm stands for "Least recent used" and this algorithm helps the
Operating system to search those pages that are used over a short duration of time
frame.

In this algorithm, when a page fault occurs, then the page that has not been
used for the longest duration of time is replaced by the newly requested page.

Example: Let’s see the performance of the LRU on the same reference string of 3,
1, 2, 1, 6, 5, 1, 3 with 3-page frames:

63 P.Sharmila,Lecturer in computer science


4. Optimal Page Replacement Algorithm

Optimal page replacement is the best page replacement algorithm as this


algorithm results in the least number of page faults. In this algorithm, the
pages are replaced with the ones that will not be used for the longest duration
of time in the future. In simple terms, the pages that will be referred farthest
in the future are replaced in this algorithm.

Example:

Let’s take the same page reference string 3, 1, 2, 1, 6, 5, 1, 3 with 3-page


frames as we saw in FIFO. This also helps you understand how Optimal Page
replacement works the best.

Faults=5
Hits=3

5.Random Page Replacement Algorithm

This algorithm, as the name suggests, chooses any random page in the
memory to be replaced by the requested page. This algorithm can behave like
any of the algorithms based on the random page chosen to be replaced.

Example: Suppose we choose to replace the middle frame every time a page
fault occurs. Let’s see how our series of 3, 1, 2, 1, 6, 5, 1, 3 with 3-page
frames perform with this algorithm:

Faults=6
Hits=2

64 P.Sharmila,Lecturer in computer science


UNIT-5
1.Explain Directory Structure?

A Directory is the collection of the correlated files on the disk. In simple words, a
directory is like a container which contains file and folder. In a directory, we can
store the complete file attributes or some attributes of the file.

There are various types of information which are stored in a directory:

1. Name
2. Type
3. Location
4. Size
5. Position
6. Protection
7. Usage

Name: - Name is the name of the directory, which is visible to the user.

Type: - Type of a directory means what type of directory is present such as


single-level directory, two-level directory, tree-structured directory, and
Acyclic graph directory.

Location: - Location is the location of the device where the header of a file is
located.

Size: - Size means number of words/blocks/bytes in the file.

65 P.Sharmila,Lecturer in computer science


Position: - Position means the position of the next-read pointer and the next-
write pointer.

Protection: - Protection means access control on the read/write/delete/execute.

Usage: - Usage means the time of creation, modification, and access, etc.

Operations on Directory
The various types of operations on the directory are:

1. Creating
2. Deleting
3. Searching
4. List a directory
5. Renaming

Types of Directory Structure

1. Single-Level Directory
2. Two-Level Directory
3. Tree-Structured Directory
4. Acyclic Graph Directory

1.Single-Level Directory: - Single-Level Directory is the easiest directory


structure. There is only one directory in a single-level directory, and that
directory is called a root directory. In a single-level directory, all the files are
present in one directory that makes it easy to understand. In this, under the
root directory, the user cannot create the subdirectories.

66 P.Sharmila,Lecturer in computer science


2.Two-Level Directory

Two-Level Directory is another type of directory structure. In this, it is possible to


create an individual directory for each of the users. There is one master node in the
two-level directory that include an individual directory for every user. At the
second level of the directory, there is a different directory present for each of the
users. Without permission, no user can enter into the other user’s directory.

3.Tree-Structured Directory

In a tree directory structure, except root directory, every directory or file has
only one parent directory. So, there is a total separation between the users
which provide complete naming freedom. Here, if a user wishes to access
another users file, it has to go through two or more directories.

4.Acyclic-Graph Directory Structure


This problem can be solved by the acyclic-graph directory structure. As this
directory structure allows a directory or a file to have many parent

67 P.Sharmila,Lecturer in computer science


directories. So, a shared file in a directory can be pointed by the other user
directories who have access to that shared file using the links.
In the diagram below you can see that the directory having file F7 and
F8 have two parent directories.

2.Write about File Operations?

A file is a collection of logically related data that is recorded on the secondary


storage in the form of sequence of operations.

1.Create operation:

This operation is used to create a file in the file system. It is the most widely used
operation performed on the file system. To create a new file of a particular type the
associated application program calls the file system.

2. Open operation:

The user wants to open a file, it provides a file name to open the particular file in
the file system.

3. Write operation:

This operation is used to write the information into a file.

4. Read operation:

This operation reads the contents from a file. A Read pointer is maintained by the
OS, pointing to the position up to which the data has been read.

68 P.Sharmila,Lecturer in computer science


5. Re-position or Seek operation:

The seek system call re-positions the file pointers from the current position to a
specific place in the file i.e. forward or backward depending upon the user's
requirement. This operation is generally performed with those file management
systems that support direct access files.

6. Delete operation: Deleting the file will not only delete all the data stored inside
the file it is also used so that disk space occupied by it is freed. In order to delete
the specified file the directory is searched. When the directory entry is located, all
the associated file space and the directory entry is released.

7. Truncate operation:

Truncating is simply deleting the file except deleting attributes. The file is not
completely deleted although the information stored inside the file gets replaced.

8. Close operation:

When the processing of the file is complete, it should be closed so that all the
changes made permanent and all the resources occupied should be released. On
closing it deallocates all the internal descriptors that were created when the file was
opened.

9. Append operation:

This operation adds data to the end of the file.

10. Rename operation:


This operation is used to rename the existing file.

3.Explain File Allocation Methods?

File Allocation Methods in OS File allocation methods are basically ways in


which any file is stored in the memory block of the system. There are three types
for file allocation methods.

 Contiguous Allocation.
 Linked Allocation.
 Indexed Allocation.

69 P.Sharmila,Lecturer in computer science


1.Contiguous File allocation
In contiguous file allocation, the block is allocated in such a manner that all the

allocated blocks in the hard disk are adjacent.

Assuming a file needs 'n' number of blocks in the disk and the file begins with

a block at position'x', the next blocks to be assigned to it will

be x+1,x+2,x+3,...,x+n-1 so that they are in a contiguous manner.

Advantages

 It is very easy to implement.


 Memory access is faster.
 It supports sequential as well as direct access.

2.Linked File Allocation

The Linked file allocation overcomes the drawback of contiguous file allocation.
Here the file which we store on the hard disk is stored in a scattered manner
according to the space available on the hard disk.

70 P.Sharmila,Lecturer in computer science


Advantages

 There is no external fragmentation.


 The directory entry just needs the address of starting block.
 Indexed File Allocation.

The indexed file allocation is somewhat similar to linked file allocation as indexed
file allocation also uses pointers but the difference is here all the pointers are put
together into one location which is called index block.

Example

As shown in the diagram below block 19 is the index block which contains all the
addresses of the file named text1. In order, the first storage block is 9, followed by
16, 1, then 10, and 25. The negative number -1 here denotes the empty index block
list as the file text1 is still too small to fill more blocks.

71 P.Sharmila,Lecturer in computer science


4.Write about Device Management?

Device management is the process of managing the implementation, operation and


maintenance of a physical and/or virtual device. It is a broad term that includes
various administrative tools and processes for the maintenance and upkeep of a
computing, network, mobile and/or virtual device.

Device management generally performs the following:

 Installing device and component-level drivers and related software


 Configuring a device so it performs as expected using the bundled operating
system, business software and/or with other hardware devices.
 Implementing security measures and processes.

Devices usually refer to physical/hardware devices such as computers, laptops,


servers, mobile phones and more. They could also be virtual, however, such as
virtual machines or virtual switches. In Windows, device management is also an
administrative module that is used for managing or configuring the physical
devices, ports and interfaces of a computer or server.

5. Explain Pipes?
Pipe is a communication medium between two or more related or interrelated
processes. It can be either within one process or a communication between the
child and the parent processes. Communication can also be multi-level such as
communication between the parent, the child and the grand-child, etc.
Communication is achieved by one process writing into the pipe and other reading
from the pipe. To achieve the pipe system call, create two files, one to write into
the file and another to read from the file.
Pipe mechanism can be viewed with a real-time scenario such as filling water with
the pipe into some container, say a bucket, and someone retrieving it, say with a
mug. The filling process is nothing but writing into the pipe and the reading
process is nothing but retrieving from the pipe. This implies that one output (water)
is input for the other (bucket).

72 P.Sharmila,Lecturer in computer science


This system call would create a pipe for one-way communication i.e., it creates
two descriptors, first one is connected to read from the pipe and other one is
connected to write into the pipe.

6. What is Buffer?Types of Buffering?


The buffer is an area in the main memory used to store or hold the
data temporarily. In other words, buffer temporarily stores data transmitted from
one place to another, either between two devices or an application. The act of
storing data temporarily in the buffer is called buffering.

1. Single Buffer

In Single Buffering, only one buffer is used to transfer the data between two
devices. The producer produces one block of data into the buffer. After that, the
consumer consumes the buffer. Only when the buffer is empty, the processor again
produces the data.

2. Double Buffer In Double Buffering, two schemes or two buffers are used in
the place of one. In this buffering, the producer produces one buffer while the
consumer consumes another buffer simultaneously. So, the producer not needs to
wait for filling the buffer. Double buffering is also known as buffer swapping.

3. Circular Buffer

When more than two buffers are used, the buffers' collection is called a circular
buffer. Each buffer is being one unit in the circular buffer. The data transfer rate
will increase using the circular buffer rather than the double buffering.

73 P.Sharmila,Lecturer in computer science


How Buffering Works

7.What is Shared Memory?

Shared memory is a memory shared between two or more processes.

Shared memory is a memory shared between two or more processes. Each process
has its own address space; if any process wants to communicate with some
information from its own address space to other processes, then it is only possible
with IPC (inter-process communication) techniques.

74 P.Sharmila,Lecturer in computer science


Shared memory is the fastest inter-process communication mechanism. The
operating system maps a memory segment in the address space of several
processes to read and write in that memory segment without calling operating
system functions.

For applications that exchange large amounts of data, shared memory is far
superior to message passing techniques like message queues
IPC using Message Queues

A message queue is an inter-process communication (IPC) mechanism that allows


processes to exchange data in the form of messages between two processes. It
allows processes to communicate asynchronously by sending messages to each
other where the messages are stored in a queue, waiting to be processed, and are
deleted after being processed.

8.Write about Security Policy Mechanism?


Security refers to providing a protection system to computer system resources such
as CPU, memory, disk, software programs and most importantly data/information
stored in the computer system. If a computer program is run by an unauthorized
user, then he/she may cause severe damage to computer or data stored in it. So a
computer system must be protected against unauthorized access, malicious access
to system memory, viruses, worms etc.

75 P.Sharmila,Lecturer in computer science


 Authentication
 One Time passwords
 Program Threats
 System Threats

Authentication

Authentication refers to identifying each user of the system and associating the
executing programs with those users.
Operating Systems generally identifies/authenticates users using following three
ways −
 Username / Password − User need to enter a registered username and
password with Operating system to login into the system.
 User card/key − User need to punch card in card slot, or enter key generated
by key generator in option provided by operating system to login into the
system.
 User attribute - fingerprint/ eye retina pattern/ signature − User need to
pass his/her attribute via designated input device used by operating system to
login into the system.

One Time passwords

One-time passwords provide additional security along with normal authentication.


In One-Time Password system, a unique password is required every time user tries
to login into the system. Once a one-time password is used, then it cannot be used
again.

Program Threats

Operating system's processes and kernel do the designated task as instructed. If a


user program made these process do malicious tasks, then it is known as Program
Threats. One of the common example of program threat is a program installed in a
computer which can store and send user credentials via network to some hacker.

System Threats

System threats refers to misuse of system services and network connections to put
user in trouble. System threats can be used to launch program threats on a complete
network called as program attack. System threats creates such an environment that
operating system resources/ user files are misused.

76 P.Sharmila,Lecturer in computer science


9.What is Authentication and Internal Access Authorization?

Access Authorization
Authorization is the process of giving someone permission to do or have
something. In multi-user computer systems, a system administrator defines for the
system which users are allowed access to the system and what privileges of use

 Authorization is a process by which a server determines if the client has


permission to use a resource or access a file.
 The type of authentication required for authorization may vary; passwords
may be required in some cases but not in others.
 In some cases, there is no authorization; any user may be use a resource or
access a file simply by asking for it. Most of the web pages on the Internet
require no authentication or authorization.

Most web security systems are based on a two-step process. The first step is
authentication, which ensures about the user identity and the second stage is
authorization, which allows the user to access the various resources based on the
user's identity.

Authentication in Operating System

Authentication mechanism determines the users identity before revealing the


sensitive information. It is very crucial for the system or interfaces where the user
priority is to protect the confidential information. In the process, the user makes a
provable claim about individual identity (his or her) or an entity identity.

The credentials or claim could be a username, password, fingerprint etc.

77 P.Sharmila,Lecturer in computer science


10. Introduction to Android Operating System?Android Architecture?

Android is a powerful operating system and it supports a large number of


applications on Smartphones.These applications are more comfortable and
advanced for users. The android is an open-source operating system that means
that it’s free and anyone can use it. Android has got millions of apps available that
can help you manage your life one or another way and it is available at low cost in
the market for that reason android is very popular.

Features of Android Operating System


 Near Field Communication (NFC)
 Alternate Keyboards
 Automation
 Wireless App Downloads
 Storage & Battery Swap
 Custom Home Screen
 Custom ROMs
 Headset layout
 Storage
 Connectivity:Bluetooth, WI-FI ,etc
 Messaging: SMS, MMS, C2DM (could to device messaging), GCM (Google
could messaging)
 Multilanguage support
 Multi-touch
 Video calling
 Screen capture
 External storage
 Optimized graphics

78 P.Sharmila,Lecturer in computer science


Android Architecture

android architecture or Android software stack is categorized into five


parts:

1. linux kernel
2. native libraries (middleware),
3. Android Runtime
4. Application Framework
5. Applications

Linux Kernel
The android uses the powerful Linux kernel and it supports a wide range of
hardware drivers. The kernel is the heart of the operating system that manages
input and output requests from the software.
Libraries
The on top of a Linux kennel there is a set of libraries including open-source web
browsers such as WebKit, library libc. These libraries are used to play and record
audio and video.

79 P.Sharmila,Lecturer in computer science


Android Runtime
The android runtime provides a key component called Dalvik Virtual Machine
which is a kind of java virtual machine. It is specially designed and optimized for
android. The Dalvik VM is the process virtual machine in the android operating
system. It is software that runs apps on android devices.
Application Framework
The application framework layer provides many higher-level services to
applications such as windows manager, view system, package manager, resource
manager, etc.
Applications
You will find all the android applications at the top layer and you will write your
application and install it on this layer. Examples of such applications are contacts,
books, browsers, services, etc. Each application performs a different role in the
overall applications.

11. Explain Android Development Framework?

Top Android Frameworks For App Development


1. Flutter Android Framework
Flutter is an open-source UI-based framework developed by Google in
2017. It is cross-platform, meaning a single codebase is required for iOS
and Android. Flutter is a prevalent choice nowadays due to its productivity
and efficiency. It helps to create a beautiful user interface that provides a
native-like feel and has various widgets which can be personalized to
create a beautiful front end.

Which Companies Use The Flutter Framework?


Companies like Alibaba, Google, CapitalOne, Tencent, and eBay have used
the Flutter framework to create mobile applications, making it a trend on
the rise.

2. Ionic Android Framework


Released in 2015, Ionic is an open-source front-end framework based on
technologies such as HTML, CSS, JavaScript, Angular, and Typescript. It

80 P.Sharmila,Lecturer in computer science


allows businesses to create hybrid mobile applications, provides high
performance, and creates sophisticated and robust designs.

Which Businesses Use The Ionic Framework?


Startups and web development firms all over the wo rld use Ionic. More
than 4 million Ionic mobile, desktop, and web apps for rapidly expanding
startup companies, travel agencies, restaurants, pharmaceuticals, and other
industries have been powered by it thus far. 4 to 5 million app developers
have utilized it.

3. React Native Android Framework


This framework is thriving, especially in the Android app development
domain. React Native is based on JavaScript and is one of the most in -
demand frameworks. It is estimated that 14.85% of the top 500 apps in the
US are built with React Native. Created by Facebook, it’s a UI -based
framework with a robust open-source community.
Which Companies Use The React Native Framework?
Numerous businesses, including Facebook, Instagram, Tesla, Intuit,
Bloomberg, Uber, Yahoo, Walmart, and others, have adopted React Native
over the years and are now widely used in thousands of apps due to its
code reusability, live-to-reload features, and excellent performance
flexibility.

4. Xamarin Android Framework


With over 2 billion downloads, the Xamarin framework is used by over
13,000 apps. Xamarin has recently emerged as an in -demand choice for
developing cross-platform applications. It uses C# and works on all three
platforms, Windows, iOS, and Android, to give the whole experien ce of a
native app (the code shareability is almost 90%). In addition, it provides a
variety of class libraries, cuts down on time and cost during development,
and uses modern-day IDEs such as VSCode.

Which Companies Use The Xamarin Framework?


The enterprise and developers both adore Xamarin. Businesses from all
sectors utilize Xamarin and .NET to create compelling native mobile apps.

81 P.Sharmila,Lecturer in computer science


12.Explain Android Applications?

Android Applications

Android applications are usually developed in the Java language using the Android
Software Development Kit.
Once developed, Android applications can be packaged easily and sold out either
through a store such as Google Play, SlideME, Opera Mobile
Store, Mobango, F-droid and the Amazon Appstore.
Android powers hundreds of millions of mobile devices in more than 190 countries
around the world. It's the largest installed base of any mobile platform and growing
fast. Every day more than 1 million new Android devices are activated worldwide.
This tutorial has been written with an aim to teach you how to develop and
package Android application. We will start from environment setup for Android
application programming and then drill down to look into various aspects of
Android applications.

Categories of Android applications

There are many android applications in the market. The top categories are −

82 P.Sharmila,Lecturer in computer science


13.Explain Android Process Management and File System?

1.Every Android application runs in its own linux process.

2.Every application consists of different components like activity,service and


Broadcast receiver.

3.The applications should use these components correctly,otherwise the system


will kill the application processes.

Process types

1.foreground process

2.visible process

3.service process

4.Background process

5.Empty process

File system

The Android OS is a popular and universally used operating system for


smartphones. Android’s user-visible file system is one of its advantages over iOS. It
allows you to more easily work with files, opening them in any app of your choice
as long as you know how.
Like other modern operating systems, Android has a disk-based file
system. There are two storage areas: internal and external. Internal storage refers to
the built-in, non-volatile memory. Devices also can come with removable memory
(like a SD card), which is referred to as external storage.
The internal storage is also occasionally referred to as permanent storage. Files
saved in internal storage are accessible only to your app by default.
External storage can be removed at any time and files saved here can be accessible
to everyone.

83 P.Sharmila,Lecturer in computer science


App data, pictures, music, and more are all accessed through a single starting
folder, and that’s certainly a different take to the hierarchy that PC and Mac users
will be used to, and is much more powerful than what’s available to iOS users.

Under the Android file system, there are usually six main partitions found on every
device. Some devices may come with a couple of additional partitions, those differ
from model to model, but there are six primary partitions that are found on every
single Android device. These include /boot, /system, /recovery, /data, /cache, and
/misc. Additionally, for external Android smartphone, there are two file system
partitions — /sdcard and /sd-ext. So, let’s break down each partition separately and
explore the Android File system hierarchy.

14.Explain Small Application Development using Android Development


Framework?

Mobile App Development Framework is a library that offers the required


fundamental structure to create mobile applications for a specific environment.

mobile application frameworks can be classified majorly into 3 categories: Native


Apps, Web Apps & Hybrid Apps.

 Native Apps: A Native App is an application that is specifically designed for a


particular platform or device.
 Web Apps: A Web App concerns with the application that is designed to
deliver web pages on different web platforms for any device.
 Hybrid Apps: A Hybrid App is a combination of both native & web
applications. It can be developed for any platform from a single code base.

84 P.Sharmila,Lecturer in computer science


1. React Native
React Native is one of the most recommended Mobile App Frameworks in the
development industry. The framework, created by Facebook, is an open-source
framework that offers you to develop mobile applications
for Android & iOS platforms.
 Code Re-usability & Cost-Effective
 Compatible with third-party plugins
 Ease of Maintenance

2. Flutter
Flutter, developed by Google, is a UI toolkit to build native applications for the
mobile, desktop & web platform. Flutter is a cross-platform mobile app
development framework that works on one code base to develop Android as
well as iOS applications.
 Flexible User interface (UI)
 Provides Strong Widget Support
 Offers Built-in Material Design
 Fast Application Development

3. Xamarin
Xamarin is also one of the most popular open-source framework used to develop
mobile applications. The framework, acquired by Microsoft, is based
on .Net and allows you to build native applications for Android, iOS,
and Windows platforms.
 Easier API Integration
 Target All Platforms
 Cost-Effective & Faster Development Process

4. Mobile Angular UI
Mobile Angular UI is an open-source mobile application development framework
that merges the implementation of the Bootstrap and Angular framework. The
framework offers various UI components such
as overlays, switches, sidebars, navbars, scrollable areas, etc.
 Offers Interactive Components
 LightWeight
 Easier conversion from the web or desktop application to the mobile app

85 P.Sharmila,Lecturer in computer science


5. Ionic
Ionic, developed in 2013, is an open-source framework that allows you to build
cross-platform mobile apps using web technologies
like HTML, CSS & JavaScript. The application built through Ionic framework
can work on Android, iOS & Windows platforms.
 Faster Application Development
 Built-in UI components
 Platform Independent

6.JQuery Mobile
JQuery Mobile is a cross-platform development framework that is used to build
mobile and web applications for various devices. The framework allows
running a single code version across for all the devices.
 Supports multiple platforms & devices
 Lightweight Size

86 P.Sharmila,Lecturer in computer science


87 P.Sharmila,Lecturer in computer science

You might also like