Question Bank: Operating System (Unit I & II)
1. Define an Operating System.
An Operating System is a System software that
manages all the resources of the computing device.
Acts as an interface between the software and
different parts of the computer or the computer
hardware.
Manages the overall resources and operations of
the computer.
Controls and monitors the execution of all other
programs that reside in the computer, which also
includes application programs and other system software of the computer.
Examples of Operating Systems are Windows, Linux, macOS, Android, iOS, etc.
2. Explain the main functions of an Operating System with suitable examples.
Functions of an Operating System
1. Process Management
Process management in operating system is about managing processes. A Process is a running program. The
life cycle of process is from the moment program start until it finishes. Operating system makes sure each
process:
gets its turn to use the CPU
synchronized when needed
has access to the resources it needs, like memory,
files, and input/output devices.
Core Functions in Process Management:
Process Scheduling: Allocates CPU time to
processes based on scheduling algorithms
like Round Robin or Priority Scheduling.
Process Synchronization: Coordinate multiple processes to ensure orderly execution and prevent
conflicts.
Deadlock Handling: Prevents deadlocks by using strategies like resource allocation graphs or avoiding
circular wait conditions.
Inter-Process Communication (IPC): Facilitates communication between processes through shared
memory, allowing processes to exchange data directly.
2. Memory Management
Memory management is an essential task of the operating system that handles the storage and organization of
data in both main (primary) memory and secondary storage. The OS ensures that memory is allocated and
deallocated properly to keep programs running smoothly. It also manages the interaction between volatile
main memory and non-volatile secondary storage.
Main Memory Management
Memory Allocation → Assign memory to processes
(paging, segmentation).
Memory Deallocation → Free unused memory.
Memory Protection → Stop processes from accessing
each other’s memory.
Virtual Memory → Use disk space as extra memory.
Fragmentation → Manage wasted memory
(internal/external).
Secondary Memory Management
Disk Space Allocation → Organize file storage (contiguous, linked, indexed).
File System Management → Manage files and directories.
Free Space Management → Track available disk space.
Disk Scheduling → Arrange order of read/write requests.
Backup & Recovery → Protect and restore data after failure.
3. File System Management
File management in the operating system ensures the organized storage, access and control of files. The OS
abstracts the physical storage details to present a logical view of files, making it easier for users to work with
data. It manages how files are stored on different types of storage devices (like hard drives or SSDs) and
ensures smooth access through directories and permissions.
File System Management includes managing of:
File Attributes: File Name, File Type, Size, Permissions.
File Types: Text Files, Binary Files, Executable Files.
Operations on Files: Create, Read, Write, Delete.
Access Methods: Sequential Access, Direct Access, Indexed Access.
4. Device Management (I/O System)
Device management of an operating system handles the
communication between the system and its hardware
devices, like printers, disks or network interfaces. The OS
provides device drivers to control these devices, using
techniques like Direct Memory Access (DMA) for efficient
data transfer and strategies like buffering and spooling to
ensure smooth operation.
Major components in Device Management:
Device Drivers: The operating system uses device drivers to interact with hardware devices. There are two
types of device drivers:
1. Kernel-space drivers
2. User-space drivers
Buffering & Caching:
Buffering temporarily stores data in memory to manage differences in device speeds.
Caching improves access speed by storing frequently accessed data in a faster storage medium
(like RAM).
Spooling: Spooling manages data waiting to be processed, particularly in devices like printers.
5. Protection and Security
Protection and security mechanisms in an operating system are designed to safeguard system resources from
unauthorized access or misuse. These mechanisms control which processes or users can access specific
resources (such as memory, files, and CPU time) and ensure that only authorized users can perform specific
actions. While protection ensures proper access control, security focuses on defending the system against
external and internal attacks.
Access Control: The operating system ensures that processes and users can only access resources they are
authorized to.
User Authentication: A system identifies users through user IDs (UIDs) or Security IDs (SIDs). During
login, the operating system verifies the user’s credentials, ensuring that only authorized users can access
their data or system resources.
Resource Protection: Mechanisms like file protection (ensuring only authorized users can access or
modify files) and device protection (restricting direct access to device-control registers) ensure the integrity
of system resources, preventing unauthorized or harmful use.
Security Against Attacks: Security mechanisms defend against external threats like viruses, worms,
denial-of-service attacks, and identity theft. The OS works to prevent these threats and minimize damage.
3. Differentiate between Batch Systems and Time-Sharing Systems.
Aspect Batch System Time Sharing System
Definition Jobs are collected, grouped, and executed in Multiple users can interact with the system
batches without user interaction during simultaneously; CPU time is shared among
execution. users.
User No direct interaction once the job is Continuous and direct interaction with the
Interaction submitted. system.
Response Time High (jobs may wait in the queue for a long Low (designed to provide quick response for
time). interactive use).
Efficiency Good for long, repetitive jobs where Good for interactive tasks and multiple user
interaction is not required. environments.
CPU High, since CPU works on jobs in batch Also high, but CPU time is divided into time
Utilization without idle time. slices for multiple users.
Example Use Payroll processing, billing, report Online systems, multi-user systems, modern
generation. OS environments.
Turnaround Long, as jobs must wait until previous Short, as each user gets CPU time rapidly in
Time batches complete. small time slices.
Cost Cheaper (requires less complex OS and More expensive (requires sophisticated
scheduling). scheduling and multi-user support).
4. What are types of OS? Give examples.
1. Batch Operating System
Batch OS executes a series of jobs without direct interaction with the user. Jobs with similar needs are grouped
and processed together to save time. It was common in early computers where processing time was expensive.
Advantages:
Reduces idle time of the CPU.
Handles large repetitive tasks efficiently.
Disadvantages:
No direct interaction with the user.
Difficult to debug errors in jobs.
2. Multi-Programming Operating System
In a multiprogramming OS, multiple programs are kept in memory at once. The CPU switches between
them when one program waits for I/O, improving resource utilization.
Advantages:
Increases CPU efficiency by reducing idle time.
Better utilization of system resources.
Disadvantages:
Requires large memory to handle multiple programs.
Complex to manage CPU scheduling.
3. Multi-Tasking/Time-Sharing Operating System
This OS allows multiple tasks or users to share system resources at the same time. CPU time is divided into
small slices so users feel like they are working simultaneously.
Advantages:
Quick response time for users.
Efficient for interactive systems.
Disadvantages:
High resource requirements.
Security and data protection can be a concern.
4. Multi-Processing Operating System
A multiprocessing OS uses two or more processors within a single system to execute multiple tasks
simultaneously. It increases performance and reliability.
Advantages:
High throughput and faster processing.
Reliability: if one processor fails, others continue.
Disadvantages:
Expensive due to multiple CPUs.
Complex architecture and programming.
5. Distributed Operating System
Distributed OS connects multiple computers and makes them function as a single system. Tasks are
distributed among systems for better efficiency and reliability.
Advantages:
High fault tolerance and reliability.
Resource sharing across multiple systems.
Disadvantages:
Complex to design and manage.
Security risks due to networking.
6. Network Operating System (NOS)
Network OS runs on servers and enables management of network resources such as file sharing, printers,
and communication between devices.
Advantages:
Centralized control and resource management.
Strong security and easy file sharing.
Disadvantages:
High cost of setup and maintenance.
Server dependency; if the server fails, services stop.
7. Real-Time Operating System
These types of OSs serve real-time systems. The time interval required to process and respond to inputs is very
small. This time interval is called response time. Real-time systems are used when there are time requirements
that are very strict like missile systems, air traffic control systems, robots, etc.
Types of Real-Time Operating Systems
Hard Real-Time Systems: Hard Real-Time OSs are meant for applications where
time constraints are very strict and even the shortest possible delay is not acceptable.
These systems are built for saving lives like automatic parachutes or airbags which
are required to be readily available in case of an accident. Virtual memory is rarely
found in these systems.
Soft Real-Time Systems: These OSs are for applications where time is less strict.
5. Write any four basic Linux commands with their usage.
1. ls
Usage: Lists files and directories in the current directory.
Example: ls -l → shows files with detailed information (permissions, size, date).
2. cd
Usage: Changes the current working directory.
Example: cd /home/user/Documents → moves to the Documents folder.
3. pwd
Usage: Displays the present working directory path.
Example: pwd → outputs something like /home/user/Desktop.
4. mkdir
Usage: Creates a new directory.
Example: mkdir projects → creates a folder named projects.
5. rm
Usage: Removes files or directories.
Example: rm [Link] → deletes [Link]; rm -r folder → deletes folder and its contents.
6. What is the purpose of the `pwd` and `cd` commands in Linux?
pwd (Print Working Directory)
Purpose: Displays the absolute path of the current working directory.
Use: Helps users know their exact location in the directory structure.
Example:
pwd
Output: /home/user/Desktop
cd (Change Directory)
Purpose: Used to navigate from one directory to another.
Use: Allows users to move through the file system.
Example:
cd /home/user/Documents
Moves the user to the Documents folder.
7. Explain the use of `chmod` in Linux.
Full Form: Change Mode
Purpose: Used to change the permissions of a file or directory (read, write, execute).
Permissions in Linux: r → Read, w → Write, x → Execute
Two ways to use chmod:
1. Symbolic Mode: chmod u+x [Link]
→ Gives the user (u) execute (x) permission for [Link].
2. Numeric Mode: chmod 755 [Link]
→ Sets permissions: user = read/write/execute, group = read/execute, others = read/execute.
8. Differentiate between a kernel and a shell.
Aspect Kernel Shell
Definition Core part of the OS that manages hardware Command interpreter that acts as an interface
and system resources. between user and kernel.
Role Controls CPU, memory, I/O devices, and Takes user commands and translates them into
processes. actions for the kernel.
Interactio Works in the background, not directly Directly interacted with by users via command-
n accessed by users. line or scripts.
Type It is a low-level program. It is a high-level program.
Examples Monolithic Kernel (Linux), Microkernel Bash, Zsh, Ksh, Csh.
(Mach).
9. Write the command to display the hostname of a Linux system.
The command to display the hostname of a Linux system is:
hostname
Example Output: my-computer
You can also use: uname -n
→ which also shows the system’s hostname.
10. Explain the working modes of `vi` editor in Linux?
The vi editor is a text editor that is available on almost all Unix systems. It is a very powerful editor with
many features that make it ideal for editing text files. One of the most important features of the vi editor is
that it is modal, which means that it has different modes for editing and for viewing files. This is a major
advantage over other editors, which are not modal and thus confusing.
1. Command Mode (Default Mode)
When you open a file in vi, it starts in command mode.
Used to give commands for navigation, deleting text, copying, pasting, saving, or quitting.
Example commands:
o dd → delete a line
o yy → copy a line
o p → paste
2. Insert Mode
Used to enter and edit text.
Switch from command mode to insert mode by pressing:
o i → insert before cursor
o a → append after cursor
o o → open a new line below
To exit insert mode, press Esc (goes back to command mode).
3. Escape Mode / Last Line Mode
Also called command-line mode.
Accessed by typing : in command mode.
Used for advanced commands like saving, quitting, searching, and replacing.
Examples:
o :w → save file
o :q → quit editor
o :wq → save and quit
o :q! → quit without saving
o
11. Define a Process.
A process is a program in execution, where execution must proceed in a sequential manner. Unlike a program,
which is a passive entity stored on disk, a process is an active entity created when a program is loaded into
memory and starts running.
A program becomes a process once it is loaded into memory and execution begins (e.g., via command line
or GUI).
Multiple processes can be created from a single program (e.g., multiple users
running the same program).
Components of a Process
1. Program Code (Text Section): The executable instructions of the program.
2. Current Activity: Includes the program counter and CPU registers.
3. Stack: Holds temporary data such as function parameters, return addresses,
and local variables.
4. Data Section: Contains global variables.
5. Heap: Memory dynamically allocated during runtime.
12. What is a Process Control Block (PCB)?
A Process Control Block (PCB), also called a Task Control Block, is a data
structure maintained by the operating system for every process. It stores all the
essential information required to manage and execute a process.
Contents of PCB
• Process state – running, waiting, etc
• Program counter – location of instruction to next execute
• CPU registers – contents of all process-centric registers
• CPU scheduling information- priorities, scheduling queue pointers
• Memory-management information – memory allocated to the process
• Accounting information – CPU used, clock time elapsed since start, time limits
• I/O status information – I/O devices allocated to process, list of open files
13. List any two differences between Preemptive and Non-Preemptive scheduling.
Aspect Pre-emptive Scheduling Non-Pre-emptive Scheduling
Definition CPU can be taken away from a process Once a process starts, it cannot be interrupted
before it finishes execution. until it finishes or voluntarily releases the CPU.
Control OS decides when a process should stop and Process keeps the CPU until it terminates or
CPU is reassigned. switches to waiting state.
Response Better response time for high-priority Poor response time for high-priority processes if
Time processes. a long process is running.
Complexity More complex (requires context switching Simpler to implement (no forced context
and scheduling overhead). switching).
Examples Round Robin, Shortest Remaining Time First Come First Serve (FCFS), Shortest Job
First (SRTF), Priority Scheduling Next (SJN), Priority Scheduling (non-
(preemptive). preemptive).
14. Define CPU Burst and I/O Burst.
CPU Burst
A CPU Burst is the period of time during which a process executes on the CPU, performing computations
(like arithmetic or logic operations).
It occurs when the process requires processor time and no I/O operations.
Example: Calculating results of a program, performing addition, sorting, etc.
I/O Burst
An I/O Burst is the period of time during which a process performs input/output operations, such as reading
from disk, writing to a file, or waiting for user input.
During this time, the CPU is idle for that process, and the process waits for I/O completion.
Example: Reading data from disk, printing to a printer, fetching input from a keyboard.
15. Discuss different scheduling criteria and explain their
significance in CPU scheduling.
1. CPU Utilization
Meaning: How much the CPU is kept busy doing useful
work (not idle).
The goal is to maximize utilization, ideally close to 100%
(but not always possible).
Example: If the CPU is busy 90% of the time and idle
10% of the time, CPU utilization is 90%.
Significance: Higher utilization means better system efficiency.
2. Throughput
Meaning: The number of processes that finish execution per unit time.
Higher throughput = better performance.
Example: If 10 processes finish in 5 seconds, throughput = 10/5 = 2 processes/second.
Significance: Higher throughput means more work is done by the system in less time.
3. Turnaround Time
Meaning: The total time taken from submission to completion of a process.
Formula: Turnaround Time = Completion Time - Arrival Time
Example: Process arrives at time 0, finishes at time 20 → Turnaround Time = 20.
Significance: Important for batch systems where users care about total job completion time.
4. Waiting Time
Meaning: The total time a process spends waiting in the ready queue, not running.
Formula: Waiting Time = Turnaround Time - Burst Time
(Burst Time = actual CPU time required by the process)
Example:
o Process needs 5 units of CPU time (burst time),
o Turnaround time = 20,
o Waiting Time = 20 – 5 = 15.
Significance: Reduces delays and improves overall performance.
5. Response Time
Meaning: The time between process submission and the first time it gets the CPU.
Important in time-sharing systems, where quick feedback matters.
Example: Process arrives at time 0, first scheduled on CPU at time 3 → Response Time = 3.
Significance: Very important in time-sharing and interactive systems, where quick feedback improves
user experience.
16. Write two advantages of Round Robin scheduling.
Round Robin is a preemptive CPU scheduling algorithm where each process is assigned a fixed time slice
(time quantum, q).
o A process runs for at most q units of time.
o If it finishes before q, it leaves the CPU.
o If it doesn’t finish, it is preempted and placed at the end of the ready queue.
o The CPU scheduler then picks the next process in the queue.
It is one of the fairest scheduling algorithms and is widely used in time-sharing systems.
Example of RR with Time Quantum = 4
Process Burst Time
P1 24
P2 3
P3 3
The Gantt chart is:
• Typically, higher average turnaround than SJF, but better response
Advantages of Round Robin Scheduling
1. Fairness:
o Every process gets an equal share of CPU time (no starvation).
o Suitable for time-sharing systems, where responsiveness is important.
2. Predictable Waiting Time:
o Each process waits at most (n-1)q before getting CPU time again (where n is number of processes).
o This makes it good for interactive systems where users expect quick responses.
17. Differentiate between SJF (Shortest Job First) and FCFS scheduling.
1. First Come First Serve (FCFS) Scheduling
Type: Non-preemptive scheduling.
Rule: The process that arrives first in the ready queue gets the CPU first.
Fair but not always efficient → longer jobs may delay shorter ones (convoy effect).
Example (FCFS):
Suppose 3 processes arrive at the same time with burst times: P1 = 6, P2 = 8, P3 = 7
Execution order: P1 → P2 → P3
Waiting times:
o P1 = 0
o P2 = 6
o P3 = 6 + 8 = 14
Average Waiting Time = (0 + 6 + 14) / 3 = 6.67
2. Shortest Job First (SJF) Scheduling
Type: Can be non-preemptive or preemptive (SRTF).
Rule: The process with the smallest burst time is executed next.
Optimal for minimizing average waiting time, but may cause starvation (long processes may wait
too long if short ones keep coming).
Example (SJF):
With the same processes (burst times): P1 = 6, P2 = 8, P3 = 7
Execution order (shortest job first): P1 → P3 → P2
Waiting times:
o P1 = 0
o P3 = 6
o P2 = 6 + 7 = 13
Average Waiting Time = (0 + 6 + 13) / 3 = 6.33 (better than FCFS).
Key Differences between FCFS and SJF
Aspect FCFS (First Come First Serve) SJF (Shortest Job First)
Scheduling type Non-preemptive Can be non-preemptive or preemptive
Selection Based on arrival order Based on shortest burst time
criteria
Fairness Fair (processes executed in order of arrival) May cause starvation of long jobs
Performance Simple, but may cause convoy effect (long Optimal in terms of average waiting time
process delays all others)
Implementation Easy Requires knowledge/prediction of burst
times
Best for Batch systems with similar job lengths Systems where burst times are predictable
18. What is the Critical Section Problem?
In an operating system with concurrent processes (p0, p1, … pn-1), each process may have a segment of code,
called the critical section, where it accesses shared resources (like common variables, files, tables, databases).
The problem:
If multiple processes enter their critical sections at the same time, it may lead to data inconsistency
or race conditions.
Example: Two processes updating a shared bank account balance at the
same time can cause incorrect results.
General Structure of a Process Pi
Entry Section: Code that requests permission to enter the critical section.
Critical Section: Code where the process accesses shared resources.
Exit Section: Code that signals the process is leaving the critical section.
Remainder Section: Code outside the critical section (normal execution).
Requirements for a Correct Solution
Any solution to the critical section problem must satisfy three conditions:
1. Mutual Exclusion
o Only one process can execute in the critical section at a time.
o If Pi is in CS, no other Pj (≠ i) should be in CS.
2. Progress
o If no process is in CS and some want to enter, then one of the waiting processes must be allowed to enter
within a finite time.
3. Bounded Waiting
o A process must not wait indefinitely to enter CS.
o There should be a limit on how many times other processes can enter CS before a waiting process gets its
chance.
19. What are Semaphores?
Semaphores are integer variables that are used to solve the critical section problem by using two atomic
operations, wait and signal that are used for process synchronization.
Wait: The wait operation decrements the value of its argument S, if it is positive. If S is negative or zero,
then no operation is performed.
wait(S)
{
while (S<=0);
S--;
}
Signal: The signal operation increments the value of its argument S.
signal(S)
{
S++;
}
Advantages of Semaphores
Synchronization: Semaphores are powerful tools for synchronizing multiple processes or threads, ensuring
they access shared resources in an orderly and safe manner.
Resource Protection: They effectively protect critical sections and shared data from simultaneous access
by multiple processes, preventing data corruption.
Prevent Race Conditions: Semaphores are used to prevent race conditions, which occur when multiple
threads attempt to access a resource concurrently.
Essential for Multitasking: They are an indispensable tool for multitasking programming, a core function
of modern operating systems.
20. Define Mutual Exclusion with respect to process synchronization.
Mutual Exclusion is a fundamental requirement of process synchronization.
It means that only one process at a time can be allowed to execute in its critical section (the part of the
program that accesses shared resources like variables, files, or devices).
If one process is executing in its critical section, all other processes must be prevented from entering their
critical sections until the first one exits.
Why is Mutual Exclusion Needed?
Without mutual exclusion, race conditions occur → multiple processes modify shared data at the same
time, leading to inconsistent or incorrect results.
Example:
o Two processes try to update the same bank account balance simultaneously.
o If both read the old value before writing, one update may overwrite the other.
Relation to Critical Section Problem
Mutual exclusion is one of the three essential conditions (along with progress and bounded waiting) for
solving the critical section problem:
1. Mutual Exclusion → At most one process in critical section at a time.
2. Progress → If no process is in CS, one waiting process must be allowed to enter.
3. Bounded Waiting → A process waiting for CS should not wait indefinitely.
How is it Achieved?
Using software algorithms (e.g., Peterson’s algorithm).
Using synchronization primitives like:
o Semaphores (binary semaphore for mutex).
o Mutex Locks.
o Monitors.
o Hardware instructions (e.g., Test-and-Set, Compare-and-Swap).
21. Compare Simple Batch Systems, Time-Sharing Systems, and Distributed Systems in terms of memory
management, process management, and process scheduling.
Simple Batch Systems
Memory Management:
o No sophisticated memory management.
o Entire job loaded into memory before execution.
o No protection between jobs.
Process Management:
o Jobs executed one by one in batches.
o No interaction with the user while the job is running.
o Very little or no context switching.
Process Scheduling:
o Uses non-preemptive scheduling, mainly First-Come, First-Served (FCFS).
o Jobs executed strictly in arrival order.
Time-Sharing Systems
Memory Management:
o Multiple processes share memory through multiprogramming.
o Techniques like paging, segmentation, and virtual memory ensure fairness and protection among
processes.
Process Management:
o Supports multi-tasking and allows multiple users to interact with the system simultaneously.
o Each user is allocated a process; system manages CPU, I/O, and user requests concurrently.
Process Scheduling:
o Uses preemptive scheduling algorithms (e.g., Round Robin, Priority Scheduling).
o Ensures quick response time and fair CPU allocation among interactive users.
Distributed Systems
Memory Management:
o Each computer/node manages its own memory locally.
o Memory management also focuses on resource sharing across the network and maintaining consistency
for distributed applications.
Process Management:
o Processes may run on different physical machines.
o Requires coordination, synchronization, and communication between processes across the network
(e.g., remote procedure calls, message passing).
Process Scheduling:
o Scheduling decisions are made in a distributed manner across nodes.
o Involves load balancing, resource allocation, and fault tolerance across multiple machines.
22. Describe the architecture of Linux OS with a neat diagram.
The Linux OS architecture is a layered structure comprising the
Hardware, Kernel, Shell, and Application layers. The Kernel is the
core, managing system resources and interacting with the
Hardware. The Shell acts as the user interface, translating commands
for the kernel. System Libraries provide essential functions to
applications, which make up the Application layer, while System
Utilities perform specific tasks. Users interact with the system through
the Shell and applications, which use system calls to request services
from the Kernel.
1. Hardware Layer:
This is the physical foundation of the system, including the CPU, RAM, hard drives, and other peripherals.
2. Kernel Layer:
The heart of the operating system, the kernel manages system resources like memory, processes, and devices. It
acts as the bridge between the hardware and the rest of the system, handling tasks such as task scheduling,
memory management, and device drivers.
3. System Libraries:
These are collections of functions that applications use to access the kernel's services. The GNU C library
(glibc) is a key example, translating user commands into system calls.
4. Shell and System Utilities:
Shell: A command-line interpreter that serves as the primary interface for users to interact with the system
by entering commands.
System Utilities: Programs that perform specialized functions and provide various services to the user,
working with the kernel to execute tasks.
5. Application Layer:
This layer consists of the user-facing software, such as word processors, web browsers, and databases, that run
on top of the operating system.
23. Write short notes on:
(a) Linux Directory Structure
Linux uses a hierarchical directory
structure (tree-like), starting from the
root directory /.
Everything in Linux is treated as a file,
including devices and processes.
Important Directories:
• / → Root directory (top of the hierarchy).
• /bin → Essential binary programs (e.g., ls, cp, mv).
• /sbin → System binaries for administration (e.g., shutdown, ifconfig).
• /etc → Configuration files (e.g., network, user settings).
• /dev → Device files (e.g., /dev/sda for disks).
• /proc → Virtual filesystem with process and kernel info.
• /var → Variable data (e.g., logs, mail, spool files).
• /tmp → Temporary files (cleared on reboot).
• /usr → User programs, libraries, documentation.
• /home → Personal directories for users (/home/user1, /home/user2).
• /lib → Shared libraries required by binaries.
• /boot → Bootloader files and kernel images.
(b) Basic File Commands in Linux
Linux provides powerful commands for file handling.
File and Directory Handling:
ls → List files and directories.
cd dirname → Change directory.
pwd → Show current directory.
mkdir dirname → Create a new directory.
rmdir dirname → Remove an empty directory.
File Creation and Viewing:
touch filename → Create an empty file.
cat filename → Display contents of a file.
more filename / less filename → View long files page by page.
nano filename / vi filename → Edit a file.
File Copy, Move, Delete:
cp source dest → Copy file.
mv source dest → Move or rename file.
rm filename → Delete file.
File Permissions and Info:
chmod → Change file permissions.
chown → Change file owner.
stat filename → Detailed file info.
23. Explain the steps to create, edit, save, and execute a shell script in `vi` editor.
A shell script is a plain text file containing a sequence of Linux/Unix commands that can be executed together.
The vi editor is commonly used to create and edit such scripts.
1. Create a New Shell Script File
Open terminal and type:
vi [Link]
Example:
vi [Link]
2. Enter Insert Mode and Write the Script
Press i to enter insert mode in vi.
Start the script with a shebang line (to specify the shell interpreter):
#!/bin/bash
echo "Hello, World!"
Add more commands as needed.
3. Save and Exit in vi
• Press Esc to leave insert mode.
• To save and quit, type: :wq
• To save only, type: :w
• To quit without saving, type: :q!
4. Make the Script Executable
By default, new files don’t have execute permissions.
Grant permission with:
chmod +x [Link]
5. Execute the Script
Run the script using either method:
./[Link]
Or explicitly with a shell:
bash [Link]
Example Run
$ vi [Link]
# (inside vi, type the following)
#!/bin/bash
echo "Welcome to Shell Scripting!"
# Save and exit (:wq)
$ chmod +x [Link]
$ ./[Link]
Output: Welcome to Shell Scripting!
25. Explain the process state model with a neat diagram.
In an operating system, a process is a program in execution.
As it executes, it changes states depending on its activity.
The operating system keeps track of these states and
manages transitions.
Main Process States
1. New
o The process is being created.
o Example: When a user starts a program, the OS sets up resources for it.
2. Ready
o The process is loaded into memory and is ready to run, but is waiting for CPU allocation.
o Multiple processes may be in the ready queue.
3. Running
o The process is currently being executed by the CPU.
o At any instant, only one process per CPU core can be in the running state.
4. Waiting (Blocked)
o The process is not using the CPU but is waiting
for some event (e.g., I/O completion, input from
the user, availability of a resource).
5. Terminated (Exit)
o The process has finished execution and is
removed from the system.
26. What is Process Scheduling? Discuss various types of schedulers.
Process Scheduling is the activity of the operating system that decides which process in the ready queue will
be executed next by the CPU.
The goal is to:
o Maximize CPU utilization.
o Ensure fairness among processes.
o Provide responsiveness in time-sharing systems.
The process scheduler maintains different queues:
Job Queue → All processes in the system.
Ready Queue → Processes in memory, waiting
for CPU.
Device Queue → Processes waiting for I/O
devices.
A process may migrate between these queues during execution.
Types of Process Schedulers
1. Long-Term Scheduler (Job Scheduler)
Decides which jobs (processes) are admitted into the system for processing.
Controls the degree of multiprogramming (number of processes in memory).
Invoked infrequently (seconds, minutes).
Can afford to be slow.
Distinguishes between:
o I/O-bound processes → Spend more time doing
I/O (many short CPU bursts).
o CPU-bound processes → Spend more time doing
computation (few long CPU bursts).
Goal: Maintain a good mix of I/O-bound and CPU-bound processes.
2. Short-Term Scheduler (CPU Scheduler)
Selects which process in the ready queue will run next.
Invoked very frequently (milliseconds).
Must be fast and efficient.
Also called the dispatcher.
Deals with context switching, mode switching, and CPU allocation.
3. Medium-Term Scheduler
Temporarily suspends (swaps out) or resumes (swaps in) processes.
Improves overall process mix and system
performance.
Reduces the degree of multiprogramming if
the system is overloaded.
Example: In time-sharing systems, a
background process may be suspended to give
more CPU to interactive users.
27. Explain different CPU scheduling algorithms with examples.
A Process Scheduler schedules different processes to be assigned to the CPU based on particular scheduling
algorithms. There are six popular process scheduling algorithms:
1. First-Come, First-Served (FCFS) Scheduling
2. Shortest-Job-Next (SJN) Scheduling
3. Priority Scheduling
4. Shortest Remaining Time
5. Round Robin(RR) Scheduling
6. Multiple-Level Queues Scheduling
1. First-Come, First-Served (FCFS)
• First-Come, First-Served Scheduling Algorithm is non-preemptive algorithm.
• It is the simplest of all the scheduling algorithms.
• The key concept of this algorithm is “The process which comes first in the ready queue will allocate the
CPU first”.
• The next process will allocate the CPU only after the previous gets fully executed.
Example: Suppose we have three processes that arrive at time 0 with burst times:
P1 = 4, P2 = 3, P3 = 2
Execution order = P1 → P2 → P3.
Waiting times:
o P1 waits 0
o P2 waits 4
o P3 waits 4 + 3 = 7
Average waiting time = (0 + 4 + 7) / 3 = 11/3 ≈ 3.67
Advantages:
Simple to understand and implement.
No starvation (every process eventually gets CPU).
2. Shortest Job First (SJF) / Shortest Job Next
Usually non-preemptive (but has a preemptive variant called Shortest Remaining Time First (SRTF))
The process with the smallest CPU burst time is selected next.
Example: Suppose three processes with burst times:
o P1 = 6, P2 = 2, P3 = 8
Execution order = P2 → P1 → P3 (Because 2 is the shortest, then among remaining 6 and 8, 6 is shorter.)
If arrival times vary, the scheduler picks the next shortest among processes already in the ready queue.
Preemptive variant (SRTF): If a new process arrives with a shorter remaining time than the current running
process, the CPU can preempt the current process and switch to the new one.
Advantages:
o Minimizes average waiting time (optimal in that sense for known burst times).
3. Priority Scheduling
Can be non-preemptive or preemptive
Each process is assigned a priority. The CPU is allocated to the process with the highest priority (or lowest
numerical priority value, depending on convention).
o In non-preemptive priority scheduling, once a process starts executing, it runs to completion even if a
higher-priority process arrives.
o In preemptive priority scheduling, if a higher-priority process arrives, it can preempt the currently
running process.
Example: Suppose we have processes with (burst time, priority):
Proces Burst Time Priority (lower = higher priority)
s
P1 5 2
P2 3 1
P3 4 3
Priority scheduling (non-preemptive) order = P2 → P1 → P3 (because P2 has highest priority).
Advantages:
o Allows important or critical processes to get CPU earlier.
4. Round Robin (RR): Round Robin is a pre-emptive CPU scheduling algorithm where each process is
assigned a fixed time slice (time quantum, q).
o A process runs for at most q units of time.
o If it finishes before q, it leaves the CPU.
o If it doesn’t finish, it is pre-empted and placed at the end of the ready queue.
o The CPU scheduler then picks the next process in the queue.
It is one of the fairest scheduling algorithms and is widely used in time-sharing systems.
Example of RR with Time Quantum = 4
Process Burst Time
P1 24
P2 3
P3 3
The Gantt chart is:
• Typically, higher average turnaround than SJF, but better response
Advantages of Round Robin Scheduling
Fairness:
o Every process gets an equal share of CPU time (no starvation).
o Suitable for time-sharing systems, where responsiveness is important.
Predictable Waiting Time:
o Each process waits at most (n-1)q before getting CPU time again (where n is number of processes).
o This makes it good for interactive systems where users expect quick responses.
5. Multilevel Queue and Multilevel Feedback Queue
Multilevel Queue
o The ready queue is divided into several separate queues (e.g., system processes, interactive, batch).
o Each queue may have its own scheduling algorithm and priority.
o Processes are assigned to a queue based on some property (priority, memory requirements, etc.).
Multilevel Feedback Queue
o Similar to multilevel queue, but processes can move between queues based on their behavior (e.g.,
if a process uses too much CPU, it may be demoted to a lower-priority queue).
o This flexibility helps adapt to changing behavior and improves responsiveness for interactive tasks.
Advantages:
o Provides differentiation among classes of processes.
o Feedback helps in managing CPU-bound vs I/O-bound processes dynamically.
o
28. Compare FCFS, SJF, Priority, and Round Robin scheduling with examples.
Aspect FCFS (First Come SJF (Shortest Job Priority Round Robin (RR)
First Serve) First) Scheduling
Type Non-preemptive Non-preemptive or Both: Preemptive Preemptive
Preemptive (SRTF) or Non-preemptive
Basis of Order of arrival (FIFO) Process with Process with Each process gets
Selection smallest CPU burst highest priority equal time quantum in
time value cyclic order
Example Order: P1 → P2 → P3 Order: P2 → P1 → Suppose priorities: Time Quantum = 2
(Burst times Avg WT = (0+5+8)/3 = P3 Avg WT = P2 > P1 > P3 Order: P1(2) → P2(2)
P1=5, P2=3, 4.3 (0+3+8)/3 = 3.7 Order: P2 → P1 → P3(2) → P1(3) →
P3=8) → P3 P2(1) → P3(6)
Advantages - Simple and fair - No - Optimal average - Important jobs - Fair, responsive,
starvation waiting time (when can be prioritized avoids starvation
burst known)
Disadvantage - Convoy effect: long - Needs knowledge - Starvation of - Performance depends
s process delays all of burst time - low-priority jobs - on time quantum -
others Starvation possible Priority inversion High context switch
overhead
Best suited for Batch systems Batch systems where Systems needing Time-sharing and
burst time is known urgent jobs first interactive systems
29. A set of processes have arrival time and burst time as follows. Calculate average waiting time and
turnaround time using FCFS, preemptive SJF, non-preemptive SJF, and round robin(quantum=2)
scheduling:
Process Arrival Time Burst Time
P1 0 5
P2 2 3
P3 4 1
P4 5 2
FCFS (First-Come, First-Served)
Gantt: P1 (0–5) → P2 (5–8) → P3 (8–9) → P4 (9–11)
Proces Arrival Burst Completio Turnaround (=C–A) Waiting (=T–Burst)
s n
P1 0 5 5 5-0=5 5-5=0
P2 2 3 8 8-2=6 6-3=3
P3 4 1 9 9-4=5 5-1=4
P4 5 2 11 11-5=6 6-2=4
Average waiting time = (0+3+4+4)/4 = 2.75; Average turnaround time = (5+6+5+6)/4 = 5.50
SJF (Non-preemptive)
At t=0 only P1 is available, so it runs to completion; then pick the shortest among arrived.
Gantt: P1 (0–5) → P3 (5–6) → P4 (6–8) → P2 (8–11)
Process Arriva Burst Completio Turnaround Waiting
l n
P1 0 5 5 5 0
P2 2 3 11 9 6
P3 4 1 6 2 1
P4 5 2 8 3 1
Average waiting time = (0+6+1+1)/4 = 2.00; Average turnaround time = (5+9+2+3)/4 = 4.75
SJF (Preemptive / SRTF)
With these arrivals, ties mean the current job keeps the CPU; the schedule ends up the same as above.
Gantt: P1 (0–5) → P3 (5–6) → P4 (6–8) → P2 (8–11)
Per-process results are identical to non-preemptive SJF:
Average waiting time = 2.00; Average turnaround time = 4.75
Round Robin (quantum = 2)
Gantt: P1 (0–2) → P2 (2–4) → P1 (4–6) → P3 (6–7) → P2 (7–8) → P4 (8–10) → P1 (10–11)
Process Arriva Burst Completio Turnaround Waiting
l n
P1 0 5 11 11 6
P2 2 3 8 6 3
P3 4 1 7 3 2
P4 5 2 10 5 3
Average waiting time = (6+3+2+3)/4 = 3.50; Average turnaround time = (11+6+3+5)/4 = 6.25
30. Define process synchronization. Explain the critical section problem with its requirements.
In an operating system, process synchronization is a mechanism that ensures that concurrent processes
(executing simultaneously) access shared resources in a safe and orderly manner, without causing data
inconsistency.
Without synchronization, multiple processes updating shared variables/files/devices at the same time can
lead to race conditions.
Critical Section Problem
Each process has a part of its program, called the critical section, where it accesses shared variables,
files, or devices.
The Critical Section Problem is:
To design a protocol that ensures only one process executes in its critical section at a time, while still
allowing efficient execution.
General Structure of a Process Pi
do {
// Entry Section (request permission)
critical section // accessing shared resource
// Exit Section (release resource)
remainder section // rest of the code
} while (true);
Requirements of a Good Solution
A correct solution to the critical section problem must satisfy three conditions:
1. Mutual Exclusion
o At most one process can be in its critical section at a time.
o If Pi is in its CS, no other Pj (≠ i) can be in CS.
2. Progress
o If no process is in CS and some want to enter, then one of them must be allowed to enter in a finite time.
o Choice cannot be postponed indefinitely.
3. Bounded Waiting
o There must be a bound on how many times other processes can enter CS before a waiting process gets its
turn.
o Prevents starvation.
31. Explain Semaphores and its types. How are they used to solve the critical section problem?
A semaphore is a synchronization tool used in concurrent programming.
It is an integer variable S, but it can only be accessed via two atomic operations:
o wait(S) (also called P() or down())
o signal(S) (also called V() or up())
These operations are used to control access to shared resources (critical sections).
Semaphore Operations
1. Wait: The wait operation decrements the value of its argument S, if it is positive. If S is negative or zero,
then no operation is performed.
wait(S)
{
while (S<=0);
S--;
}
2. Signal: The signal operation increments the value of its argument S.
signal(S)
{
S++;
}
Both wait() and signal() must be atomic (no interruptions while executing).
Types of Semaphores
1. Counting Semaphore
o Value can range over an unrestricted domain (≥ 0).
o Used when there are multiple instances of a resource.
o Example:
3 printers available → initialize S = 3.
Each process does wait(S) before printing, signal(S) after printing.
2. Binary Semaphore (Mutex)
o Value is only 0 or 1.
o Works like a lock.
o Used to enforce mutual exclusion (only one process in the critical section at a time).
Using Semaphores to Solve the Critical Section Problem
The critical section problem requires that:
1. Mutual Exclusion – Only one process in the critical section at a time.
2. Progress – If no process is in CS, one waiting process must be allowed to enter.
3. Bounded Waiting – A process should not wait indefinitely.
Solution Using Binary Semaphore (Mutex):
Initialize mutex = 1 (resource is free).
do {
wait(mutex); // entry section → request CS
// critical section
signal(mutex); // exit section → release CS
// remainder section
} while (true);
When a process executes wait(mutex), the value decreases.
o If it becomes 0, the resource is locked.
o Other processes trying wait(mutex) must wait until a signal(mutex) is issued.
This guarantees mutual exclusion: only one process at a time can be in the critical section.
32. Describe classic problems of synchronization with algorithm.
Classical problems used to test newly proposed synchronization schemes
1. Bounded-Buffer Problem
2. Readers and Writers Problem
3. Dining-Philosophers Problem
1. Bounded-Buffer Problem (Producer–Consumer Problem)
There is a fixed-size buffer shared between a producer (which generates items) and a consumer (which
uses items).
Synchronization must ensure:
o Producer does not add data when buffer is full.
o Consumer does not remove data when buffer is empty.
Both must not access the buffer simultaneously.
Algorithm (using semaphores)
semaphore mutex = 1; // for mutual exclusion
semaphore empty = n; // number of empty slots (buffer size = n)
semaphore full = 0; // number of filled slots
Producer:
do {
produce_item();
wait(empty); // decrease empty slots
wait(mutex); // enter critical section
insert_item();
signal(mutex); // leave critical section
signal(full); // increase filled slots
} while(true);
Consumer:
do {
wait(full); // check if buffer has items
wait(mutex); // enter critical section
remove_item();
signal(mutex); // leave critical section
signal(empty); // increase empty slots
consume_item();
} while(true);
2. Readers–Writers Problem
A shared database/file is accessed by multiple readers and writers.
Rules:
o Multiple readers can read at the same time.
o Only one writer can write at a time.
o No reader allowed during writing.
Algorithm (first readers–writers solution)
semaphore mutex = 1; // controls access to read_count
semaphore wrt = 1; // for writer (or reader-writer exclusion)
int read_count = 0;
Reader:
do {
wait(mutex);
read_count++;
if (read_count == 1)
wait(wrt); // first reader blocks writers
signal(mutex);
// perform reading
wait(mutex);
read_count--;
if (read_count == 0)
signal(wrt); // last reader allows writers
signal(mutex);
} while(true);
Writer:
do {
wait(wrt); // only one writer, excludes readers
// perform writing
signal(wrt);
} while(true);
3. Dining-Philosophers Problem
Five philosophers sit around a circular table. Each has a plate of food and one fork between them.
To eat, a philosopher needs two forks (left and right).
Problem: how to avoid deadlock (if all pick left fork first, all will wait forever).
Algorithm (semaphores for forks)
semaphore fork[5] = {1,1,1,1,1};
Philosopher i:
do {
think();
wait(fork[i]); // pick left fork
wait(fork[(i+1) % 5]); // pick right fork
eat();
signal(fork[i]); // put down left fork
signal(fork[(i+1) % 5]); // put down right fork
} while(true);
Deadlock Avoidance
Allow at most 4 philosophers at the table at once.
Or make one philosopher pick the right fork first (break symmetry).
Or use a monitor with condition variables.
33. Describe Peterson’s solution for process synchronization with algorithm.
Peterson’s Solution is a classic software-based algorithm for achieving process synchronization.
It provides a simple way to solve the Critical Section (CS) Problem for two processes.
It was one of the earliest algorithmic descriptions of a correct solution and works on the assumption of
sequential consistency (i.e., instructions execute in the order
issued).
Concept
The two processes, say P0 and P1, share two variables:
1. int turn;
o Indicates whose turn it is to enter the critical section.
2. boolean flag[2];
o Used to indicate whether a process is ready to enter the critical
section.
o flag[i] = true means process Pi wants to enter CS.
How It Works
1. Entry Section
o Each process sets its flag to true (willing to enter CS).
o Then it sets turn = j, giving the other process a chance.
o If both want to enter CS, the one with the turn value waits.
2. Critical Section
o Only one process enters at a time.
3. Exit Section
o The process resets its flag to false, signaling it is leaving CS.
4. Remainder Section
o The process executes the rest of its code before repeating the cycle.