Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 4.6 KB

Process_thread_scheduling.md

File metadata and controls

54 lines (37 loc) · 4.6 KB

OS Scheduling

Scheduler and dispatcher

Dispatcher

Scheduling algorithm/policy

Context Switch

What is PCB (process control block)?

Information associated with each process(also called task control block).Entry of the Process Table, Task Struct, or Switchframe) is a data structure in the operating system kernel containing the information needed to manage the scheduling of a particular process.

  • 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

https://www.geeksforgeeks.org/process-table-and-process-control-block-pcb/

What is TCB (Thread control block)?

Very similar to Process Control Blocks (PCBs) which represents processes, Thread Control Blocks (TCBs) represents threads generated in the system. It contains information about the threads, such as it’s ID and states.

The components have been defined below:

  • Thread ID: It is a unique identifier assigned by the Operating System to the thread when it is being created. Thread states: These are the states of the thread which changes as the thread progresses through the system
  • CPU information: It includes everything that the OS needs to know about, such as how far the thread has progressed and what data is being used.
  • Thread Priority: It indicates the weight (or priority) of the thread over other threads which helps the thread scheduler to determine which thread should be selected next from the READY queue.
  • A pointer which points to the process which triggered the creation of this thread.
  • A pointer which points to the thread(s) created by this thread.

https://www.geeksforgeeks.org/thread-control-block-in-operating-system/?ref=rp

Scheduling criterias

  • CPU utilization. We want to keep the CPU as busy as possible. Conceptually, CPU utilization can range from 0 to 100 percent. In a real system, it should range from 40 percent (for a lightly loaded system) to 90 percent (for a heavily used system).
  • Throughput. If the CPU is busy executing processes, then work is being done. One measure of work is the number of processes that are completed per time unit, called throughput.
  • Turnaround time. From the point of view of a particular process, the important criterion is how long it takes to execute that process. The interval from the time of submission of a process to the time of completion is the turnaround time. Turnaround time is the sum of the periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/0.
  • Waiting time. The CPU-scheduling algorithm does not affect the amount of time during which a process executes or does I/0, it affects only the amount of time that a process spends waiting in the ready queue. Waiting time is the sum of the periods spent waiting in the ready queue.
  • Response time. Time from the submission of a request until the first response is produced. This measure, called response time, is the since it takes to start responding, not the time it takes to output the response.

Benefits of multithreading

Benefits of multithreaded programming can be broken down into four major categories:

  • Responsiveness. Multithreading an interactive application may allow a program to continue running even if part of it is blocked or is performing a lengthy operation, thereby increasing responsiveness to the user.
  • Resource sharing. Processes may only share resources through techniques such as shared memory or message passing. Such techniques must be explicitly arranged by the programmer. However, threads share the memory and the resources of the process to which they belong by default.
  • Economy. Allocating memory and resources for process creation is costly. Because threads share the resources of the process to which they belong, it is more economical to create and context-switch threads. Empirically gauging the difference in overhead can be difficult, but in general, it is much more time consuming to create and manage processes than threads.
  • Scalability. The benefits of multithreading can be greatly increased in a multiprocessor architecture, where threads may be running in parallel on different processors. A single-threaded process can only run on one processor, regardless how many are available. Multithreading on a multiCPU machine increases parallelism