0% found this document useful (0 votes)
5 views

OS lecture-3

The document provides a comprehensive overview of processes in operating systems, including definitions, states, and components such as the Process Control Block (PCB). It covers various aspects of process management, including scheduling, memory allocation, and interprocess communication. Additionally, it includes true/false questions and essay prompts to assess understanding of the material.

Uploaded by

medo43005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

OS lecture-3

The document provides a comprehensive overview of processes in operating systems, including definitions, states, and components such as the Process Control Block (PCB). It covers various aspects of process management, including scheduling, memory allocation, and interprocess communication. Additionally, it includes true/false questions and essay prompts to assess understanding of the material.

Uploaded by

medo43005
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Process

1. What defines a process in an operating system?


A) A program stored on disk
B) A program in execution
C) A function executing in parallel
D) A program in cache memory
Answer: B
2. Which of the following best describes a passive entity in an OS?
A) Process
B) Thread
C) Program
D) Register
Answer: C
3. What section of a process stores dynamically allocated memory during runtime?
A) Stack
B) Data section
C) Heap
D) Text section
Answer: C
4. The stack in a process mainly contains which type of data?
A) Global variables
B) Function parameters and return addresses
C) Heap allocations
D) Program instructions
Answer: B
5. Which process state indicates that instructions are being executed?
A) Ready
B) Waiting
C) Running
D) New
Answer: C
7. What is the role of the program counter in a process?
A) Stores process execution time
B) Tracks the current process state
C) Holds the address of the next instruction to execute
D) Manages memory allocation
Answer: C
8. Which of the following is NOT stored in the Process Control Block (PCB)?
A) Process ID
B) Program counter
C) CPU registers
D) Disk space allocation
Answer: D
9. In which state is a process waiting for an event to occur?
A) Running
B) Ready
C) New
D) Waiting
Answer: D
10. Which of the following statements about process execution is correct?
A) A process can execute multiple instructions in parallel.
B) A process can only transition from the running state to the new state.
C) A process execution progresses sequentially.
D) A process does not require a PCB.
Answer: C
11. What structure represents a process in the Linux operating system?
A) task_struct
B) PCB_Table
C) process_struct
D) process_control
Answer: A
12. What information is NOT stored in the task_struct structure?
A) Process state
B) Open files list
C) Parent and child process pointers
D) User interface settings
Answer: D
13. What is the main purpose of the process scheduler?
A) To allocate memory to a process
B) To determine which process gets CPU time next
C) To manage disk space allocation
D) To keep track of open files
Answer: B
14. The ready queue in process scheduling contains:
A) Processes waiting for I/O operations to complete
B) Processes ready and waiting to execute
C) Processes that have been terminated
D) Processes that are currently executing
Answer: B
15. What happens when a process issues an I/O request?
A) It is placed in the ready queue
B) It is terminated
C) It is placed in an I/O wait queue
D) It continues executing until the I/O completes
Answer: C
16. What does the process scheduler use to manage processes waiting for execution?
A) Memory table
B) Ready queue
C) File system
D) Cache memory
Answer: B
17. What happens when a process's time slice expires?
A) It is placed back into the ready queue
B) It continues running indefinitely
C) It is moved to the terminated state
D) It is deleted from memory
Answer: A
18. What is the function of a wait queue?
A) Stores terminated processes
B) Holds processes waiting for an event (e.g., I/O completion)
C) Executes processes in the background
D) Allocates additional CPU time to running processes
Answer: B
19. Which event can move a process from the waiting state to the ready queue?
A) The process completes its execution
B) An interrupt occurs, preempting another process
C) The process terminates another process
D) The event it was waiting for occurs (e.g., I/O completion)
Answer: D
20. What is the primary purpose of a context switch?
A) To allocate additional memory to a process
B) To switch the CPU from executing one process to another
C) To remove a process from execution permanently
D) To increase the CPU's clock speed
Answer: B
21. What is the purpose of the task_struct in the Linux operating system?
A) Stores system-wide kernel settings
B) Represents process-related information, including state and scheduling details
C) Manages virtual memory allocations only
D) Keeps a record of all executed commands
Answer: B
22. Which of the following is NOT included in a Process Control Block (PCB)?
A) Process state
B) Program counter
C) CPU scheduling information
D) System clock frequency
Answer: D
23. What happens when a process creates a new child process?
A) The child process is immediately terminated
B) The parent process moves to the terminated state
C) The parent may move to the waiting state until the child terminates
D) The parent process takes over the CPU entirely
Answer: C
24. What does the process scheduler aim to achieve?
A) Maximize CPU utilization and switch processes efficiently
B) Ensure each process runs indefinitely
C) Minimize memory usage by blocking processes
D) Convert processes into kernel threads
Answer: A
25. When an interrupt occurs, what must the operating system do first?
A) Immediately terminate the current process
B) Ignore the interrupt if the process is important
C) Save the current process’s state for later restoration
D) Delete the process's PCB
Answer: C
26. Why is context switch time considered overhead?
A) It improves the CPU’s performance
B) No useful work is done while switching
C) It speeds up the execution of the current process
D) It reduces the number of processes in the system
Answer: B
27. What is a major factor affecting the speed of context switching?
A) Number of registers to copy
B) Number of processes in the system
C) Number of CPU cores
D) Size of the hard disk
Answer: A
28. Which system call creates a new process in UNIX?
A) exec()
B) exit()
C) fork()
D) abort()
Answer: C
29. What does the exec() system call do?
A) Creates a new process
B) Terminates the process
C) Replaces the process’s memory space with a new program
D) Allocates additional resources to the process
Answer: C
30. What happens when a parent process terminates in an OS that does not allow
orphan processes?
A) The child process continues running independently
B) The system assigns the child process to another parent
C) All child processes are terminated (cascading termination)
D) The system restarts the parent process
Answer: C
31. What is the purpose of the wait() system call in process management?
A) To create a new process
B) To wait for an I/O operation to complete
C) To suspend a process indefinitely
D) To make a parent process wait for its child’s termination
Answer: D
32. In process creation, what happens when the fork() system call is executed?
A) A new process is created
B) The parent process is terminated
C) The child process starts executing a new program immediately
D) The child process waits for user input before execution
Answer: A
33. What is cascading termination?
A) Termination of a single process
B) Termination of all child processes when a parent process terminates
C) Termination of only orphaned processes
D) Immediate termination of all processes in the system
Answer: B
34. Which of the following is NOT a reason for a parent process to terminate a child
process?
A) The child process has exceeded allocated resources
B) The child process has completed execution
C) The parent process is exiting and does not allow child processes to continue
D) The parent process has no more resources to allocate
Answer: B
35. In a producer-consumer system, what happens in a bounded-buffer scenario when
all buffers are full?
A) The producer process must wait
B) The consumer process must wait
C) Both processes continue executing without delay
D) The producer process discards excess data
Answer: A
36. What is the main drawback of context switching?
A) It improves CPU execution time
B) It consumes additional CPU cycles without performing useful work
C) It increases the efficiency of process execution
D) It eliminates the need for scheduling algorithms
Answer: B
39. In message passing, which operation is used to send data from one process to
another?
A) write()
B) send()
C) exec()
D) fork()
Answer: B
41. What is the purpose of the wait() system call in process management?
A) To pause a process indefinitely
B) To wait for a child process to terminate
C) To terminate the parent process
D) To allocate memory dynamically
Answer: B
42. What happens to a child process if its parent terminates in an OS that enforces
cascading termination?
A) The child process continues execution
B) The child process is terminated automatically
C) The child process is promoted to a parent process
D) The child process is paused until reassigned
Answer: B
43. In a cooperating process model, which of the following is NOT a reason for process
cooperation?
A) Information sharing
B) Computation speedup
C) Preventing context switching
Answer: C
44. What is the key difference between an unbounded buffer and a bounded buffer in
IPC?
A) An unbounded buffer has unlimited space, while a bounded buffer has a fixed size
B) An unbounded buffer allows only one producer and consumer
C) A bounded buffer cannot be used in IPC
D) A bounded buffer dynamically expands when full
Answer: A
45. Which of the following best describes message passing in IPC?
A) It requires processes to communicate using shared memory
B) It allows processes to exchange messages using send() and receive() operations
C) It forces processes to execute sequentially
D) It is slower than shared memory but ensures automatic synchronization
Answer: B

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

