Thursday 31 January 2013

Linux scheduler

The most fundamental part of any operating system is its scheduler which manages all the processes (tasks) in the OS.
If you look into /usr/src/linux-headers/include/linux ,you will find all the system files which makes up the kernel .Here search for sched.h ;This would be our scheduler and if you open it in a text editor,you will find a task_struct structure.

 This represents the process control block(PCB) which is a datastructure holding all essential details of a process

you can view a partial PCB of a process by
$ cat /proc/pid/status  

here pid is the process id of the process ,whose status you want to view.



PCB is composed of all details needed for running a process along with details of resources which a process has access to,and the scheduler uses it for context switching or switching between process for CPU access .


Kernel keeps a list of process descriptors wherin a doubly linked circular list is maintained ,this linked list is composed of all process descriptors including the init.


Here each block is a PCB for that task, Now the scheduler needs to make a list of tasks which are ready to be executed.The ready queue is implemented in this circular linked list itself .


Here the scheduler just have to know the pointer to the beginning of the queue and to the end.The red arrows indicate the pointer from 1 PCB to the next in the ready queue.Similarly a wait queue can be maintained just by managing pointers in the PCB.The next process to be run is determined  by Struct task_struct *next_run; 


Source codes for scheduling algorithms using pthreads in c are available here

No comments:

Post a Comment