Introduction to Operating Systems: Unit II(a): Process Management

Process Scheduling

Process Management - Introduction to Operating Systems

CPU utilization is maximizing by using multiprogramming concept. Processor is not idle, it is executing a process. Processor scheduler selects one process for execution from the ready queue.

Process Scheduling

AU: May-18

• CPU utilization is maximizing by using multiprogramming concept. Processor is not idle, it is executing a process. Processor scheduler selects one process for execution from the ready queue.

Scheduling Queue

• Scheduling queue is processes or input-output devices. When the user process enters into the system, they put into the job queue. Job queue consists of all processes of the system.

• Operating system maintains different types of queues for different purposes. The queue are ready queue, device queue etc.Fig. 2.2.1 shows ready queue and device queue.

Ready queue: The processes which are ready and waiting to execute are kept in the ready queue. Ready queue is stored in main memory. Linked list is used for representing ready queue. Pointer field of PCB is used for this.

Device queue: Device queue is a queue for which multiple processes are waiting  for a particular I/O device. Each device has maintained its own device queue.

• Process scheduling is represented by queueing diagram. Newly created process is kept into the ready queue and waits for processor. When CPU select the process for executing, following things happens :

1. Process may require I/O device to perform operation. So it is put into the I/O queue.

2. Process may create child process and wait for child process termination.

3. Because of interrupt, process preempted from CPU and put into the ready

queue.

Schedulers

• Schedulers are used to handles process scheduling. It is one type of system software and selects the jobs from the system and decide which process to run. Schedulers are of three types -

1. Long term scheduler 2. Short term scheduler 3. Medium term scheduler

• Fig. 2.2.2 shows queueing diagram for process scheduling. (See Fig. 2.2.2 on next page.)

Long term scheduler

• Long term scheduler is also called job scheduler. It determines which process are admitted to the system for processing. Processes are selected from the queue and loads into the main memory for execution.

• Long term scheduling controls the degree of multiprogramming in multitasking systems. It provides a balanced mix of jobs, such as I/O bound and CPU bound. •Long term scheduling is used in real time operating system. Time sharing operating system has no long term scheduler.

Medium term scheduler

Medium term scheduler is part of swapping function. Sometimes it removes the process from memory. It also reduces the degree of multiprogramming.

• If process makes an I/O request and it is in memory then operating system takes this process into suspended states. Once the process becomes suspended, it cannot make any progress towards completion.

• In this situation, the process is removed from memory and makes free space for other process.

• The suspended process is stored in the secondary storage device i.e. hard disk. This process is called swapping.

Short term scheduler

• Short term scheduler is also called CPU scheduler. It selects the process from queue which are ready to execute and allocate the CPU for execution.

• Short term scheduler is faster that long term scheduler. This scheduler makes scheduling decisions much more frequently than the long-term or mid-term schedulers.

• A scheduling decision will at a minimum have to be made after every time slice, and these are very short.

• It is also known as dispatcher.

Difference between Long Term, Short Term and Medium Term Scheduler

Context Switch

• A context switch is the switching of the CPU from one process or thread to another. A context is the contents of a CPU's registers and program counter at any point in time.

• Switching the CPU to another process requires performing a state save of the current process and a state restore of a different process. This task is known as a context switch.

• A context switch can mean a register context switch, a task context switch, a mot thread context switch or a process context switch.

• A register is a small amount of very fast memory inside of a CPU that is used to speed the execution of computer programs by providing quick access to commonly used values.

• A program counter is a specialized register that indicates the position of the CPU in its instruction sequence and which holds either the address of the instruction being executed or the address of the next instruction to be executed, depending on the specific system.

• Context switching can be described in more detail as the Kernel performing the following activities with regard to processes (including threads) on the CPU:

1. Suspending the progression of one process and storing the CPU's state (i.e., the context) for that process somewhere in memory.

2. Retrieving the context of the next process from memory and restoring it in the CPU's registers and

3. Returning to the location indicated by the program counter in order to resume to the process. 

• Context switches can occur only in Kernel mode (system mode). Kernel mode is a privileged mode of the CPU in which only the Kernel runs and which provides  access to all memory locations and all other system resources.

• Other programs, including applications, initially operate in user mode, but they can run portions of the Kernel code via system calls. Software context switching an can be used on all CPUs and can be used to save and reload only the state that needs to be changed.

• To use the hardware context switch you need to tell the CPU where to save the existing CPU state and where to load the new CPU state from. The CPU state is always stored in a special data structure called a TSS (Task State Segment).

• Context switch times are highly dependent on hardware support. Context switching represents a substantial cost to the system in terms of CPU time and it can be the most costly operation on an operating system.

• There are three situations where a context switch needs to occur. They are multitasking, interrupt handling, user and Kernel mode switching.


University Question

1. Describe the difference among short-term, medium-term and long-term scheduling with suitable example.  AU: May-18, Marks 13

Introduction to Operating Systems: Unit II(a): Process Management : Tag: : Process Management - Introduction to Operating Systems - Process Scheduling