0% found this document useful (0 votes)
14 views10 pages

Untitled Document

An Operating System (OS) is system software that acts as an intermediary between computer hardware and users, managing resources and providing essential services to applications. Key functions include process management, memory management, file system management, device management, security, and user interface provision. Deadlocks can occur when processes are blocked waiting for resources, and strategies for handling deadlocks include prevention, avoidance, detection, and recovery.

Uploaded by

itsnikku02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views10 pages

Untitled Document

An Operating System (OS) is system software that acts as an intermediary between computer hardware and users, managing resources and providing essential services to applications. Key functions include process management, memory management, file system management, device management, security, and user interface provision. Deadlocks can occur when processes are blocked waiting for resources, and strategies for handling deadlocks include prevention, avoidance, detection, and recovery.

Uploaded by

itsnikku02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

What is an Operating System (OS)?

An Operating System (OS) is system software that serves as an intermediary


between computer hardware and users. It manages hardware resources,
facilitates communication between software and hardware, and provides
essential services to application programs. The OS ensures efficient use of
resources, enhances user experience, and maintains system stability and
security.

Key Roles of an OS:

●​ Resource Manager: Allocates and manages resources such as CPU,


memory, storage, and I/O devices.
●​ User Interface Provider: Offers user interfaces like Command-Line
Interface (CLI) or Graphical User Interface (GUI) for user interaction.
●​ Security and Access Control: Protects system data and resources from
unauthorized access.
●​ Error Handling: Detects, handles, and recovers from hardware and
software errors.

Functions of an Operating System:

1.​ Process Management:


○​ The OS handles the creation, scheduling, and termination of
processes (programs in execution).
○​ It manages process states: New, Ready, Running, Waiting, and
Terminated.
○​ Ensures fair CPU time distribution among processes using
scheduling algorithms like:
■​ First-Come, First-Served (FCFS): Processes are executed in
the order they arrive.
■​ Shortest Job Next (SJN): Prioritizes processes with the
shortest execution time.
■​ Round Robin (RR): Each process gets a fixed time slice for
execution.
■​ Priority Scheduling: Executes processes based on priority
levels.
2.​ Memory Management:
○​ Allocates and deallocates memory spaces as needed by
applications and system processes.
○​ Maintains a record of each memory location's status (allocated or
free).
○​ Ensures efficient memory utilization and prevents conflicts through:
■​ Paging: Divides memory into fixed-size pages for efficient
allocation.
■​ Segmentation: Divides memory into variable-sized segments
based on logical divisions like functions or modules.
■​ Virtual Memory: Uses secondary storage (e.g., hard disk) as
an extension of RAM, enabling larger applications to run on
limited physical memory.
3.​ File System Management:
○​ Organizes and manages files on storage devices, supporting
operations like:
■​ Creation, Deletion, Reading, and Writing of Files.
■​ Directory Management: Organizes files hierarchically for
easy navigation and access.
■​ Access Control: Restricts file access using permissions
(read, write, execute).
■​ File Allocation Methods:
■​ Contiguous Allocation: Stores files in contiguous
blocks for fast access but can cause fragmentation.
■​ Linked Allocation: Uses pointers to link file blocks,
flexible but slower for random access.
■​ Indexed Allocation: Maintains an index block
containing pointers to file blocks, ensuring efficient
access.
4.​ Device Management:
○​ Controls peripheral devices (e.g., printers, keyboards, storage
devices) using device drivers.
○​ Facilitates communication between devices and the OS.
○​ Handles Input/Output operations efficiently, ensuring devices are not
overloaded.
○​ Implements Interrupt Handling to prioritize and manage device
requests.
5.​ Security and Access Control:
○​ Protects data and resources from unauthorized access.
○​ Implements:
■​ User Authentication: Verifies user identity using credentials
like usernames and passwords.
■​ Access Permissions: Defines user access levels (e.g.,
read-only, write, execute).
■​ Encryption: Secures data transmission and storage.
6.​ User Interface:
○​ Provides a way for users to interact with the computer system.
○​ Types of User Interfaces:
■​ Command-Line Interface (CLI): Text-based interface where
users type commands.
■​ Graphical User Interface (GUI): Visual interface with icons,
windows, and menus.
7.​ Error Detection and Handling:
○​ Monitors and handles hardware and software errors.
○​ Ensures consistent system performance and recovery from errors.
○​ Logs errors for diagnostics and troubleshooting.

