0% found this document useful (0 votes)
67 views11 pages

Assignment 2 Solution

An Operating System (OS) manages hardware resources and provides services to users, acting as an intermediary between them and the hardware. There are various types of OS, including mainframe, server, multiprocessor, personal computer, handheld, embedded, sensor node, real-time, and smart card operating systems. System calls are mechanisms for user programs to request services from the OS, and the document also discusses OS structures, services, process states, and threading models.

Uploaded by

hjdphtus2105
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)
67 views11 pages

Assignment 2 Solution

An Operating System (OS) manages hardware resources and provides services to users, acting as an intermediary between them and the hardware. There are various types of OS, including mainframe, server, multiprocessor, personal computer, handheld, embedded, sensor node, real-time, and smart card operating systems. System calls are mechanisms for user programs to request services from the OS, and the document also discusses OS structures, services, process states, and threading models.

Uploaded by

hjdphtus2105
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/ 11

1. What is OS? Briefly explain types of OS.

Operating System (OS):

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.

2. What is system call? Explain all the steps with example.


System Call:
A system call is a mechanism by which a user program requests a service from the operating
system. It acts as an interface between the user program and the OS, allowing the program to
perform tasks that require privileged access to hardware or system resources.
Steps in System Call Execution:
1. Push Parameters onto Stack:
o The user program pushes the parameters required for the system call onto the
stack.

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.

3. Explain Operating System Structures in detail.


Operating System Structures:
1. Monolithic Systems:
o The entire OS runs as a single program in kernel mode.
o All OS services (e.g., memory management, file system, device drivers) are part of
the kernel.

o Advantages: Simple design, efficient communication between components.

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 Advantages: Modularity, easier debugging, and maintenance.

o Disadvantages: Performance overhead due to multiple layers.


o Example: THE operating system.
3. Microkernel:
o Only the most essential services (e.g., process scheduling, memory management)
run in kernel mode.
o Other services (e.g., file system, device drivers) run as user-mode processes.

o Advantages: High reliability, easier to extend and maintain.

o Disadvantages: Performance overhead due to frequent context switches.


o Examples: MINIX, QNX.
4. Client-Server Model:
o The OS is divided into servers (e.g., file server, memory server) that provide
services and clients that request services.
o Servers and clients communicate via message passing.

o Advantages: Modularity, fault isolation, and scalability.

o Disadvantages: Performance overhead due to message passing.


o Example: Windows NT.
5. Virtual Machines:
o The OS creates virtual machines (VMs) that mimic the underlying hardware.
o Each VM can run its own OS, allowing multiple OSes to run on the same physical
machine.

o Advantages: Isolation, flexibility, and resource sharing.


o Disadvantages: Performance overhead due to virtualization.
o Examples: VMware, VirtualBox.
6. Exokernels:
o The exokernel provides minimal abstraction over the hardware, allowing user
programs to directly manage resources.

o Advantages: High performance, flexibility.

o Disadvantages: Complexity in resource management.


o Example: Exokernel research projects.

4. Explain Operating System Services in detail.


Operating System Services:
1. Program Development:
o The OS provides tools like editors and debuggers to help programmers develop
software.
o Example: Text editors (e.g., Vim, Emacs) and debuggers (e.g., GDB).
2. Program Execution:
o The OS loads programs into memory, initializes resources, and executes them.
o Example: Running a C program by loading it into RAM and executing it.
3. Access to I/O Devices:
o The OS manages I/O devices and provides a uniform interface for accessing them.
o Example: Reading from a file or printing to a printer.
4. Memory Management:
o The OS manages the allocation and deallocation of memory for processes.
o Example: Allocating memory for a new process and freeing it when the process
terminates.
5. Controlled Access to Files:
o The OS provides a file system for organizing and accessing files.

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

Management User-level library Kernel

Speed Faster Slower


Blocking Entire process blocks Only the blocking thread

Parallelism No true parallelism True parallelism


Flexibility High Low

સ ૂચના : ખાલી ડિફેન્સ જ લખવો જેને 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 Fast creation and management: No kernel intervention is required.

o Flexibility: Thread scheduling can be customized by the application.

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.

o No true parallelism: Cannot take advantage of multiple CPUs.


Kernel-Level Threads:

• 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:

o True parallelism: Can run on multiple CPUs simultaneously.

o No blocking: If one thread blocks, other threads can continue execution.

• Disadvantages:

o Slower creation and management: Requires kernel intervention.

o Less flexibility: Thread scheduling is controlled by the OS.


8. Context Switching with Example:
Context Switching:

• 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.

• Steps in Context Switching:


1. Save the state of the current process:

▪ 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:

▪ The CPU starts executing the new process.

• Example:

o Suppose Process A is running, and the scheduler decides to switch to Process B.

o The OS saves the state of Process A (e.g., CPU registers, program counter) into its
PCB.

o The OS then loads the state of Process B from its PCB.

o The CPU starts executing Process B.


Diagram:

Process A (Running) → Save State → Load State → Process B (Running)

You might also like