0% found this document useful (0 votes)
12 views14 pages

Understanding Operating Systems and Their Functions

The document provides a comprehensive overview of Operating Systems (OS), detailing their definitions, roles, types, structures, system calls, process states, Process Control Blocks (PCBs), CPU scheduling criteria, threads, and multithreading models. It explains how an OS acts as an interface between users and hardware, manages processes, and ensures efficient resource allocation. Additionally, it discusses the lifecycle of threads and common multithreading problems such as race conditions and deadlocks.

Uploaded by

tyash6332
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)
12 views14 pages

Understanding Operating Systems and Their Functions

The document provides a comprehensive overview of Operating Systems (OS), detailing their definitions, roles, types, structures, system calls, process states, Process Control Blocks (PCBs), CPU scheduling criteria, threads, and multithreading models. It explains how an OS acts as an interface between users and hardware, manages processes, and ensures efficient resource allocation. Additionally, it discusses the lifecycle of threads and common multithreading problems such as race conditions and deadlocks.

Uploaded by

tyash6332
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

Questions with answers

Q1. Define an OS and explain its role as an interface between the hardware and the
user
Definition:
●​ An Operating System (OS) is a system software that manages hardware and
software resources of a computer.
●​ It acts as a bridge (interface) between:
o​ User → Application Programs → Hardware.
Roles as an Interface:
1.​ User Interaction
o​ Provides Command-Line Interface (CLI) (MS-DOS, UNIX shell).
o​ Provides Graphical User Interface (GUI) (Windows, macOS, Android).
2.​ Program Execution
o​ Loads programs into memory.
o​ Allocates CPU & other resources.
o​ Provides error handling during execution.
3.​ Resource Management
o​ Allocates CPU, memory, I/O devices fairly.
o​ Ensures no process monopolizes resources.
4.​ File Management
o​ Manages files: create, read, write, delete.
o​ Provides security (permissions).
5.​ I/O Device Management
o​ Controls devices like keyboard, mouse, printers, etc.
o​ Provides device drivers to hide hardware complexity.
6.​ Security and Protection
o​ Prevents unauthorized access.
o​ Provides password protection, firewalls, access rights.

1
Q2. Explain the different types of OS
1.​ Batch Operating System
o​ Jobs are grouped (batched) and executed without user interaction.
o​ Input given on punched cards/tapes.
o​ Example: Early IBM mainframes.
2.​ Time-Sharing Operating System
o​ CPU time is divided into time slices.
o​ Multiple users can use the system at the same time.
o​ Example: UNIX.
3.​ Distributed Operating System
o​ Manages multiple computers as one system.
o​ Provides resource sharing, fault tolerance.
o​ Example: LOCUS.
4.​ Real-Time Operating System (RTOS)
o​ Provides immediate response to external events.
o​ Two types:
▪​ Hard RTOS: Deadlines must be met (aircraft control).
▪​ Soft RTOS: Deadlines can be missed occasionally (multimedia).
o​ Example: VxWorks, QNX.
5.​ Network Operating System (NOS)
o​ Runs on servers to manage network resources.
o​ Provides file sharing, printer access, communication.
o​ Example: Novell NetWare, Windows Server.
6.​ Mobile Operating System
o​ Designed for smartphones & tablets.
o​ Provides touch interface, app store, sensors handling.

2
o​ Example: Android, iOS.

Q3. Explain OS System Structure


1.​ Monolithic Structure
o​ OS is a single large program.
o​ All services (CPU scheduling, memory, I/O) are inside one kernel.
o​ Pros: Simple, fast.
o​ Cons: Hard to modify/debug.
o​ Example: MS-DOS.
2.​ Layered Structure
o​ OS divided into layers (bottom = hardware, top = user interface).
o​ Each layer uses services of the lower one.
o​ Pros: Easier debugging.
o​ Cons: Less efficient.
3.​ Microkernel Structure
o​ Kernel contains minimal services: scheduling, IPC, memory mgmt.
o​ Other services (drivers, file systems) run in user mode.
o​ Pros: Modular, secure, stable.
o​ Cons: Slower (context switching).
o​ Example: Mac OS
4.​ Modules (Modular Structure)
o​ Kernel has loadable modules (plug-in like).
o​ Flexible and efficient.
o​ Example: Modern Linux.
5.​ Virtual Machines
o​ Hardware is shared between multiple OS instances.
o​ Example: VMware, VirtualBox.

