Assignment 2 Solution
Assignment 2 Solution
An Operating System (OS) is a collection of software that manages hardware resources and
provides various services to users. It acts as an intermediary between the user and the hardware,
making it easier for users to interact with the computer system. The OS handles tasks such as
memory management, process scheduling, file management, and device management.
Types of Operating Systems:
1. Mainframe Operating Systems:
o Found in large, room-sized computers used in corporate data centers.
o Services include batch processing, transaction processing, and timesharing.
o Examples: OS/390, OS/360.
2. Server Operating Systems:
o Run on servers that serve multiple users over a network.
o Provide services like file sharing, print services, and web services.
o Examples: Solaris, FreeBSD, Linux, Windows Server.
3. Multiprocessor Operating Systems:
o Designed for systems with multiple CPUs.
o Enhance performance by allowing parallel processing.
o Examples: Windows, Linux.
4. Personal Computer Operating Systems:
o Installed on personal computers and laptops.
o Provide support for single users.
o Examples: Windows, macOS, Linux.
5. Handheld Computer Operating Systems:
o Run on small devices like PDAs and smartphones.
o Provide functionalities like telephony, digital photography, and internet access.
o Examples: Symbian OS, Palm OS.
6. Embedded Operating Systems:
o Installed in devices like ATMs, printers, and washing machines.
o Do not allow user-installed software.
o Examples: QNX, VxWorks.
7. Sensor Node Operating Systems:
o Run on tiny sensor nodes used in environmental monitoring.
o Communicate wirelessly with each other and a base station.
o Examples: TinyOS.
8. Real-Time Operating Systems (RTOS):
o Designed for systems with strict timing constraints.
o Two types: Hard real-time (e.g., industrial control systems) and Soft real-time (e.g.,
multimedia systems).
o Examples: e-Cos.
9. Smart Card Operating Systems:
o Run on credit card-sized devices with limited processing power.
o Used in electronic payment systems.
o Examples: Java Card OS.
o Example: For a read system call, the parameters might include the file descriptor,
buffer address, and number of bytes to read.
2. Call to Library Procedure:
o The user program calls a library procedure (e.g., read() in C) that corresponds to the
system call.
o This library procedure is part of the standard library (e.g., libc in Unix).
3. Trap to Kernel Mode:
o The library procedure executes a special instruction (e.g., int 0x80 in x86
architecture) that triggers a software interrupt, causing the CPU to switch from
user mode to kernel mode.
4. System Call Execution in Kernel Mode:
o The OS identifies the system call using a system call number (e.g., read might have
a specific number like 3).
o The OS then executes the corresponding kernel routine to perform the requested
operation (e.g., reading data from a file).
5. Return to User Mode:
o After the system call is executed, the OS returns the result to the user program and
switches back to user mode.
o The library procedure returns the result to the user program.
Example:
#include <unistd.h>
int main() {
char buffer[100];
int count = read(0, buffer, 100); // System call to read from standard input
return 0;
• In this example, the read system call is used to read up to 100 bytes from standard input
(file descriptor 0) into the buffer.
o Disadvantages: Difficult to maintain and debug; a bug in one part can crash the
entire system.
o Example: Traditional Unix systems.
2. Layered Systems:
o The OS is organized into layers, where each layer provides services to the layer
above it and uses services from the layer below.
o Example: Creating, reading, and writing files using system calls like open, read,
and write.
6. Communication:
o The OS facilitates communication between processes, either on the same machine
or across a network.
o Example: Inter-process communication (IPC) mechanisms like pipes, shared
memory, and message queues.
7. Error Detection and Response:
o The OS detects errors in hardware, software, or user programs and takes
appropriate action.
o Example: Handling a division by zero error or a disk read error.
8. Accounting:
o The OS keeps track of resource usage for billing or performance monitoring.
o Example: Logging CPU time used by each process.
9. Protection and Security:
o The OS ensures that resources are accessed only by authorized users and
processes.
o Example: User authentication and file permissions.
4. Find out average waiting time and average turn round time for FCFS,SJF,SRTN, preemptive &
non preemptive priority and round robin scheduling algorithm. Time quantum is 1ms.
6. Process States and Process State Transitions:
Process States:
A process can be in one of the following states during its lifecycle:
1. New:
o The process is being created.
o It has not yet been admitted to the ready queue.
2. Ready:
o The process is waiting to be assigned to the CPU.
o It is in the ready queue and is eligible for execution.
3. Running:
o The process is currently being executed by the CPU.
o Only one process can be in the running state at a time on a single CPU.
4. Blocked/Waiting:
o The process is waiting for some event to occur (e.g., I/O completion, signal).
o It cannot proceed until the event happens.
5. Terminated/Exit:
o The process has finished execution.
o It is removed from the system.
Process State Transitions:
The transitions between these states are as follows:
1. New → Ready:
o The process is admitted to the ready queue and is waiting for CPU time.
2. Ready → Running:
o The scheduler selects the process from the ready queue and assigns it to the CPU.
3. Running → Ready:
o The process is preempted (e.g., due to time quantum expiration in Round Robin
scheduling).
4. Running → Blocked:
o The process requests an I/O operation or waits for an event.
5. Blocked → Ready:
o The event the process was waiting for occurs (e.g., I/O completion).
6. Running → Terminated:
o The process finishes execution and exits.
Diagram:
7. User-Level Threads and Kernel-Level Threads:
Comparison:
Feature User-Level Threads Kernel-Level Threads
સ ૂચના : ખાલી ડિફેન્સ જ લખવો જેને badhu લખવુ હોય તો લખી લ્યો grey કરે લ ુ
User-Level Threads:
• Definition:
o User-level threads are managed entirely by user-level libraries (e.g., POSIX threads
or Pthreads).
o The kernel is unaware of these threads and sees only the process.
• Advantages:
o Portability: User-level threads can run on any OS that supports the thread library.
• Disadvantages:
o Blocking: If one thread blocks (e.g., for I/O), the entire process blocks.
• Definition:
o Kernel-level threads are managed directly by the operating system.
o Each thread is recognized by the kernel and can be scheduled independently.
• Advantages:
• Disadvantages:
• Definition:
o Context switching is the process of saving the state of a currently running process
and loading the state of another process so that it can be executed.
o It involves saving the CPU registers, program counter, and other process-specific
data.
▪ The OS saves the CPU registers, program counter, and other process-
specific data into the Process Control Block (PCB) of the current process.
2. Load the state of the next process:
▪ The OS loads the CPU registers, program counter, and other process-
specific data from the PCB of the next process.
3. Switch to the new process:
• Example:
o The OS saves the state of Process A (e.g., CPU registers, program counter) into its
PCB.