Examples of Operating Systems:

●​ Desktop and Laptop Operating Systems:


○​ Windows: Popular OS by Microsoft, known for its GUI and
extensive software support.
○​ macOS: Developed by Apple, known for its sleek design and
integration with Apple devices.
○​ Linux (Ubuntu, Fedora, Debian): Open-source OS, highly
customizable, widely used for development and servers.
●​ Mobile Operating Systems:
○​ Android: Developed by Google, used in smartphones and tablets,
based on Linux kernel.
○​ iOS: Developed by Apple, exclusive to iPhone, iPad, and iPod
Touch.
●​ Server Operating Systems:
○​ Windows Server: Designed for enterprise-level networking and
hosting applications.
○​ Linux Server (Red Hat, CentOS, Ubuntu Server): Preferred for
web servers due to stability and security.
○​ Unix: Multiuser, multitasking OS used in servers and workstations.

OS vs. Kernel:

Aspect Operating System (OS) Kernel

Definition System software managing Core component of the OS


hardware and providing services to interacting directly with
application software. hardware.

Function Manages system resources, Manages CPU, memory,


provides UI, and facilitates device communication, and
application execution. system calls.

Dependen Depends on the kernel for Functions independently but


cy hardware communication. is part of the OS.

Types Monolithic, Microkernel, Hybrid, Monolithic Kernel,


and Embedded OS. Microkernel, Hybrid Kernel.

Example Windows, Linux, macOS, Android. Linux Kernel, Windows NT


Kernel.

User Mode vs. Kernel Mode:


Aspect User Mode Kernel Mode

Definition Restricted mode where Privileged mode where the


applications run with limited kernel executes with full
system access. hardware access.

Access Limited access to memory and Full access to hardware and


Level hardware for security reasons. system memory.

Crash Application crash does not System crash leads to OS


Impact affect system stability. failure.

Examples Running applications like Device drivers, memory


browsers, editors. management, system calls.

Transition Uses system calls to request Switches to user mode to


kernel services. execute application code.

System Calls:

●​ Definition:
○​ System Calls are the programming interface between user
applications and the OS kernel.
○​ They enable programs to request services from the OS, such as
hardware access, file management, and process control.
●​ Types of System Calls:
○​ Process Control:
■​ Create, execute, and terminate processes.
■​ Examples: fork() (create a child process), exec() (execute
a new program), exit() (terminate a process).
○​ File Management:
■​ Operations on files like creating, reading, writing, and closing.
■​ Examples: open() (open a file), read() (read data),
write() (write data), close() (close file).
○​ Device Management:
■​ Interacts with device drivers and controls devices.
■​ Examples: ioctl() (control device operations), read() and
write() (device I/O).
○​ Information Maintenance:
■​ Gets and sets system information.
■​ Examples: getpid() (get process ID), alarm() (set a
timer), sleep() (pause execution).
○​ Communication:
■​ Facilitates communication between processes.
■​ Examples: pipe() (create a communication channel),
shmget() (shared memory), msgget() (message queue).
●​ Examples of System Calls:
○​ Linux: fork(), exec(), open(), read(), write()
○​ Windows: CreateProcess(), ReadFile(), WriteFile(),
ExitProcess()

Deadlock in Operating Systems

A deadlock in an operating system 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. In simpler terms, deadlock occurs when two or more processes wait indefinitely for
each other to release resources.

Conditions for Deadlock (Coffman’s Conditions)


Deadlock can occur if all the following four conditions are satisfied simultaneously:

1.​ Mutual Exclusion:


○​ At least one resource must be held in a non-shareable mode. That is, only one
process can use the resource at any given time.
○​ If another process requests the resource, the requesting process must be
delayed until the resource is released.
2.​ Hold and Wait:
○​ A process is holding at least one resource and waiting to acquire additional
resources that are currently being held by other processes.
3.​ No Preemption:
○​ Resources cannot be forcibly taken away from a process. They must be released
voluntarily by the process holding them, after it has completed its task.
4.​ Circular Wait:
○​ A set of processes are waiting for each other in a circular chain. For example,
process P1 is waiting for a resource held by P2, P2 is waiting for a resource held
by P3, and P3 is waiting for a resource held by P1.