3
Q4. Explain types of System Calls
System calls = functions that programs use to request services from OS.
Types:
1.​ Process Control
o​ Create, terminate, end, abort, load programs.
o​ Example: fork(), exit(), wait().
2.​ File Management
o​ Operations on files.
o​ Example: open(), read(), write(), close(), delete().
3.​ Device Management
o​ Request, release, attach, or detach devices.
o​ Example: ioctl(), read(), write().
4.​ Information Maintenance
o​ Get/set system information (time, date, OS details).
o​ Example: getpid(), getuid().
5.​ Communication
o​ For Inter-Process Communication (IPC).
o​ Example: pipe(), send(), recv(), socket().

Chapter 2

Q1. What are the Process States in an OS?


A process is a program in execution.
●​ When a program is stored on disk → it’s a passive entity.
●​ When loaded into memory and running → it becomes an active process.
●​ The OS keeps track of process states using a Process Control Block (PCB).

4
1. New (Created State)
●​ A process is created when a program is submitted for execution.
●​ It has not yet been admitted into main memory (RAM).
●​ Resources (like PCB, memory allocation) are set up.
●​ Example: You double-click on MS Word → OS creates a new process.

2. Ready State
●​ The process is loaded into main memory and is ready to execute.
●​ It is waiting for the CPU to be assigned.
●​ Multiple processes can be in the ready queue.
●​ Example: You open several apps; they wait in ready queue until CPU schedules
them.

3. Running State
●​ The process is currently being executed by the CPU.
●​ Only one process per CPU can be in Running state at a time.
●​ If the system has multiple CPUs/cores → multiple processes may be in running
state simultaneously.
●​ Example: While typing in Word, CPU executes Word’s process.

4. Waiting (or Blocked) State


●​ Process is not using the CPU but is waiting for some event.
●​ Events include I/O completion, resource availability, or signal from another
process.
●​ Example: A print request waits for printer → process goes into waiting state.

5. Terminated (or Exit) State


●​ Process has finished execution or is killed by OS/user.
●​ All resources (memory, I/O) are released.
●​ The process’s PCB is deleted from the process table.

5
●​ Example: You close Word → the process enters terminated state.

Diagram posted on group

Q2. Explain Process Control Block (PCB)


●​ The Process Control Block (PCB) is a data structure maintained by the
Operating System for each process.
●​ It contains all the essential information about the process so that the OS can
manage it properly.
●​ It is sometimes called the process descriptor.
.

Contents of PCB (in detail):

1. Process ID (PID)
●​ A unique identifier assigned by the OS to each process.
●​ Used to differentiate between processes.
●​ Example: In Linux, when you run ps -aux, you see PIDs of all processes.

2. Process State
●​ Shows the current state of the process.
●​ Possible states:
o​ New
o​ Ready
o​ Running
o​ Waiting (Blocked)
o​ Terminated
●​ The OS updates the state in PCB whenever the process changes state.

6
3. Program Counter (PC)
●​ Holds the address of the next instruction that the process will execute.
●​ If the process is interrupted (e.g., context switch), the OS saves the current PC in
PCB.
●​ When the process resumes, execution continues from this saved PC.

4. CPU Registers
●​ Includes all register values that the process was using:
o​ General-purpose registers (AX, BX, etc. in x86).
o​ Stack pointer, base pointer.
o​ Status registers, condition codes (flags).
●​ During a context switch, all these register values are saved in PCB and restored
when the process runs again.

