Chapter 2: Processes and Threads
1 Mark Questions:
Q. What do you understand by a thread? Q. Explain posix pthread.
Answer: POSIX stands for portable operating system interface, it is a set of standard operating system interfaces based on UNIX operating system.
POSIX threads are often referred to as pthreads. They are used for developing concurrent and parallel applications. pthreads library provides a set of functions and conventions for creating, manipulating and syncronizing threads. Q. Give examples of operating systems using pthread. Answer: Here are examples:
1) LINUX
2) UNIX
3) mac OS
4) Solaris
Q. List any two operating system examples that use a one-to-one model.
Answer: In one to one thread model, there is one to one relationship between user level thread to a kernel level thread. Each user thread maps to a kernel thread.
Example: Windows NT, Windows 2000. Q. List any two examples of the many-to-many model.
Answer: In many to many model, many user level threads multiplex to the kernel thread of smaller or equal numbers.
Examples of Operating systems : Solaris 2, IRIX,etc.
Q. Define multiprocessor system.
Answer: A multiprocessor system, also known as a parallel processor system, is a computer system that uses more than one central processing unit (CPU) to perform tasks. In a multiprocessor system, multiple CPUs share the processing load and work together to execute programs and handle data.
Q. What is job queue?
Answer: It keeps all the processes in the system. As the process enters in the system, it enters the job queue. Q. What is the ready queue?
- It keeps a set of all processes residing in main memory, ready and waiting to execute. When a process is ready to execute, it is moved to the ready queue, and operating system's scheduler selects a process from the ready queue to run on CPU. Q. Write advantages of multiprocessor system.
Answer: Multiprocessor systems advantages are: 1) Increased Performance:By distributing the workload among multiple processors, tasks can be executed concurrently, leading to faster computation and reduced overall processing time. 2) Scalability: Multiprocessor systems are scalable, meaning that additional processors can be added to the system to handle increasing workloads. 3) Enhanced Reliability: Multiprocessor systems can be designed with redundancy and fault tolerance mechanisms. If one processor fails, the remaining processors can continue to operate. 4) Parallel Processing: Multiprocessor systems enable parallel processing, where multiple tasks can be executed simultaneously. 5) Cost-Effectiveness: In certain scenarios, a multiprocessor system can be more cost-effective than deploying multiple single-processor systems. Q. State scalability and responsiveness benefits of multithreading.
Answer: Scalability Benefits of Multithreading: 1) Efficient workload distribution across multiple threads. 2) Improved performance on multicore processors. 3) Better resource utilization, especially in parallelizable tasks. Responsiveness Benefits of Multithreading: 1) Enhanced user experience, particularly in GUIs. 3) Asynchronous operations prevent blocking and waiting. 4) Parallelism for heavy tasks maintains responsiveness. Q. What is context switching? State conditions when context switching occurs.
- Context switching is process of saving the state of a process in PCB and loading the state of another process from another PCB. It is used in multitasking operating system. It enables multiple processes to share a single CPU.
Conditions when it occurs:
1) Interrupt : When an interrupt occurs (Hardware- I/o Completion or Software: system call), a context swtich is performed to handle the interrupt.
2) Blocking/Waiting: When a process is waiting for an event, it gives up CPU, the operating system performs a context switch to allow another process to execute.
3) Process termination: When process completes its execution, context switch is performed to release its resources.
4) Process switching: When process requests to yield the CPU to switch to another process, a context switch occurs.
5) Priority Changes: If higher priority process becomes ready to run. Q. Explain any two benefits of multithreaded programming.
- Answer: Benefits of multi threaded programming are:
1) Improved responsiveness: Since multiple threads execute at a time, allowing system to continue processing tasks even when one thread is blocked or waiting for resources.
2) Increased throughput or performance: It allows leveraging of available resources more effectively. Multiple threads can take advantage of multiple CPU cores or processors, distributing work completion in parallel. Q. What is the primary function of the medium-term scheduler?
Answer: The medium-term scheduler is essential for maintaining a balance between the number of processes in main memory and the available resources. The medium-term scheduler is responsible for deciding which processes should be moved into or out of the main memory (RAM). When a process is in the "swapped out" state, it is stored on secondary storage (like the hard disk), and when it is "swapped in," it is brought back into the main memory for execution. 4 Mark Questions: Q. Explain many-to-many multithreaded model.
Answer: It is a threading model that combines features of both the one-to-one and many-to-one models. In this model multiple user level threads are mapped to an equal or smaller number of kernel level threads. The number of threads may be specific to either a particular application or particular machine. Q. Explain PCB with a proper diagram.
Answer: Each process in an operating system is represented by a Process Control Block (PCB) or Task Control Block (TCB).
-The operating system uses PCB data structure to manage information about a running process.
-It stores information about the process like its state, program counter, memory management, allocated resources, scheduling, etc. required to control and manage a particular process.
Preemptive vs. Non-Preemptive Scheduling
Aspect | Preemptive Scheduling | Non-Preemptive Scheduling |
---|---|---|
Interrupts | Allows forced interruption of running processes. | Does not forcibly interrupt running processes. |
Response Time | Better for high-priority tasks due to immediate scheduling. | May result in higher response times for high-priority tasks. |
Fairness | Provides fairness by preventing process monopolization. | May be less fair as long-running tasks can monopolize the CPU. |
Complexity | Can be more complex due to handling interruptions. | Simple to implement without interruption handling. |
Answer: A process is an instance of a computer program that is being executed by one or many threads. It is the basic unit of execution in a computer system. Each process has its own memory space, resources, and state.
Following are the types of process states:
1) New: It is the initial state when a process is first created. In this state, process is being initialized and not being executed.
2) Ready: It is the state when process is ready for execution, and loaded onto the main memory. It is waiting to be allocated a CPU to it.
3) Running : It is the state when process is selected for execution by the schedular. Now CPU has been allocated to it and it is currently being executed.
4) Blocked or Waiting: It is the state when the process has to wait for a particular event (such as user input) before it can proceed it's execution. Unless that event occurs, process cannot continue it's execution.
5) Terminated : It is the state when process has finished its execution. Now the process releases all of its allallocated resources, and operating system removes it from process table.
Q. Write a note on multilevel queue scheduling. Answer:
Q. What do you understand by a thread? Answer: It is the smallest unit of execution within a process in multi tasking operating system. It is a light weight sub process that shares same resources as its parent processs. They allow multiple operationgs to be performed concurrently within a single process. They are generally used in applications where parallel processing is beneficial like GUI network programming.
Q. Define independent and dependent processes.
Answer:
Independent Processes: Independent processes are those that do not rely on or affect the execution of other processes. Each independent process can run concurrently without any dependencies on the state or output of other processes. Dependent Processes: Dependent processes, on the other hand, have interdependencies, meaning that the execution or outcome of one process is contingent upon the behavior or results of another. Dependencies can involve sharing data, resources, or specific execution sequences. Q. Explain multilevel feedback queue scheduling with a diagram.
Answer: Q. Differentiate between user-level thread and kernel-level thread.
User-Level Threads vs. Kernel-Level Threads
Aspect | User-Level Threads | Kernel-Level Threads |
---|---|---|
Management | Managed by user-level threading library or runtime environment. | Managed by the operating system kernel. |
Responsiveness | May be faster and more lightweight for thread creation and switching. | Offers better responsiveness as the kernel can make scheduling decisions based on individual threads. |
Concurrency | Limited concurrency within a process since the kernel sees the entire process as a single-threaded entity. | Enables true concurrency, allowing threads within the same process to execute in parallel. |
Kernel Awareness | The kernel is unaware of individual user-level threads. | The kernel is aware of and manages individual threads within a process. |
Portability | Highly portable across different operating systems. | May have variations in efficiency depending on the underlying operating system's threading support. |
Resource Usage | Less resource-intensive, but limited parallelism. | May be more resource-intensive due to kernel involvement but allows for greater parallelism. |
Answer:
Difference Table
Characteristic | Short-Term Scheduler (CPU Scheduler) | Medium-Term Scheduler | Long-Term Scheduler (Job Scheduler) |
---|---|---|---|
Scope | Deals with the selection of processes in the ready queue for execution. | Handles the swapping of processes in and out of main memory. | Selects processes to be admitted to the ready queue. |
Frequency of Execution | Executes frequently, often in milliseconds or microseconds. | Executes less frequently than the short-term scheduler. | Executes the least frequently as it involves admitting processes. |
Time Horizon | Very short-term, focusing on the immediate execution of processes. | Medium-term, involving the swapping of processes in and out of main memory. | Long-term, considering overall system performance and resource availability. |
Decision Criteria | Based on factors like burst time, priority, and fairness. | Considers factors like process size, I/O intensity, and priority. | Based on factors such as overall system workload, memory, and CPU utilization. |
Goal | To optimize CPU utilization and throughput. | To manage the degree of multiprogramming in the system, ensuring a balance between CPU and I/O-bound processes. | To maintain a balance between system performance and fairness in admitting new processes. |
Example | Short-Term Scheduler (Round Robin, Priority Scheduling) | Medium-Term Scheduler (Swapper) | Long-Term Scheduler (Admission Control Algorithm) |
Q. Write advantages of multiprocessor system. Answer:
A. Increased Processing Power:
Multiprocessor systems can handle multiple tasks simultaneously, boosting overall processing power.
B. Improved Throughput:
Tasks are executed concurrently, enhancing system throughput and responsiveness.
C. Scalability:
The system can grow in power by adding more processors, adapting to increasing workloads.
D. Enhanced Reliability:
Redundancy minimizes the impact of hardware failures, improving system reliability.
E. Better Resource Utilization:
Multiple processors efficiently use resources by working on independent tasks.
F. Parallel Processing:
Multiprocessors excel at parallel execution, providing significant speedup for certain computations.
G. Efficient Multitasking:
Different processors handle various tasks simultaneously, making multitasking smoother.
H. Cost-Effectiveness:
Shared resources and scalability often result in cost-effective solutions compared to single-processor systems.
Q. List any two advantages of multithreaded programming.