Stack: Holds temporary data, including function parameters, return addresses, •


and local variables.
Data section: Stores global variables, further divided into initialized and •
uninitialized data.
Heap: Allocates memory dynamically during runtime. •

3. What are the different process states in an operating system?


Answer:
A process goes through the following states:
New: The process is being created. •

Ready: The process is waiting to be assigned to a CPU. •

Running: The process is currently executing instructions. •


Waiting: The process is waiting for an event (e.g., I/O operation). •

Terminated: The process has completed execution and is removed from •


memory.
4. What is a Process Control Block (PCB) and what are its main components?
Answer:
A Process Control Block (PCB) is a data structure used by the operating system to store
information about a process. The main components of a PCB include:
Process State: Indicates whether the process is new, ready, running, waiting, or •
terminated.
Program Counter: Stores the address of the next instruction to be executed. •

CPU Registers: Includes various registers needed for execution, such as •


accumulators and stack pointers.
CPU Scheduling Information: Contains details like process priority and •
scheduling queue pointers.
Memory Management Information: Stores memory allocation details. •

Accounting Information: Tracks CPU usage, execution time, and other process- •
related statistics.
I/O Status Information: Lists allocated I/O devices and open files. •

5. Explain the purpose of scheduling queues in process management.


Answer:
Scheduling queues are used to manage process execution efficiently in an operating
system. The key types of queues include:
Ready Queue: Contains processes that are ready to execute and waiting for CPU •
allocation.
Wait Queues: Contain processes that are waiting for an event, such as I/O •
completion.
Processes transition between these queues based on CPU availability, I/O requests,
and interrupts. The use of scheduling queues ensures optimal CPU utilization and fair
process execution.
6. Describe the role of interrupts in process execution and context switching.
Answer:
Interrupts play a crucial role in managing process execution by allowing the OS to
respond to external and internal events. When an interrupt occurs:
The OS saves the current process's state in its PCB. •

The kernel handles the interrupt by executing the appropriate routine. •

A context switch may occur if another process is scheduled to run. •

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

Ready: The process is waiting for CPU allocation. •

Running: The process is currently executing. •

Waiting: The process is waiting for an event (e.g., I/O completion). •

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

Memory Management Information: Information about allocated memory. •

Scheduling Information: Process priority and scheduling queue pointers. •

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

Consumer: Retrieves data from the buffer and processes it. •

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.

You might also like