Questions_os
Questions_os
Answer:
An Operating System (OS) is system software that manages computer hardware and software
resources and provides services for computer programs.
Functions of an OS:
Answer:
System Calls provide an interface between a program and the OS. Programs use system calls to
request OS services.
1. Process Control:
Example: fork() , exec() , exit()
Used for creating and terminating processes.
2. File Management:
Example: open() , read() , write() , close()
Handles file operations.
3. Device Management:
Example: ioctl() , read() , write()
Interacts with hardware devices.
4. Information Maintenance:
Example: getpid() , getuid()
Retrieves system information.
5. Communication:
Example: send() , recv() , socket()
Used for inter-process communication.
Answer:
1. Monolithic Structure:
All OS functionalities exist in a single large kernel.
Example: MS-DOS, Linux Kernel
2. Layered Structure:
OS is divided into layers, where each layer performs specific functions.
Example: THE OS (Technische Hogeschool Eindhoven OS)
3. Microkernel Structure:
Only essential functions (like process and memory management) are in the kernel; other
services run in user mode.
Example: Minix, QNX
4. Modular Structure:
Uses dynamically loadable kernel modules.
Example: Modern Linux Kernels
5. Hybrid Structure:
Combination of monolithic and microkernel structures.
Example: Windows, macOS
System Programs are software utilities that provide functionalities beyond an OS but support its
operation.
Answer:
OS Design Goals:
Implementation Considerations:
Answer:
A process is a program in execution. It includes the program code, stack, heap, and data sections.
Process States:
The Process Control Block (PCB) stores process details like process ID, program counter,
registers, scheduling information, and memory limits.
2. What are the different types of process scheduling? Explain various CPU
scheduling algorithms.
Answer:
Answer:
IPC Mechanisms:
1. Shared Memory:
Processes share a memory space to exchange information.
Fast but requires synchronization mechanisms like semaphores.
2. Message Passing:
Processes send and receive messages using OS services.
Slower but more secure than shared memory.
3. Pipes:
Unidirectional communication channel between processes.
4. Sockets:
Used for network communication between processes on different machines.
5. Signals:
Used to notify processes about events like termination or errors.
4. Explain the concepts of threads and processes. What are the advantages
of multithreading?
Answer:
A process is an independent execution unit with its own memory space, while a thread is a
lightweight process that shares memory with other threads in the same process.
Types of Threads:
Advantages of Multithreading:
Answer:
A deadlock occurs when two or more processes wait indefinitely for resources held by each
other.
Deadlock Detection:
The OS checks for cycles in the resource allocation graph.
Deadlock Avoidance:
Answer:
Memory management is responsible for efficiently allocating and deallocating memory to
processes. There are several strategies used:
1. Swapping:
A process is temporarily moved from main memory to disk and brought back when
needed.
Reduces CPU idle time but increases disk I/O overhead.
2. Contiguous Memory Allocation:
Each process gets a single continuous block of memory.
Types:
Fixed Partitioning: Divides memory into fixed-size blocks.
Dynamic Partitioning: Allocates memory dynamically based on process size.
3. Paging:
Divides memory into fixed-sized pages, and processes into equal-sized page frames.
The OS uses a page table to map logical addresses to physical addresses.
4. Segmentation:
Divides memory into variable-sized segments based on program structures (code, data,
stack).
Provides better program organization but leads to external fragmentation.
5. Virtual Memory Management:
Uses demand paging to execute programs larger than RAM by keeping only needed
pages in memory.
Uses page replacement algorithms to remove old pages when memory is full.
2. Explain paging and how it works. How does it solve the problem of
external fragmentation?
Answer:
Paging is a non-contiguous memory allocation technique that divides memory into fixed-size
pages.
Advantages:
Eliminates external fragmentation since any free page frame can be allocated.
Simplifies memory allocation because all pages are of fixed size.
Example:
Answer:
Segmentation divides a process into variable-sized logical units called segments (e.g., code,
data, stack).
Example:
Consider a process with:
Each segment gets a separate segment number and an offset within that segment.
Advantages:
Disadvantages:
Answer:
Virtual memory allows programs to execute without loading the entire process into RAM. It
extends memory by using disk space as swap space.
Demand Paging:
A page is loaded into memory only when needed, rather than loading the whole program.
If a page is not in memory, a page fault occurs, and the OS loads it from disk.
Advantages:
Answer:
When memory is full, a page replacement algorithm decides which page to remove.
1. FIFO (First-In-First-Out):
Oldest page is removed first.
Simple but may remove frequently used pages.
2. Optimal (OPT):
Replaces the page that will not be used for the longest time.
Not practical since future requests are unknown.
3. LRU (Least Recently Used):
Replaces the page that was used the longest time ago.
More efficient than FIFO but needs extra tracking.
Thrashing:
Answer:
A file system is responsible for organizing, storing, and managing data on a storage device. Its
components include:
1. Files:
The basic unit of storage, containing user or system data.
2. Directories:
Helps in organizing files in a hierarchical structure.
3. File Control Block (FCB):
Stores metadata about a file, such as name, size, location, permissions, and timestamps.
4. Superblock:
Stores details about the entire file system, such as free space, number of files, and
directory structures.
5. Inode Table:
Stores metadata for each file, including its permissions, owner, and block addresses.
6. Disk Blocks:
Physical storage units where file data is stored.
File access methods define how data is read from and written to files. The main types are:
1. Sequential Access:
Data is accessed in a linear order.
Example: Reading a text file line by line.
2. Direct (Random) Access:
Any part of the file can be accessed directly using an index.
Example: Databases where records are accessed randomly.
3. Indexed Access:
Uses an index to locate file data efficiently.
Example: B-trees in file systems for faster lookup.
4. Memory-Mapped Access:
Maps a file into memory for faster read/write operations.
Example: OS paging systems.
Answer:
File system mounting is the process of making a file system accessible to users by attaching it to
a directory.
Process of Mounting:
Types of Mounting:
1. Automatic Mounting: The OS mounts the file system during boot time.
2. Manual Mounting: Users manually mount a file system using commands like mount .
3. Virtual Mounting: Used in cloud-based or network file systems.
Answer:
File Sharing:
Users can share files in multi-user environments.
Types:
i. Single-user file sharing: Files shared between different applications of the same user.
ii. Multi-user file sharing: Files shared between different users.
1. Access Control Lists (ACLs): Specifies read, write, execute permissions for users and groups.
2. Password Protection: Files are accessed using passwords.
3. Encryption: Files are stored in an encrypted format for security.
4. User Groups: Users are divided into groups with specific permissions.
Here,
Answer:
1. I/O Scheduler: Decides the order in which I/O requests are processed.
2. Buffering: Temporarily stores data during input/output operations.
3. Caching: Stores frequently accessed data to improve performance.
4. Device Drivers: Interface between the OS and hardware devices.
5. Interrupt Handlers: Manage interrupts triggered by I/O devices.