Operating System | Process Scheduler | Scheduling Queues - cook the code

Sunday 31 December 2017

Operating System | Process Scheduler | Scheduling Queues

Scheduling Queues
  • Job queue − This queue keeps all the processes in the system(
          Each new process goes into the job queue. Processes in the job  queue                reside on mass storage and await the allocation of main memory.
             )     
  • Ready queue − This queue keeps a set of all processes residing in main memory, ready and waiting to execute. A new process is always put in this queue.
  • Device queues − The processes which are blocked due to unavailability of an I/O device constitute this queue.(
                 Device Queue is the list of processes waiting for particular I/O devices.
           )
Process Scheduling Queuing


A new process is initially put in the ready queue. It waits in the ready queue until it is selected for execution(or dispatched). Once the process is assigned to the CPU and is executing, once of several events could occur.
  • The process could issue an I/O request, and then be placed in an I/O queue.
  • The process could create a new subprocess and wait for its termination.
  • The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready queue.
Scheduling Queues

Types of Schedulers




    There are three types of schedulers available :

    Long Term Scheduler :-
    The long-term scheduler, or admission scheduler, decides which jobs or processes are to be admitted to the ready queue (in main memory).
    The long-term scheduler is responsible for controlling the degree of multiprogramming.
    In general, most processes can be described as either I/O-bound or CPU-bound. An I/O-bound process is one that spends more of its time doing I/O than it spends doing computations. A CPU-bound process, in contrast, generates I/O requests infrequently, using more of its time doing computations. It is important that a long-term scheduler selects a good process mix of I/O-bound and CPU-bound processes. If all processes are I/O-bound, the ready queue will almost always be empty, and the short-term scheduler will have little to do. On the other hand, if all processes are CPU-bound, the I/O waiting queue will almost always be empty, devices will go unused, and again the system will be unbalanced. The system with the best performance will thus have a combination of CPU-bound and I/O-bound processes. In modern operating systems, this is used to make sure that real-time processes get enough CPU time to finish their tasks.
    Short Term Scheduler :-

    The short-term scheduler (also known as the CPU scheduler) decides which of the ready, in-memory processes is to be executed (allocated a CPU) after a clock interrupt, an I/O interrupt, an operating system call or another form of signal.
    Note: Short term scheduler only selects the process to schedule it doesn’t load the process on running.
    Dispatcher is responsible for loading the selected process by Short Term scheduler on the CPU (Ready to Running State) Context switching is done by dispatcher only. A dispatcher does following:
    1) Switching context.
    2) Switching to user mode.
    3) Jumping to the proper location in the newly loaded program.

    Medium Term Scheduler :-

    The medium-term scheduler temporarily removes processes from main memory and places them in secondary memory (such as a hard disk drive) or vice versa,which is commonly referred to as "swapping out" or "swapping in" (also incorrectly as "paging out" or "paging in"). The medium-term scheduler may decide to swap out a process which has not been active for some time, or a process which has a low priority, or a process which is page faulting frequently, or a process which is taking up a large amount of memory in order to free up main memory for other processes, swapping the process back in later when more memory is available.

    Scheduling Queues

    Comparison among Scheduler

    S.N.Long-Term SchedulerShort-Term SchedulerMedium-Term Scheduler
    1It is a job schedulerIt is a CPU schedulerIt is a process swapping scheduler.
    2Speed is lesser than short term schedulerSpeed is fastest among other twoSpeed is in between both short and long term scheduler.
    3It controls the degree of multiprogrammingIt provides lesser control over degree of multiprogrammingIt reduces the degree of multiprogramming.
    4It is almost absent or minimal in time sharing systemIt is also minimal in time sharing systemIt is a part of Time sharing systems.
    5It selects processes from pool and loads them into memory for executionIt selects those processes which are ready to executeIt can re-introduce the process into memory and execution can be continued.

    Context Switch

    A context switch is the mechanism to store and restore the state or context of a CPU in Process Control block so that a process execution can be resumed from the same point at a later time. Using this technique, a context switcher enables multiple processes to share a single CPU. Context switching is an essential part of a multitasking operating system features.
    When the scheduler switches the CPU from executing one process to execute another, the state from the current running process is stored into the process control block. After this, the state for the process to run next is loaded from its own PCB and used to set the PC, registers, etc. At that point, the second process can start executing.
    Process Context Switch
    Context switches are computationally intensive since register and memory state must be saved and restored. To avoid the amount of context switching time, some hardware systems employ two or more sets of processor registers. When the process is switched, the following information is stored for later use.
    • Program Counter
    • Scheduling information
    • Base and limit register value
    • Currently used register
    • Changed State
    • I/O State information
    • Accounting information

    No comments:

    Post a Comment