5. Memory Management Information


●​ Contains details about memory allocated to the process.
●​ Includes:
o​ Base & Limit registers (start and size of memory).
o​ Page tables (in paging systems).
o​ Segment tables (in segmentation).
●​ Helps OS in address translation and preventing one process from accessing
another’s memory.

6. Accounting Information
●​ Contains information related to process execution history and priority, such as:
o​ CPU usage time.
o​ Time limits.
o​ Job priority.
o​ Process scheduling info (like time quantum in Round Robin).

7
●​ Helps the OS in fair scheduling and maintaining logs.

7. I/O Status Information


●​ Contains list of I/O devices and files allocated to the process.
●​ Includes:
o​ List of open files.
o​ Pending I/O requests.
o​ Devices being used (e.g., printer, disk).
●​ Ensures that I/O resources are properly assigned and released after process
termination.

Importance of PCB
1.​ Context Switching:
o​ PCB stores all necessary information when CPU switches from one
process to another.
o​ Without PCB, process execution cannot resume correctly.
2.​ Process Management:
o​ OS uses PCB to manage scheduling, memory, and resources.
3.​ Security & Protection:
o​ Prevents processes from interfering with each other.

Q3. Explain CPU Scheduling Criteria


When multiple processes are in the ready queue, the Operating System must decide

👉
which process gets CPU first.​
To evaluate and compare scheduling algorithms, we use certain criteria (metrics).

1. CPU Utilization
●​ Definition: It measures how busy the CPU is.
●​ Goal: Keep the CPU as active as possible (ideally 100%).

8
●​ In real systems:
o​ Range = 40% (low-load system) to 90% (high-load system).
●​ Example: If CPU is idle too often, utilization is low → poor scheduling.

2. Throughput
●​ Definition: The number of processes completed per unit time.
●​ Formula:

Throughput=Number of processes completedTotal time taken\text{Throughput} =


\frac{\text{Number of processes completed}}{\text{Total time
taken}}Throughput=Total time takenNumber of processes completed​

●​ High throughput = better performance.


●​ Example: If 10 processes finish in 5 seconds → throughput = 2 processes/sec.

3. Turnaround Time (TAT)


●​ Definition: Total time taken from process submission to process completion.
●​ Formula:

TAT=Completion Time−Arrival TimeTAT = \text{Completion Time} -


\text{Arrival Time}TAT=Completion Time−Arrival Time

●​ Includes waiting time + execution time + I/O time.


●​ Example: Process arrives at 0 ms, finishes at 20 ms → TAT = 20 ms.

4. Waiting Time (WT)


●​ Definition: Total time a process spends in the ready queue waiting for CPU.
●​ Formula:

WT=TAT−BurstTimeWT = TAT - Burst TimeWT=TAT−BurstTime

●​ Example: Process has burst time 5 ms, turnaround time 12 ms → waiting time = 7
ms.
●​ Good scheduling = minimize average waiting time.

9
5. Response Time (RT)
●​ Definition: Time from submission of a request → first response produced (not
completion).
●​ Important in interactive systems (like OS with GUIs, databases).
●​ Example: If you type in Google and wait 3 sec for search to start → RT = 3 sec.
●​ Goal: Minimize response time to make system feel fast and interactive.

6. Fairness
●​ Definition: Every process should get a fair share of CPU.
●​ Prevents starvation (a process waiting indefinitely).
●​ Example: In Priority Scheduling, low-priority processes may starve → fairness
needed.
●​ Goal: Ensure all processes progress.

Criterion Goal / Importance

CPU Utilization Keep CPU busy (maximize usage).

Throughput Maximize number of completed processes.

Turnaround Time Minimize total completion time.

Waiting Time Minimize time spent waiting.

Response Time Minimize delay before first response.

Fairness Avoid starvation, ensure equal opportunity

Q4. Explain Threads in detail along with its types


