Truth, Computing and Fail

  • Home
  • About

Round robin process scheduling simulation

anomit | September 11, 2008

No big deal. Everyone has to do it once for their UNIX concepts practical work I guess. What irked me was that the teacher and some of the ‘good students’ were hell bent on arguing that non-preemptive process scheduling simulations do not require any kind of data regarding the arrival time of processes in the ready queue. I still don’t understand how that simulates a real life scenario, that is, after the completion of a process, to which other process would the scheduler perform a context switch. Could someone point me out if I am missing something here?

Anyways, this is the code I wrote today during the practical class:

#include<stdio.h>

struct processinfo

{

        int id;

        int burst;

        int arr;

};

typedef struct processinfo process;

/*checks if all the processes have finished execution*/

int check(process* p,int n)

{

        int i=0,flag=0;

        for(i=0;i<n;i++)

        {

                if(p[i].burst!=0)

                {

                        flag=1;

                        break;

                }

        }

        return flag;

}

int main()

{

        int n;

        printf("No. of processes:");

        scanf("%d",&n);

        process p[n];

        int i=0,j=0;

        int wt[n]/*the waiting time array*/,last[n]/*last[i] stores the last executed instant of the process i*/;

        for(i=0;i<n;i++)

        {

        	printf("Proccess id:");

        	scanf("%d",&p[i].id);

                printf("Arrival time:");

                scanf("%d",&p[i].arr);

                printf("Burst time:");

                scanf("%d",&p[i].burst);

                wt[i]=0;

                last[i]=0;

        }

        /*gah, bubble sort*/

       /*anyways we won't be doing any sorting in a real scheduler, I guess*/

        for(i=0;i<n-1;i++)
		{

        	for(j=i+1;j<n;j++)

        	{

                if(p[j-1].arr>p[j].arr)

                {

                 process temp=p[j-1];

                 p[j-1]=p[j];

                 p[j]=temp;

                }

        	}

		}

int timequantum=2/*the time quantum*/,time=0/*running time*/;

while(1)

{

        if(!check(p,n))

                break;

	int k=0;

for(k=0;k<n;k++)

{

        if(p[k].burst!=0)

        {

                if(p[k].burst<timequantum)

                {

                        wt[k]+=time-last[k];

                        time+=p[k].burst;

                        p[k].burst=0;

                }

                else

                {

                        p[k].burst-=timequantum;

                        wt[k]+=time-last[k];

                        time+=timequantum;

                }
                last[k]=time;
        }

}

 }//end of while

for(i=0;i<n;i++)

	printf("\nWaiting time for Process %d:%d",p[i].id,wt[i]);

return 0;

}
Categories
Coding, GNU/Linux
Tags
scheduler, unix
Comments rss
Comments rss
Trackback
Trackback

« Just what I have been saying Wuss R Us »

2 responses

Well the arrival time of the process is of no

Ankit | October 8, 2008

Well the arrival time of the process is of no use unless you are aiming for deadlines or preemption, or deferred scheduling. Linux kernel does not in fact use arrival time, except in RT scheduling.

Coming from you, I'd accept it for the time being.

anomit | October 8, 2008

Coming from you, I’d accept it for the time being. I’d really like to find some time and learn more about this.

PS: Welcome to my blog! :)

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

What’s in

  • Apologies
  • Examining the Linux VDSO
  • Symlinks in a libfs virtual file system: The Pains
  • Small rant on the FUSE API reference
  • Kernel module debugging: a simple technique

Blogroll

  • Akshay Kothari
  • Ankur Shrivastav (OS)
  • Ankur Sinha
  • Harsh J
  • Hullap
  • LUG manipal
  • Swap

Tags

aircrack airfail airtel assembly blues build c Coding college country cryptography dean faculty file systems fuckery gnuplot hacking India kernel linux mangalore manipal mpd music NASM plugin politicians pub culture python rant rock sam scheduler simulation SSFNet stupidity supernatural suppression syscall syscalls system calls unix vim xchat xml

Archives

  • December 2010
  • April 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • January 2009
  • November 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • October 2007
  • September 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007

License

Creative Commons License
This work by Anomit Ghosh is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 India License.
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox