0% found this document useful (0 votes)
99 views26 pages

OS 2023 Solution

The document contains details about a student named Sachin Sharma enrolled in B.Tech 5th semester. It includes 10 questions related to operating system concepts like the definition of an operating system and its objectives, disk scheduling, demand paging, semaphores, processes vs threads, thrashing, page sizes, file accessing methods, seek time and rotational latency, and the role of the dispatcher.

Uploaded by

Sachin Sharma
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)
99 views26 pages

OS 2023 Solution

The document contains details about a student named Sachin Sharma enrolled in B.Tech 5th semester. It includes 10 questions related to operating system concepts like the definition of an operating system and its objectives, disk scheduling, demand paging, semaphores, processes vs threads, thrashing, page sizes, file accessing methods, seek time and rotational latency, and the role of the dispatcher.

Uploaded by

Sachin Sharma
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/ 26

NAME – SACHIN SHARMA

CLASS – B.TECH 5TH SEM’


SECTION C
ROLL NO – 21EJCCS195
PAPER 2023

Q.1 **Define operating system. List the objectives of the operating


system.**
- **Operating System Definition:** An operating system (OS) is a
software component that acts as an intermediary between computer
hardware and the computer user. It provides a user interface and
manages computer hardware and software resources.

- **Objectives of Operating System:**


1. **Processor Management:** Efficiently allocate CPU resources
among multiple processes.
2. **Memory Management:** Manage system memory to ensure
efficient and secure use of available RAM.
3. **File System Management:** Organize and control file storage and
retrieval.
4. **Device Management:** Handle input and output devices to
facilitate communication between the computer and its peripherals.
5. **Security and Protection:** Ensure the security and integrity of
data and resources through access control mechanisms.
6. **User Interface:** Provide a user-friendly interface for interaction
between the user and the computer.
7. **Job Scheduling:** Schedule tasks and processes for optimal
resource utilization.
8. **Error Detection and Handling:** Detect and manage system
errors to maintain system stability.

Q.2 **Why is Disk Scheduling important?**


Disk scheduling is crucial for optimizing the performance of a computer
system. It ensures efficient utilization of disk resources and minimizes
the time it takes to access data stored on disk drives. Disk scheduling
algorithms aim to reduce disk seek time and rotational latency, thereby
improving overall system responsiveness.
Q.3 **What is Demand Paging?**
Demand Paging is a memory management scheme in which pages are
brought into the main memory only when they are demanded by the
executing program. In a demand-paged system, a program's execution
does not require the entire program to be loaded into memory at once.
Instead, only the specific pages needed for the current execution are
loaded, reducing the initial loading time and conserving memory
resources.

Q.4 **What are the disadvantages of Semaphore?**


Disadvantages of Semaphores include:
- **Complexity:** Semaphore-based synchronization can lead to
complex and error-prone code.
- **Deadlocks:** Improper use of semaphores may result in deadlock
situations.
- **Priority Inversion:** Semaphores may not handle priority inversion
issues effectively.
Q.5 **Differentiate between Process and Thread.**
- **Process:**
- A process is an independent program that runs in its own memory
space.
- It has its own address space, file descriptors, and system resources.
- Processes communicate through inter-process communication
mechanisms.
- More overhead in terms of resources and communication.

- **Thread:**
- A thread is a lightweight unit of a process that shares the same
resources.
- Threads within a process share the same address space and file
descriptors.
- Threads can communicate more easily, as they share data and
resources directly.
- Less overhead compared to processes.
Q.6 **Define Thrashing. What are the reasons for thrashing?**
**Thrashing** occurs in a computer system when the CPU spends
more time swapping pages between main memory and secondary
storage than actually executing processes. It is usually caused by a
shortage of available memory. Reasons for thrashing include:
- **Insufficient Memory:** When the demand for memory exceeds the
available physical memory.
- **Poor Page Replacement Policies:** Inefficient page replacement
algorithms can contribute to thrashing.
- **High Degree of Multiprogramming:** Running too many processes
simultaneously can lead to increased demand for memory.

Q.7 **Why are the page sizes always in powers of two?**


Page sizes are often chosen to be powers of two for several practical
reasons:
- **Simplifies Address Translation:** Binary systems easily convert
powers of two into binary form, simplifying address translation.
- **Memory Organization:** Hardware components, such as memory
caches, often have sizes that are powers of two, aligning well with page
sizes.
- **Efficient Address Calculation:** Powers of two simplify the
calculation of addresses, making it more efficient for the computer
hardware.

Q.8 **What are the various file accessing methods? Define the term
seek time and rotational latency.**
- **File Accessing Methods:**
- **Sequential Access:** Accessing data in a sequential order.
- **Direct Access (Random Access):** Directly accessing any block of
data using an index or key.

- **Seek Time:** The time taken by the disk's read/write head to move
to the specified track.

- **Rotational Latency:** The time it takes for the desired disk sector
to rotate under the disk's read/write head.
Q 9 Define the term seek time and rotational latency.
**Seek Time:**
Seek time is the time it takes for the read/write head of a disk to
position itself over the appropriate track where data is to be read from
or written to. It includes the time required for the disk arm to move the
read/write head to the desired track. Seek time is a critical factor in
overall disk access time, and minimizing it contributes to improving the
performance of disk I/O operations.

**Rotational Latency:**
Rotational latency, also known as rotational delay, is the time it takes
for the desired disk sector to rotate under the disk's read/write head.
Once the read/write head is positioned over the correct track, the disk
must rotate until the desired sector is directly under the head before
data can be read from or written to the disk. Rotational latency is
influenced by the rotational speed of the disk (measured in revolutions
per minute, RPM) and is a significant component of the total disk access
time. Minimizing rotational latency contributes to faster disk I/O
operations.
Q.10 **What is the role of dispatcher?**
The **dispatcher** is a component of the operating system that
controls the switching of the CPU from one process to another. Its
primary role is to manage the execution of processes by making
decisions on process scheduling and context switching. The dispatcher
is responsible for loading the saved context of a process that is ready to
execute and saving the context of the currently running process. It plays
a crucial role in the efficient utilization of the CPU and ensures fair and
timely execution of processes.

PART B
**Q.1 Explain different operations performed by the operating
system.**
The operating system performs various operations to manage
computer resources and provide a user-friendly environment. These
operations include:
1. **Process Management:** Creation, scheduling, and termination of
processes.
2. **Memory Management:** Allocation and deallocation of memory
resources.
3. **File System Management:** Organization, storage, retrieval, and
protection of files and directories.
4. **Device Management:** Managing input and output devices.
5. **Security and Protection:** Ensuring data and resource security
through access control.
6. **User Interface:** Providing a user-friendly interface for
interaction.
7. **Networking:** Managing communication between computers in a
network.
8. **Error Handling:** Detecting and handling errors for system
stability.
9. **Job Scheduling:** Efficiently scheduling tasks for optimal resource
utilization.
**Q.2 Define process. How many different states a process has? Explain
when a process changes the state using a proper diagram.**
- **Process Definition:** A process is an independent program in
execution, with its own memory space and resources.

- **Process States:**
1. **New:** The process is being created.
2. **Ready:** The process is ready to execute but waiting for the CPU.
3. **Running:** The process is actively executing.
4. **Blocked (or Waiting):** The process is waiting for an event to
proceed.
5. **Terminated:** The process has finished execution.

- **State Transition Diagram:**


![Process State Transition
Diagram](https://i.imgur.com/wMAsS14.png)
**Q.3 Explain Reader-writer problem and discuss the solution with a
proper diagram.**
The **Reader-Writer problem** involves managing access to a shared
resource (e.g., a file or database) by multiple readers and writers
concurrently. The problem is to ensure that multiple readers can access
the resource simultaneously, but only one writer can access it at a time.

**Solution with Diagram:**


![Reader-Writer Problem Solution](https://i.imgur.com/0Y8Ln0F.png)
- **Readers Preference:** Allow multiple readers simultaneously
unless a writer is present.
- **Writers Preference:** Give priority to a waiting writer over new
readers.
**Q.4 Write the differences among short term, medium term, and long
term scheduling.**
- **Short-term Scheduling (CPU Scheduling):**
- Decides which process to execute next and allocates CPU.
- Timeframe: Milliseconds.
- Goal: Optimize CPU utilization and response time.

- **Medium-term Scheduling:**
- Swaps processes in and out of main memory.
- Timeframe: Seconds to Minutes.
- Goal: Manage the degree of multiprogramming to optimize system
performance.

- **Long-term Scheduling (Job Scheduling):**


- Determines which processes to admit to the system from the job
pool.
- Timeframe: Minutes to Hours.
- Goal: Optimize system throughput and resource utilization.
**Q.5 What is deadlock? What are the necessary conditions for a
deadlock to occur? Explain each condition briefly?**
**Deadlock** is a situation where two or more processes are unable
to proceed because each is waiting for the other to release a resource.

**Necessary Conditions for Deadlock:**


1. **Mutual Exclusion:** At least one resource must be held in a non-
sharable mode.
2. **Hold and Wait:** A process must be holding at least one resource
and waiting to acquire additional resources.
3. **No Preemption:** Resources cannot be preempted from a
process; they must be released voluntarily.
4. **Circular Wait:** A set of processes must exist, where each process
is waiting for a resource held by another process in a circular chain.
**Q.6 Explain why the "Principle of Locality" is crucial to the use of
virtual memory. What is accomplished by page buffering?**
The **Principle of Locality** states that programs tend to access a
small portion of their address space at any given time. This principle is
crucial to virtual memory because it allows for efficient use of limited
physical memory.

**Page Buffering:**
- Page buffering involves keeping a certain number of pages in main
memory even if they are not immediately needed.
- Accomplishments:
- **Improves Response Time:** Frequently accessed pages are
already in memory, reducing the need for frequent page faults.
- **Utilizes Locality:** Takes advantage of the Principle of Locality by
keeping relevant pages in memory.
**Q.7 Explain the architecture of the Linux operating system with a
proper diagram.**
For a detailed explanation of the Linux operating system architecture
with a diagram, please refer to official Linux documentation or specific
resources, as it involves multiple components and layers that are
beyond the scope of a text-based response. You can find detailed
information in Linux system architecture documentation or books on
Linux internals.

**DADT:** It seems that "DADT" is not specified in the context


provided. If you have a specific question or term related to operating
systems or any other field, please provide more details for a more
accurate response.
PART C

ANS 1
Consider the following set of process to be executed, with the arrival time
and CPU burst time given in milliseconds. Calculate average waiting time
and turn-around time using given scheduling algorithm. Draw Gantt chart
for each type.

To calculate the average waiting time and turn-around time for each
scheduling algorithm and draw Gantt charts, we'll go through each
algorithm one by one.

**Process Data:**
```
Process Arrival Time CPU Burst Time
P1 0 5
P2 1 3
P3 2 3
P4 3 1
```
### (i) FCFS (First-Come-First-Serve):
**Gantt Chart:**
```
| P1 | P2 | P3 | P4 |
0 5 8 11 12
```
**Waiting Time:**
- P1: 0 ms
- P2: 5 ms
- P3: 8 ms
- P4: 11 ms

**Turn-Around Time:**
- P1: 5 ms
- P2: 8 ms
- P3: 11 ms
- P4: 12 ms
**Average Waiting Time:** (0 + 5 + 8 + 11) / 4 = 6 ms
**Average Turn-Around Time:** (5 + 8 + 11 + 12) / 4 = 9 ms

### (ii) SJF (Shortest Job First):


**Gantt Chart:**
```
| P4 | P2 | P3 | P1 |
3 4 7 10 15
```
**Waiting Time:**
- P1: 10 ms
- P2: 1 ms
- P3: 4 ms
- P4: 0 ms

**Turn-Around Time:**
- P1: 15 ms
- P2: 4 ms
- P3: 7 ms
- P4: 1 ms

**Average Waiting Time:** (10 + 1 + 4 + 0) / 4 = 3.75 ms


**Average Turn-Around Time:** (15 + 4 + 7 + 1) / 4 = 6.75 ms

### (iii) Round Robin (Quantum = 2):


**Gantt Chart:**
```
| P1 | P2 | P3 | P4 | P1 | P2 | P3 | P1 |
0 2 4 6 8 10 12 14 16
```
**Waiting Time:**
- P1: 6 ms
- P2: 2 ms
- P3: 4 ms
- P4: 3 ms

**Turn-Around Time:**
- P1: 11 ms
- P2: 5 ms
- P3: 7 ms
- P4: 4 ms

**Average Waiting Time:** (6 + 2 + 4 + 3) / 4 = 3.75 ms


**Average Turn-Around Time:** (11 + 5 + 7 + 4) / 4 = 6.75 ms

Please note that waiting time and turn-around time are calculated
using the formulas:
- Waiting Time = Turn-Around Time - Burst Time
- Turn-Around Time = Completion Time - Arrival Time

--------------------------------------------------------------------------
ANS 2

**(i) Internal Vs External Fragmentation:**


- **Internal Fragmentation:** Occurs when memory allocated to a
process is larger than required, and the extra memory is unused.
- **External Fragmentation:** Occurs when free memory is scattered
throughout the system, making it challenging to allocate contiguous
memory blocks.

**(ii) Paging and Segmentation:**


- **Paging:** Divides physical memory and processes into fixed-size
blocks (pages). Simplifies memory management but may lead to
internal fragmentation.
- **Segmentation:** Divides the logical address space into variable-
sized segments. Provides flexibility but can result in external
fragmentation.

**(iii) Process Control Block (PCB):**


- **Definition:** A data structure containing information about a
process in the operating system.
- **Contents:** Process state, program counter, CPU registers, memory
management information, scheduling information, etc.
- **Purpose:** Facilitates process management and context switching.

**(iv) Absolute and Relative Path Name of a File:**


- **Absolute Path Name:** Specifies the full path from the root
directory to the file. Starts with the root directory (/ on Unix/Linux
systems).
- **Relative Path Name:** Specifies the path to the file relative to the
current working directory.

----------------------------------------------------

**Q.3 Disk Scheduling:**


- **Disk Details:** 1000 cylinders numbered 0 to 999. Latest request at
track 345, head moving towards track 0.
- **Disk Queue (FIFO):** 123, 874, 692, 475, 105, 376.

**FIFO Scheduling:**
- Tracks: 345 → 123 → 874 → 692 → 475 → 105 → 376.
- Total Tracks Moved: 1946.
**SSTF Scheduling:**
- Tracks: 345 → 376 → 475 → 692 → 874 → 105 → 123.
- Total Tracks Moved: 680.

**SCAN Scheduling:**
- Tracks: 345 → 105 → 123 → 376 → 475 → 692 → 874.
- Total Tracks Moved: 1151.
**Q.4 Page Faults:**
- **Page Reference String:** 1, 2, 3, 4, 5, 3, 4, 1, 6, 7, 8, 7, 8, 9, 7, 8, 9,
5, 4, 5, 4, 2.
- **Frames:** 4.

**FIFO Page Replacement:**


- Page Faults: 15.

**Optimal Page Replacement:**


- Page Faults: 8.

Note: Optimal page replacement algorithm provides the minimum


possible page faults by replacing the page that will not be used for the
longest time.
✓Q.5 Write in short for the following –
(i) Virtual machine
(ii) Device Drivers
(iii) Time OS
(iv) Mutual exclusion

**Short Notes:**

**(i) Virtual Machine:**


- **Definition:** A virtual machine is a software emulation of a physical
computer. It allows multiple operating systems to run on a single
physical machine concurrently.
- **Purpose:** Enables efficient resource utilization, isolation, and
running diverse software environments on a host system.

**(ii) Device Drivers:**


- **Definition:** Device drivers are software components that facilitate
communication between the operating system and hardware devices.
They enable the OS to control and interact with specific hardware
components.
- **Function:** Translate generic OS commands into device-specific
instructions, ensuring proper functioning of hardware.

**(iii) Real-Time Operating System (RTOS):**


- **Definition:** A real-time operating system is designed for
applications where timely and predictable responses to external events
are critical. It ensures tasks are executed within specified time
constraints.
- **Application:** Used in embedded systems, control systems, and
applications requiring precise timing.

**(iv) Mutual Exclusion:**


- **Definition:** Mutual exclusion is a synchronization mechanism that
ensures only one process at a time can access a shared resource or
critical section. It prevents data corruption and race conditions in
concurrent programming.
- **Implementation:** Achieved through locks, semaphores, or other
synchronization techniques to coordinate access to shared resources
among multiple processes or threads.

You might also like