Resource Allocation Graph (RAG)


●​ A Resource Allocation Graph is a graphical representation of the resources allocated to
processes and the resources requested by them.
●​ It consists of nodes and edges:
○​ Nodes:
■​ Circles represent processes.
■​ Squares represent resources.
○​ Edges:
■​ A directed edge from a process to a resource represents a request.
■​ A directed edge from a resource to a process indicates allocation.
●​ Deadlock Detection Using RAG:
○​ If the graph contains no cycles, then no deadlock exists.
○​ If the graph contains a cycle:
■​ In the case of a single instance per resource type, a deadlock exists.
■​ In the case of multiple instances per resource type, a cycle does not
necessarily imply a deadlock.

Deadlock Handling Strategies


1.​ Deadlock Prevention:
○​ Design the system in such a way that at least one of the necessary conditions for
deadlock cannot hold.
■​ Mutual Exclusion: Make resources shareable.
■​ Hold and Wait: Require processes to request all resources at once.
■​ No Preemption: Allow preemption of resources.
■​ Circular Wait: Impose a strict ordering on the resources.
2.​ Deadlock Avoidance:
○​ The system dynamically examines the resource-allocation state to ensure that a
circular wait condition cannot occur.
○​ Banker's Algorithm is used to check for safe states by simulating resource
allocation to ensure no deadlocks will occur.
3.​ Deadlock Detection and Recovery:
○​ Allow deadlocks to occur, then detect and recover from them.
■​ Deadlock Detection: Using a detection algorithm to check for cycles in
the Resource Allocation Graph.
■​ Deadlock Recovery: Methods include:
■​ Process Termination: Terminate one or more processes to break
the cycle.
■​ Resource Preemption: Preempt resources from other processes
and assign them to the blocked processes.
4.​ Ignoring Deadlock (Ostrich Algorithm):
○​ The system simply ignores the problem of deadlocks.
○​ This is used in most operating systems like Windows and UNIX, where deadlocks
are rare and the cost of prevention and detection is high.

Deadlock Avoidance Algorithms


1. Banker's Algorithm:

●​ It is a resource allocation and deadlock avoidance algorithm developed by Edsger


Dijkstra.
●​ It is named so because it can be compared to a bank where customers request loans
and the bank grants loans only if it can satisfy all customer requests without getting
bankrupt.
●​ Data Structures Required:
○​ Available: Number of available resources of each type.
○​ Max: Maximum demand of each process.
○​ Allocation: Number of resources currently allocated to each process.
○​ Need: Remaining resource needs of each process.
■​ Need=Max−AllocationNeed = Max - AllocationNeed=Max−Allocation
●​ Algorithm Steps:
○​ Check if the request ≤ Need.
○​ Check if the request ≤ Available.
○​ Simulate resource allocation and check for a safe state.
○​ If the system remains in a safe state, allocate resources. Otherwise, the process
must wait.

Examples
Example 1: Circular Wait

●​ P1 is holding Resource A and waiting for Resource B.


●​ P2 is holding Resource B and waiting for Resource A.
●​ This forms a cycle, leading to a deadlock.

Example 2: Using Banker's Algorithm

●​ Given:
○​ Total resources: A=10, B=5, C=7
○​ Available: A=3, B=2, C=2
○​ Allocation and Maximum demand for 3 processes are:

Proces Allocation (A B C) Max (A B C)


s

P0 010 753

P1 200 322

P2 302 902

●​ Calculate Need as: Need = Max - Allocation

Process Need (A B C)

P0 743

P1 122

P2 600

●​ Check if the system is in a safe state by simulating resource allocation and seeing if all
processes can complete.
Deadlock Recovery Techniques
1.​ Process Termination:
○​ Abort all deadlocked processes or Abort one process at a time until the
deadlock cycle is broken.
○​ Criteria for choosing the process:
■​ Priority
■​ Execution time
■​ Number of resources held
2.​ Resource Preemption:
○​ Preempt resources from some processes and allocate them to others.
○​ Challenges:
■​ Selecting the victim
■​ Rollback to a safe state
■​ Starvation prevention by ensuring that no process is repeatedly
preempted.

You might also like