OS
1)Illustrate the role of the operating system in connection with user and system viewpoints with a
diagram.
a) An Operating System (OS) acts as an intermediary between users, application programs, and
computer hardware.
It provides a platform where hardware resources (CPU, memory, I/O devices) are used e ciently
to run application programs and serve user needs.
User View of the Operating System
From the user’s perspective, the OS is designed to make the computer easy to use:
•Single-user systems (PCs, Laptops):
Focus on ease of use and performance, not on sharing resources.
•Multi-user systems (Mainframes, Servers):
Focus on resource utilisation so all users share CPU, memory, and I/O fairly.
•Networked Workstations:
Balance between usability and resource sharing (e.g., print servers, le servers).
•Mobile Devices (Smartphones, Tablets):
Touch-based interfaces for ease of interaction, wireless connectivity.
•Embedded Systems (Cars, Home Devices):
No direct user interaction; OS runs silently to control devices.
System View of the Operating System
From the system’s perspective, the OS is:
•A Resource Allocator:
Manages CPU time, memory, I/O devices, and storage among programs and users.
•A Control Program:
Manages execution of user programs, prevents errors, and controls I/O operations.
fi
ffi
2) With a diagram discuss how dual mode of operation protects operating system from errant
users.
a) Modern computer systems use a dual-mode operation to protect the operating system (OS)
and resources from errant or malicious user programs.
The two modes are:
• User Mode (Mode bit = 1) –
Normal execution of user applications. Access to critical instructions (like direct I/O operations or
hardware control) is restricted.
• Kernel Mode (Mode bit = 0) –
Privileged execution mode where the OS runs. All machine instructions, including privileged ones,
can be executed.
How Protection Works
• A mode bit (0 = kernel, 1 = user) is maintained by the hardware to indicate the
current mode.
• At system boot, the system starts in kernel mode to load the operating system.
• When a user program requests a service (system call, trap, or interrupt), the CPU
switches from user mode to kernel mode to safely execute the request.
• After the service is completed, the CPU returns to user mode.
• If a user program attempts to execute privileged instructions in user mode, the
hardware traps to the OS, preventing any harmful operation.
3) What are the responsibilities of the operating system with respect to
i) Process management
ii) Memory management
iii) File system management
iv) Input-output management.
a)
i) PROCESS MANAGEMENT:
A process is a program in execution.
Since processes require CPU time, memory, les, and I/O devices, the operating system must
manage all activities related to their creation, execution, and termination.
The OS is responsible for the following process management tasks:
1. Process Scheduling
• Decides which process will run on the CPU and for how long.
• Uses scheduling algorithms (like FCFS, Round Robin, Priority) to maximise CPU
utilisation and ensure fairness.
fi
2. Process Creation and Deletion
• Creates user processes (applications) and system processes (OS tasks).
• Cleans up resources when processes terminate.
3. Process Suspension and Resumption
• Temporarily stops (suspends) processes when needed (e.g., waiting for I/O).
• Resumes processes once resources are available.
4. Process Synchronisation
• Provides mechanisms (like semaphores, mutexes) to coordinate multiple processes
so they can safely share data without con icts.
5. Process Communication
• Enables processes to exchange information using Inter-Process Communication
(IPC) techniques such as pipes, message passing, or shared memory.
ii) MEMORY MANAGEMENT:
Main memory is a large array of bytes that stores the data and instructions needed by the CPU for
execution.
Since multiple programs often share memory simultaneously, the operating system must manage
memory e ciently to ensure safe and optimal utilisation.
The OS is responsible for the following memory management tasks:
1. Tracking Memory Usage
• Keeps a record of which parts of memory are in use and which processes are using
them.
2. Allocation and Deallocation
• Allocates memory to processes when they start execution.
• Deallocates memory and marks it as free when a process terminates.
3. Memory Placement and Movement
• Decides which processes (or parts of processes) should be loaded into memory
and when to swap them in or out to optimise CPU utilisation and system response time.
iii) File-System Management:
The le system provides a way to store, organise, and access data on storage devices like
magnetic disks, optical disks, and tapes.
Since each storage medium and device has unique characteristics, the operating system must
manage les and directories to ensure e cient and secure access.
The OS is responsible for the following le management tasks:
1. File Creation and Deletion
•Creates new les for user and system programs.
•Deletes les when they are no longer needed.
2. Directory Management
•Creates and deletes directories to organise les for easier access.
•Maintains the hierarchical structure for e cient searching.
3. File and Directory Manipulation
•Provides operations (primitives) such as read, write, append, rename, open, and close for
managing les and directories.
4. Mapping to Storage
•Maps logical le names to physical storage locations on secondary storage devices.
5. Backup and Recovery
•Maintains backups of les on stable, non-volatile media to prevent data loss.
iv) Input-output management.
The I/O system enables communication between the computer and external devices (disks,
printers, keyboards, network cards, etc.).
fi
fi
fi
ffi
fi
fi
fi
fi
fi
ffi
ffi
fl
fi
Since each device has unique characteristics, the operating system provides a uniform interface
to hide hardware details and ensure e cient data transfer.
The OS is responsible for the following I/O management tasks:
1. Device Driver Management
• Provides a general device-driver interface so that di erent hardware devices can
be accessed in a uniform way.
• Uses speci c drivers to handle the peculiarities of each device.
2. Bu ering, Caching, and Spooling
• Bu ering: Temporarily stores data during transfer between devices and memory to
handle speed di erences.
• Caching: Stores frequently accessed data in high-speed memory for quick access.
• Spooling: Queues data (e.g., print jobs) for devices that cannot handle
simultaneous operations.
3. Device Communication and Control
• Coordinates interrupt handling to signal I/O completion or errors.
• Manages data transfer between main memory and devices e ciently.
4. Device Allocation and Deallocation
• Keeps track of all I/O devices, allocates them to processes when requested, and
releases them after use.
4) Explain the “MicroKernel approach” for the design of an operating system and state its
advantages.
a) Microkernel Approach in Operating System Design:
The microkernel approach structures the operating system by removing all nonessential
components from the kernel and implementing them as system or user-level programs, leaving
only a small, minimal kernel.
Key Features
•The microkernel contains only the essential functions, such as:
•Basic process management
•Basic memory management
•Inter-process communication (IPC) (message passing)
ff
ff
ff
fi
ffi
ff
ffi
•All other services (e.g., le systems, device drivers, networking, user interface) run in user space
as separate processes.
•Communication between user programs and services occurs via message passing through the
microkernel.
Advantages of the Microkernel Approach
1. Ease of Extension
•New services can be added in the user space without changing the kernel.
2. Portability
•Easier to adapt (port) the operating system to new hardware because the kernel is small and
hardware-independent.
3. Reliability and Security
•Most services run in user mode.
•If a service fails, the kernel and other services remain una ected, improving fault tolerance.
4. Simpler Maintenance
•A smaller kernel means fewer changes are needed when updates are required.
Example Operating Systems
•Mach (Carnegie Mellon University)
•QNX (real-time OS for embedded systems)
•Mac OS X (Darwin kernel) (partly based on Mach)
5) What is the problem with priority scheduling? Exemplify a remedy for the same
Problem with Priority Scheduling
In priority scheduling, the CPU is allocated to the process with the highest priority (lowest priority
number).
A major problem with this algorithm is inde nite blocking or starvation:
• Starvation occurs when a low-priority process waits inde nitely because the CPU
is continuously assigned to higher-priority processes.
• In a heavily loaded system, a constant stream of high-priority processes can
prevent a low-priority process from ever executing.
EXAMPLE Remedy – Aging
fi
fi
ff
fi
The standard solution to starvation is aging.
•Aging gradually increases the priority of a process the longer it waits in the ready queue.
•For example, if priorities range from 127 (lowest) to 0 (highest), the system can raise the priority
by 1 every 15 minutes.
•Eventually, even a process that started with the lowest priority will reach the highest priority and
get CPU time.
6)What is a thread? Compare user-level and kernel-level threads.
a)A thread is the smallest unit of execution within a process.
•A process may contain multiple threads, each having its own program counter, register set, and
stack, but sharing the code, data, and operating system resources of the process.
•Multithreading allows parallel execution within a single process, improving e ciency and
responsiveness.
Types of Threads
Threads can be implemented in two main ways:
1. User-Level Threads (ULTs) – Managed by a user-level thread library, with no direct involvement
of the kernel.
2. Kernel-Level Threads (KLTs) – Managed directly by the operating system’s kernel.
7) What are System calls? Demonstrate the working of any three types of system calls
a) System Calls
A system call is the mechanism by which a user-level program requests a service from the
operating system kernel.
•It provides the interface between the application and the OS.
•Examples of services requested: creating a process, reading/writing a le, allocating memory, or
communicating between processes.
fi
ffi
System calls are usually accessed through an Application Programming Interface (API) such as
POSIX (UNIX/Linux) or Windows API.
Types of System Calls
System calls can be broadly grouped into categories like:
•Process control (create/terminate processes)
•File management (open/read/write/close les)
•Device management (control hardware devices)
•Information maintenance (get/set time, system data)
•Communication (message passing, network communication)
•Protection (access control) fi
11. What is semaphore? Develop a solution to the readers-writer problem using semaphores.
a)pending
12. Explain Deadlock and the necessary conditions for a deadlock to occur
a) Deadlock
A deadlock is a situation in which a set of processes are permanently blocked, each waiting for an
event that can be caused only by another process in the same set.
• Typically, the event is the release of a resource that another process holds.
• Since none of the processes can proceed, the system reaches a state of
permanent waiting.
13) What is a Virtual Machine? Explain about para-virtualization
a)Virtual Machine (VM)
A Virtual Machine is a software-based environment that allows multiple guest operating systems
and their applications to run on a single physical machine as if each has its own dedicated
hardware.
•The Virtual Machine Monitor (VMM) or hypervisor provides an abstraction layer that:
•Presents virtual hardware (CPU, memory, I/O devices) to each guest OS.
•Manages and isolates the guests to ensure protection and resource sharing.
•To the guest OS, the virtual machine appears like real hardware, even though it is simulated.
Examples: VMware, VirtualBox, Microsoft Hyper-V, KVM.
Para-Virtualization
•De nition:
Para-virtualisation is a virtualisation technique in which the guest operating system is modi ed to
work cooperatively with the hypervisor (VMM) for better performance.
•Unlike full virtualisation, where the hypervisor tricks the guest OS into thinking it runs on real
hardware, para-virtualisation exposes certain interfaces (hypercalls) so that the guest OS can
directly communicate with the hypervisor.
•Because the guest is aware of the virtual environment, operations such as I/O or memory
management can be optimised.
Key Features of Para-Virtualisation
1. Guest OS Modi cation
•The guest OS kernel is modi ed to replace hardware-sensitive instructions with hypercalls to the
hypervisor.
•Example: Modi ed Linux or BSD kernels.
2. E cient Communication
•Shared memory and circular bu ers are used for device I/O to reduce overhead.
3. Optimised Memory Management
•The guest uses read-only page tables and makes hypercalls for page-table updates instead of
using nested page tables.
4. Performance Gains
•Eliminates the need for complex binary translation.
•Reduces CPU overhead and improves I/O speed.
Example
•Xen Hypervisor is a classic implementation of para-virtualisation.
•It provides clean device abstractions for e cient I/O.
•Uses hypercalls for operations like page-table updates.
14) List out and explain the services provided by the operating system.
Services Provided by the Operating System
An Operating System (OS) provides an environment for program execution and o ers a set of
services to users, programs, and system resources.
These services make programming easier, ensure e cient resource management, and provide
convenience and security.
The main services include:
1. User Interface (UI)
•Provides a way for the user to interact with the computer.
•Types of Interfaces:
fi
ffi
fi
fi
fi
ff
ffi
ffi
ff
fi
•Command Line Interface (CLI): Text-based commands (e.g., Linux shell, Windows CMD).
•Batch Interface: Commands entered in les and executed as jobs.
•Graphical User Interface (GUI): Windows, icons, menus, and mouse for easy interaction.
2. Program Execution
•The OS must:
•Load programs into memory.
•Run programs by assigning CPU resources.
•Provide mechanisms to terminate programs normally or abnormally.
•Ensures proper cleanup of resources after execution.
3. I/O Operations
•Programs often require input/output with les, printers, keyboards, or other devices.
•OS provides system calls to:
•Read/Write data.
•Control devices (e.g., eject a disk, print documents).
•Protects hardware by restricting direct user access to I/O devices.
4. File-System Manipulation
•Programs need to store and retrieve data as les.
•OS provides functions to:
•Create, delete, open, read, write, and close les.
•Search and list le information.
•Manage directories and enforce permissions (read, write, execute).
5. Communications
•Allows processes to exchange data, either:
•Within the same system: Using shared memory or message passing.
•Across a network: Using protocols for inter-computer communication (e.g., sockets).
•Enables client-server applications, distributed computing, and inter-process communication
(IPC).
6. Error Detection
•Continuously monitors the system to detect and handle errors, such as:
•Hardware errors: Memory failure, device malfunction, power loss.
•Software errors: Illegal memory access, arithmetic over ow.
•I/O errors: Disk parity errors, printer out of paper.
•Takes appropriate action:
•Halt the system.
•Terminate faulty processes.
•Report error codes for recovery.
fi
fi
fi
fi
fi
fl