OS lecture-3
OS lecture-3
True/False Questions
1. A process executes multiple instructions in parallel.
Answer: False (A process executes sequentially.)
2. An executable file on disk is considered a process before it starts executing.
Answer: False (A program is a passive entity; it becomes a process when loaded into
memory.)
3. A single program can create multiple processes for multiple users.
Answer: True
4. The program counter in a PCB stores the address of the next instruction to be
executed.
Answer: True
5. The heap section in a process stores global variables.
Answer: False (The heap stores dynamically allocated memory; global variables are in
the data section.)
6. The process control block (PCB) contains information related to process
scheduling.
Answer: True
7. A process in the "Ready" state is currently executing instructions.
Answer: False (A process in the "Ready" state is waiting to be assigned to a processor.)
8. The program counter is part of the CPU registers.
Answer: True
9. Processes in the "Waiting" state can move directly to the "Running" state.
Answer: False (A process in the "Waiting" state must transition to "Ready" before
running.)
10. The Process Control Block (PCB) contains information about CPU scheduling.
Answer: True
11. The process scheduler’s main goal is to maximize CPU utilization.
Answer: True
12. The ready queue contains processes that are waiting for I/O operations.
Answer: False (The ready queue contains processes that are ready to execute, not
waiting for I/O.)
13. A new process is initially placed in the waiting queue.
Answer: False (A new process is placed in the ready queue.)
14. Interrupts allow the OS to switch from one process to another.
Answer: True
15. Context switching involves saving and restoring the state of a process.
Answer: True
16. A process in the ready queue is guaranteed to be the next to execute.
Answer: False (The process scheduler selects which process to execute based on
scheduling algorithms.)
17. A process in the waiting state can transition to the ready state when the event it
is waiting for occurs.
Answer: True
18. Context switching does not require saving the state of the currently running
process.
Answer: False (Context switching requires saving and restoring process states.)
19. A process that issues an I/O request remains in the running state until the
request is complete.
Answer: False (It moves to the waiting state.)
20. The process scheduler decides which process gets the CPU next.
Answer: True
21. The task_struct in Linux does not contain information about process
scheduling.
Answer: False (It includes scheduling information, process state, memory
management details, etc.)
22. A process can have multiple children but only one parent.
Answer: True
23. The ready queue and waiting queue are the same.
Answer: False (The ready queue holds processes waiting for CPU execution, while the
waiting queue holds processes waiting for an event.)
24. Context switching is required when switching from one process to another.
Answer: True
25. Interrupts allow the OS to handle important system events while suspending
the current process.
Answer: True
26. A context switch happens when the CPU switches from one process to another.
Answer: True
27. Cascading termination refers to terminating all child processes when a parent
process exits.
Answer: True
28. A child process can never share any resources with its parent.
Answer: False (A child can share all, some, or none of its parent’s resources.)
29. In a bounded-buffer system, a producer process never waits.
Answer: False (A producer must wait if the buffer is full.)
30. Message passing is an alternative to shared memory for interprocess
communication (IPC).
Answer: True
36. Context switching introduces overhead because no useful work is done during
the switch.
Answer: True
37. Context switch time depends only on the number of processes running in the
system.
Answer: False (It depends on memory speed, number of registers, and hardware
support.)
38. A process in an I/O wait queue is ready to be assigned a CPU for execution.
Answer: False (It is waiting for an I/O operation to complete.)
39. Message passing in IPC allows processes to communicate without shared
memory.
Answer: True
40. The exec() system call is used to create a new process.
Answer: False (The fork() system call is used to create a new process, while exec()
replaces the current process’s memory space.)
41. The wait() system call allows a parent process to wait until its child process
terminates.
Answer: True
42. In operating systems that enforce cascading termination, if a parent process
terminates, its child processes continue execution.
Answer: False (They are also terminated.)
44. In an unbounded buffer, the producer must wait if the buffer is full.
Answer: False (An unbounded buffer does not have a limit, so the producer never
waits.)
45. A process can create multiple child processes, forming a tree-like structure.
Answer: True
Essay Questions
1. Explain the difference between a program and a process.
Answer:
A program is a passive entity stored on a disk, representing an executable file, while a
process is an active entity that exists when a program is loaded into memory and
executed. A program does not change its state, but a process transitions through
states
2. Describe the different sections of a process and their functions.
Answer:
A process consists of multiple sections:
Text section: Contains the executable code. •
Accounting Information: Tracks CPU usage, execution time, and other process- •
related statistics.
I/O Status Information: Lists allocated I/O devices and open files. •
Context switching involves saving the state of the currently running process and
restoring the state of another process, allowing for efficient multitasking.
7. Explain how a process transitions between different states.
Answer:
A process transitions through multiple states during its execution:
New: The process is being created. •
Terminated: The process has finished execution and is removed from memory. •
Transitions occur due to scheduling decisions, I/O operations, time slice expiration,
and system interrupts.
8. Describe the role of the process control block (PCB) in process management.
Answer:
The Process Control Block (PCB) is a data structure used by the operating system to
store information about a process. It contains:
Process State: The current state of the process (new, ready, running, waiting, •
terminated).
Program Counter: The address of the next instruction to execute. •
CPU Registers: Stores register values when the process is not running. •
The PCB allows the OS to manage and switch between processes efficiently.
9. Explain the role of process scheduling and the types of scheduling queues used
in an operating system.
Answer:
Process scheduling ensures that multiple processes can share CPU time efficiently. It
helps maximize CPU utilization and manage task execution. The scheduler maintains
different types of queues:
Ready Queue: Holds processes waiting for CPU execution. •
Waiting Queue: Stores processes waiting for an event (e.g., I/O completion). •
Scheduling decisions determine which process moves from the ready queue to
execution.
10. What is context switching, and why is it necessary?
Answer:
Context switching occurs when the CPU switches from executing one process to
another. It is necessary for multitasking and efficient process management.
When switching, the OS must:
Save the current process's state in its PCB. .1
Load the next process's state from its PCB. .2
Resume execution of the newly scheduled process. .3
This process allows multiple processes to share CPU time, ensuring fairness and
responsiveness.
11. Explain how a process is created and terminated in an operating system.
Answer:
A process is created using system calls such as fork() in UNIX. The parent process
creates a child, which can either run the same code as the parent or use exec() to load
a new program. Each process is identified by a unique process ID (PID).
A process terminates when it finishes execution or when a parent explicitly terminates
it using abort(). The exit() system call ensures the OS deallocates resources. In some
cases, a parent process waits for a child to terminate using wait(). Some OSes enforce
cascading termination, where if a parent terminates, all child processes must also
terminate.
12. Describe the two models of Interprocess Communication (IPC) and their
differences.
Answer:
Shared Memory: Processes share a designated memory space to exchange data.
Synchronization mechanisms (e.g., semaphores) ensure proper access.
Message Passing: Processes send and receive messages via an IPC facility. .1
Message size may be fixed or variable, and OS involvement is required.
The key difference is that shared memory requires direct access and
synchronization, while message passing relies on system-managed
communication channels.
13. Explain the differences between independent and cooperating processes.
Answer:
Independent processes do not share data and execute without affecting each other.
They operate in isolation and do not rely on other processes for execution.
Cooperating processes, on the other hand, interact with each other, sharing data and
resources. They improve system efficiency through parallel execution, modularity, and
task distribution. Interprocess Communication (IPC) mechanisms, such as shared
memory and message passing, enable cooperation among these processes.
14. Describe the producer-consumer problem and how it is managed in bounded
and unbounded buffers.
Answer:
The producer-consumer problem involves two processes:
Producer: Generates data and stores it in a buffer. •
In a bounded-buffer system, the buffer has a fixed size. If the buffer is full, the
producer must wait; if empty, the consumer must wait.
In an unbounded-buffer system, the buffer has no practical size limit. The producer
never waits, but the consumer waits if there is no data to consume. Synchronization
mechanisms such as semaphores or message passing are used to coordinate access
to the buffer.
16. Describe the differences between shared memory and message passing in
interprocess communication (IPC).
Answer:
Shared Memory:
Processes communicate by reading and writing to a shared section of memory. •
It provides fast communication but requires synchronization to prevent race •
conditions.
The operating system provides mechanisms to control access to the shared •
region.
Message Passing:
Processes exchange data through explicit send and receive operations. •
It is slower than shared memory due to additional overhead but provides better •
synchronization.
Suitable for distributed systems where processes do not share physical memory. •
Both mechanisms have advantages and trade-offs, and the choice depends on system
requirements and performance considerations.
17. Explain the concept of process termination and the mechanisms provided by
an operating system for terminating a process.
Answer:
Process termination occurs when a process completes execution or is forcibly
stopped. The operating system provides several mechanisms for terminating a process:
Normal termination: A process executes its final statement and calls exit(), •
notifying the OS that it has completed.
Parent-initiated termination: A parent process can terminate a child process •
using abort() if the child exceeds allocated resources, completes an unnecessary
task, or if the parent itself is exiting.
Cascading termination: In some operating systems, when a parent terminates, •
all its child processes are also terminated.
OS-initiated termination: The OS may terminate processes due to system •
resource limits, security violations, or system shutdown.
Once a process terminates, the OS deallocates its resources and removes its entry
from process tables.