OS Question Bank Solution
OS Question Bank Solution
A Process Control Block (PCB) is used by the operating system to manage information about a
process. The process control keeps track of crucial data needed to manage processes
efficiently. A process control block (PCB) contains information about the process, i.e. registers,
quantum, priority, etc. The process table is an array of PCBs, which logically contains a PCB for
all of the current processes in the system.
With the creation of a process, a PCB is created which controls how that process is being
carried out. The PCB is created with the aim of helping the OS to manage the enormous
amounts of tasks that are being carried out in the system. PCB is helpful in doing that as it
helps the OS to actively monitor the process and redirect system resources to each process
accordingly. The OS creates a PCB for every process which is created, and it contains all the
important information about the process. All this information is afterward used by the OS to
manage processes and run them efficiently.
OS question bank 1
Primary Terminologies Related to Process Control
Block
Process State: The state of the process is stored in the PCB which helps to manage the
processes and schedule them. There are different states for a process which are “running,”
“waiting,” “ready,” or “terminated.”
Process ID: The OS assigns a unique identifier to every process as soon as it is created
which is known as Process ID, this helps to distinguish between processes.
Program Counter: While running processes when the context switch occurs the last
instruction to be executed is stored in the program counter which helps in resuming the
execution of the process from where it left off.
CPU Registers: The CPU registers of the process helps to restore the state of the process
so the PCB stores a copy of them.
Memory Information: The information like the base address or total memory allocated to a
process is stored in PCB which helps in efficient memory allocation to the processes.
Accounting Information: The information such as CPU time, memory usage, etc helps the
OS to monitor the performance of the process.
OS question bank 2
Process Scheduling: The different information like Process priority, process state, and
resources used can be used by the OS to schedule the process on the execution stack. The
scheduler checks the priority and other information to set when the process will be
executed.
Context Switching: When context switching happens in the OS the process state is saved
in the CPU register and a copy of it is stored in the PCB. When the CPU switches to another
process and then switches back to that process the CPU fetches that value from the PCB
and restores the previous state of the process.
Resources Sharing: The PCB stores information like the resources that a process is using,
such as files open and memory allocated. This information helps the OS to let a new
process use the resources which are being used by any other process to execute sharing
of the resources.
Helps in Scheduling: The process table provides information needed to decide which
process should run next.
Easy Process Management: It organizes all the details about processes in one place,
making it simple for the OS to manage them.
Advantages of PCB:
Efficient process management
Helps in scheduling
Manages resources
Aids in debugging
Disadvantages of PCB:
Consumes memory
OS question bank 3
Slows down due to context switching
1. New State
A process is created but not yet ready for execution.
The OS initializes its Process Control Block (PCB) and allocates necessary resources.
2. Ready State
The process is loaded into RAM and waiting for the CPU.
Example: Multiple programs are waiting for CPU time in a multitasking OS.
3. Running State
The process is executing on the CPU.
Only one process can be in the running state at a time in a single-core system.
It completes execution.
OS question bank 4
It is interrupted (preempted).
It requests I/O.
5. Terminated State
The process completes execution or is forcibly stopped.
State Transitions
1. New → Ready (Process is created and ready for execution)
This model ensures efficient CPU utilization and smooth process management in an OS.
2. Mode of Execution
OS question bank 5
1. Processes are placed in a queue in the order of their arrival.
3. If a process doesn’t complete within the quantum, it is preempted and moved to the end
of the queue.
4. If the process completes execution, it terminates and is removed from the queue.
P1 X Y ? ? ?
Note: Values are filled after solving the problem using a Gantt Chart.
4. Important Formulas
Completion Time (CT): Time at which a process finishes execution.
TAT=CT−ATTAT = CT - AT
WT=TAT−BTWT = TAT - BT
Answer:
The critical section problem occurs in concurrent programming when multiple processes or
threads need access to shared resources. A critical section is a part of the code where shared
resources, such as memory or files, are accessed. To avoid data inconsistencies and ensure
proper execution, we must control access to the critical section.
OS question bank 6
Solution to the Critical Section Problem
The Critical Section Problem requires an efficient solution to manage synchronization among
multiple processes. The solution must ensure that processes can safely execute their critical
sections without conflicts or data inconsistencies.
To achieve this, any solution must satisfy the following three essential conditions:
1. Mutual Exclusion
Definition: Only one process should be allowed inside the critical section at any given
time.
Reason: If multiple processes enter the critical section simultaneously, shared data may
become corrupted or inconsistent due to race conditions.
Implementation:
Locks (Mutex) – A process acquires a lock before entering and releases it after exiting.
2. Progress
Definition: If the critical section is free, a process must not be unnecessarily delayed from
entering.
Reason: If processes that are not interested in entering the critical section block others, it
leads to wasted CPU cycles and inefficient execution.
Implementation:
OS question bank 7
Proper process scheduling – The OS must allow a process to enter as soon as the
critical section becomes free.
Fair lock mechanisms – Avoid processes being unfairly prioritized over others.
3. Bounded Waiting
Definition: Every process should get a fair chance to execute within a finite amount of
time. No process should be indefinitely delayed (starvation).
Implementation:
FIFO-based locking mechanisms – Ensure processes get access in the order they
requested.
In simple terms, mutual exclusion acts as a lock mechanism that prevents multiple processes
from interfering with each other when accessing shared data.
OS question bank 8
3. Avoids Deadlocks and Starvation
Deadlocks occur when two or more processes wait indefinitely for a resource held by each
other. Proper mutual exclusion mechanisms help in deadlock prevention.
Starvation happens when a process is denied access to resources for a long time due to
unfair scheduling. Well-designed mutual exclusion algorithms ensure fairness.
1. Hardware-Based Approaches
Disabling Interrupts
2. Software-Based Solutions
Peterson’s Algorithm
Bakery Algorithm
3. Synchronization Primitives
The main objective of process synchronization is to ensure that multiple processes access
shared resources without interfering with each other and to prevent the possibility of
inconsistent data due to concurrent access. To achieve this, various synchronization
techniques such as semaphores, monitors, and critical sections are used.
In a multi-process system, synchronization is necessary to ensure data consistency and
integrity, and to avoid the risk of deadlocks and other synchronization problems. Process
synchronization is an important aspect of modern operating systems, and it plays a crucial role
in ensuring the correct and efficient functioning of multi-process systems.
On the basis of synchronization, processes are categorized as one of the following two types:
OS question bank 9
Independent Process: The execution of one process does not affect the execution of other
processes.
Process synchronization problem arises in the case of Cooperative processes also because
resources are shared in Cooperative processes.
Process Synchronization
Process Synchronization is the coordination of execution of multiple processes in a multi-
process system to ensure that they access shared resources in a controlled and predictable
manner. It aims to resolve the problem of race conditions and other synchronization issues in a
concurrent system.
1. Inconsistency: When two or more processes access shared data at the same time without
proper synchronization. This can lead to conflicting changes, where one process’s update
is overwritten by another, causing the data to become unreliable and incorrect.
2. Loss of Data: Loss of data occurs when multiple processes try to write or modify the same
shared resource without coordination. If one process overwrites the data before another
process finishes, important information can be lost, leading to incomplete or corrupted
data.
3. Deadlock: Lack of Synchronization leads to Deadlock which means that two or more
processes get stuck, each waiting for the other to release a resource. Because none of the
OS question bank 10
processes can continue, the system becomes unresponsive and none of the processes can
complete their tasks.
Example:
>>ps/grep "chrome"/wc
grep command find/count the lines form the output of the ps command.
Therefore, three processes are created which are ps, grep and wc. grep takes input from ps
and wc takes input from grep.
From this example, we can understand the concept of cooperative processes, where some
processes produce and others consume, and thus work together. This type of problem must be
handled by the operating system, as it is the manager.
Race Condition:
Preemption:
OS question bank 11
If a process is preempted while using shared data, another may read incomplete or
incorrect values.
Chmod question ➖
The
chmod (Change Mode) command in Linux is used to change the permissions of a file or
directory. It controls who can read (r), write (w), or execute (x) a file. Proper understanding of
this command is essential for system security and efficient file management.
The
chmodcommand is essential for file security and access control in Linux. Using the symbolic
or numeric method, you can efficiently set permissions for different users and groups.
Permission Representation
Permissions are assigned to three user groups:
User Groups:
1. Owner (u) – The user who created the file.
Permission Types:
Symbol Permission Numeric Value Meaning
Usage of chmod :-
OS question bank 12
chmod u+r file.txt # Add read permission for the owner
chmod g-w file.txt # Remove write permission from the group
chmod o+x file.txt # Add execute permission for others
chmod u+x,g+r file.sh # Add execute for user, read for group
Examples:-
1. Giving full permission to the owner, read/execute to others:
Context switch
Context switch time is less. Context switch time is more.
time
Blocking If one user-level thread performs a If one kernel thread performs a blocking
operation blocking operation then the entire operation then another thread can
OS question bank 13
process will be blocked. continue execution.
Creation and User-level threads can be created and Kernel-level level threads take more time
Management managed more quickly. to create and manage.
Any operating system can support user- Kernel-level threads are operating
Operating System
level threads. system-specific.
Example POSIX threads, Mach C-Threads. Java threads, POSIX threads on Linux.
User-level threads are more portable Less portable due to dependence on OS-
Portability
than kernel-level threads. specific kernel implementations.
1. Process Management
Handles the creation, scheduling, and termination of processes.
🔹 Example: The OS ensures multiple applications (e.g., browser, media player) run smoothly
without conflicts.
2. Memory Management
Allocates and deallocates memory to processes.
OS question bank 14
Uses techniques like paging, segmentation, and virtual memory to optimize memory
usage.
🔹 Example: Running multiple apps without exhausting RAM, thanks to virtual memory.
3. File System Management
Organizes and stores data efficiently.
🔹 Example: Windows uses NTFS, while Linux uses EXT4 for file management.
4. Device Management
Controls hardware devices (printers, USBs, hard drives).
🔹 Example: Plugging in a USB drive automatically detects and allows file access.
5. Security and Protection
Prevents unauthorized access using authentication (passwords, biometrics).
Enables users to interact with the system via icons, windows, or commands.
🔹 Example: Windows provides GUI, while Linux has both GUI and CLI (Terminal).
7. Deadlock Prevention & Handling
Manages resources to avoid deadlocks where processes wait indefinitely.
OS question bank 15
🔹 Example: Browsing the internet, downloading files, or cloud computing.
OS question bank 16