Thread:

10
●​ A lightweight process inside a process.
●​ Each thread has its own Program Counter, Registers, Stack, but shares code,
data, and files with other threads of the process.
Advantages:
1.​ Faster context switching.
2.​ Efficient CPU utilization.
3.​ Communication between threads is easy.
4.​ Useful in multiprocessors (parallel execution).
Types of Threads:
1.​ User-Level Threads (ULTs)
o​ Managed by user libraries, not kernel.
o​ Faster creation/switching.
o​ Cons: One thread blocking = all threads blocked.
2.​ Kernel-Level Threads (KLTs)
o​ Managed by OS kernel.
o​ Each thread scheduled by OS.
o​ Cons: Slower, but more powerful.
3.​ Hybrid Threads
o​ Combines both user and kernel level advantages.
o​ Example: Solaris.
[Link] Multi threading Models
Multithreading means a process can have multiple threads running at the same time.​
different multithreading models exist.
Types of Multithreading Models

(a) Many-to-One Model


●​ Many user threads are connected to one kernel thread.
●​ Thread switching is very fast (done in user space).
●​ Only one thread can run at a time → no true parallelism.

11
●​ If one thread makes a system call (like file read), the whole process is blocked.
●​ Example: Early Java "green threads".

(b) One-to-One Model


●​ Each user thread maps to exactly one kernel thread.
●​ Multiple threads can run in parallel on multiprocessor systems.
●​ But creating many threads = creating many kernel threads → more overhead.
●​ Example: Windows, Linux.

(c) Many-to-Many Model


●​ Many user threads can be mapped to many kernel threads.
●​ OS chooses how to schedule kernel threads on CPU.
●​ Best balance between efficiency and parallelism.
●​ Example: Solaris, Windows with Thread Fiber package.

●​ Many-to-One: Simple, but no parallel execution.


●​ One-to-One: True parallelism, but costly.
●​ Many-to-Many: Balanced, scalable, but more complex.

👉
6. Thread Lifecycle (with Diagram)
Just like a process, a thread also has different states during execution.

Thread States
1.​ New (Created):
o​ Thread is created but not started yet.
o​ Example: After Thread t = new Thread() in Java, but before [Link]().
2.​ Runnable (Ready):
o​ Thread is ready and waiting for CPU time.
o​ Example: Thread has called start(), but CPU has not picked it yet.

12
3.​ Running:
o​ Thread is actually running on CPU.
o​ Only one thread per CPU core can be in this state at a time.
4.​ Waiting/Blocked:
o​ Thread is paused because it is waiting for some event (like I/O or lock).
o​ Example: Thread waits for file input.
5.​ Terminated (Dead):
o​ Thread has finished its work.
o​ Cannot be restarted.

Thread Lifecycle Diagram(on WhatsApp Group)

7. Common Problems in Multithreading


Multithreading improves speed but creates synchronization issues.
1. Race Condition
●​ When two or more threads access shared data at the same time → final result
may be wrong.
●​ Example: Two ATM threads updating same bank balance at the same time.

2. Deadlock
●​ Two or more threads are waiting for resources, but none can continue because
each one holds something the other needs.
●​ Example: Thread A holds printer, waiting for scanner; Thread B holds scanner,
waiting for printer.

3. Starvation
●​ A thread keeps waiting because other threads always get preference.
●​ Example: In priority scheduling, low-priority threads may never get CPU.

13
4. Livelock
●​ Threads are not blocked, but keep changing their states and making no progress.
●​ Example: Two people trying to pass each other in a corridor → both keep moving
aside but never pass.

[Link] Average Waiting time using Round Robin for a given set of processes and
Quantum Time

●​ (Ans on WhatsApp Group)

Chapter 3
[Link] Semaphores in detail

2. Explain the critical section problem in detail

3. Explain Peterson's Problem with solution

●​ (Ans on WhatsApp Group)

14

You might also like