Docstoc
EXCLUSIVE OFFER FOR DOCSTOC USERS
Try the all-new QuickBooks Online for FREE.  No credit card required.

DISK SCHEDULING

Document Sample
DISK SCHEDULING Powered By Docstoc
					                       ACKNOWLEDGEMENT

      The satisfaction and euphoria that accompany the successful completion of any
task would be but incomplete without the mention of the people who made it possible
whose constant guidance and encouragement crowned our efforts with success.

Firstly I would like to thank god for his blessing to all on earth.


       We wish to place on record our grateful & sincere thanks to Mr. Channakeshava
Principal of the S.S.P.T, and Tiptur for providing us the facility and support.

     We convey our sincere regards to our project guide Miss.Santhosh Kavitha
M.N Department of Computer science for her encouragement and guidance.

We are very grateful to

    Mrs. Gayathri V
    Mrs. Tulase
    Mr. Girish S

       We would also like to mention our special thanks to all staff members and lab
assistants of, Department of Computer science for their support.

      We consider our privilege to express our gratitude and respect to all those who
guided as in the completion of this project.

      Last but not the least we would like to thank our family members, our friends
and well wishers for their valuable help and time they spared in making things easier
and possible.




                                                                                   1
CONTENTS

Synopsis

Introduction

Hardware and Software Requirements

About ‘C’

Algorithms of Disk Scheduling


            1.   FCFS
            2.   SSTF
            3.   SCAN
            4.   C-SCAN

Graphical Notation of Algorithms

Software Implementations

            1. Source code


Snap Shots

Conclusion

Limitations and Scope for Improvements

Bibliography




                                         2
                                    SYNOPSIS

       This project is about “Disk Scheduling”. Disk scheduling means selecting
one of the I/O request out of number of requests made by a number of processes for
servicing.


       When some data has to be writer in to or read from the disk, it issues a system
call to the operating system. This system call will contain information about the type
of the operation (read/write), address of data on the disk, address of main memory
and the number of bytes to be transferred. If the I/O devices are free the request is
serviced, other wise such a request is placed on the separate queue for servicing later.


       If the desired disk drive and controller are available, the request can be
serviced immediately. If the drive or controller is busy, any new requests for service
will be placed on the queue of pending requests for the drive, for a multi
programming system with many process, the disk queue may often have several
pending request. Thus, when one request is completed the operating system chooses
which pending request to service next. This is called scheduling.


In this project we have implemented four algorithm of disk scheduling they are

             1. First Come First Served Scheduling (F C F S).
             2. Shortest Seek Time First (S S T F).
             3. SCAN Scheduling.
             4. Circular SCAN Scheduling (C-SCAN)


       ‘C’ language is used to develop this project because of its facility of graphics
routine. This project is used to illustrate each of the algorithms that are used in
operating system process.

                                                                                       3
   HARDWARE AND SOFTWARE CONFIGURATION


Software Constraints:

             Turbo C and Graphics Routines.

Hardware Constraints:

     Input                     :    104 keys keyboard.

     Memory requirements       :    32 MB RAM.

     Processor Required        :    Pentium and Higher derivatives.

     Hard Disk                 :    10 GB

     Floppy Disk               :    1.44 MB

     O/S Required              :    Windows 95 or higher derivatives.

     Display                   :    EGA/VGA compatible color.

     Printer                   :    132 column Dot Matrix and Ink jet
                                    printer of any make.




                                                                        4
5
                                   ABOUT ‘C’
      C is a programming language developed at At and T's Bell laboratories of USA
in 1972. It was designed and written by a man named Dennis Ritchie. C can begin to
replace the more familiar languages of that time like PL/I, ALGOL etc.
      Possibly why c seems so popular is because it is reliable, simple and easy to use
.C is a procedural oriented program (pop).

Where C stands:

 All the programming languages can be divided into two categories:


      A) Problem oriented languages or High level languages: These languages have
          been designed to give a better programming efficiency, i.e. faster program
          development


      B) Machine oriented languages or Low level languages: These languages have
          been designed to give a better machine efficiency, i.e. faster program
          execution.
      C stands in between these two categories. That’s why it is often called a Middle
level language, since it was designed to have both: a relatively good programming
efficiency (as compared to machine oriented languages) and relatively good machine
efficiency (compared to problem oriented languages).

Macro used:
      Preprocessor is a program that processes our source program before it is
passed to the compiler. Different type’s pf preprocessor directives are:

             1) Macro expansion
             2) File inclusion
             3) Conditional compilation
             4) Miscellaneous directives


                                                                                     6
File inclusion:
       This directive causes one file to be included in another. Syntax of header file
inclusion #include (directive)


Treats text in the file specified by filename as if it appeared in the current file.
        Syntax :
              #include "filename"
              #include <filename>


       #include "filename"          searches the source path first, then the include path.
       #include <filename>          does not search the source directory.


        Examples:
              #include <stdio.h>
              #include "main.h"


Some of the header files used:-


              1) #include<stdio.h>
              2) #include<conio.h>
              3) #include<math.h>
              4) #include<stdlib.h>
              5) #include<time.h>
              6) #include<ctype.h>
              7) #include<dos.h>
              8) #include<graphics.h>




                                                                                         7
1)       #include<stdio.h>:-
stdio.h Defines types and macros needed for the Standard I/O Package defined in
Kernighan and Ritchie and extended under UNIX                     System V. Defines the standard
I/O predefined streams stdin,
         stdout, stdprn, and stderr, and declares stream-level I/O routines.


The functions of STDIO.H used
fclose    getc       getchar       gets      getw       printf     putc    putchar    puts
putw     scanf


2)       #include<conio.h>:-
conio.h Declares various functions used in calling the DOS console


I/O routines.
The functions of conio.h used
          cgets           clrscr      cprintf       cputs        cscanf    getch     gettextinfo
 gotoxy           putch        textbackground               textcolor textmode


3) #include<math.h>:-
math.h Declares prototypes for the math functions, defines the macro HUGE_VAL,
and declares the exception structure used by matherr.
The functions of math.h used
         pow()     sqrtA()

4)       #include<graphics.h>:-
graphics.h    Declares prototypes for the graphics functions.
The functions of graphics.h are           arc bar circle cleardevice clearviewport
closegraph getbkcolor getcolor
imagesize initgraph line
                                                                                                   8
5) #include<ctype.h>:-
ctype.h    Contains information used by the character classification and character
conversion macros.
The functions of ctype.h are
toascii    tolower      toupper



6) #include<stdlib.h>:-
stdlib.h Declares several commonly used routines: conversion routines, search/sort
routines, and other miscellan
   The functions of stdlib.h used exit abort

7) #include<time.h>:-
time.h Defines a structure filled in by the time-conversion routines, and a type used
by other time routines; also provides prototypes for these routines.


The functions of time.h used clock    ctime time

8) #include<dos.h>:-
dos.h Defines various constants and gives declarations needed for DOS and 8086-
specific calls.




closegraph():-
This function unloads the graphics driver and restorecrtmode()takes the screen back
to the mode that existed prior to calling of initgraph(),which in our case is the text
mode.
initgraph():-
To switch over to the graphics mode that offers the best resolution we need to call the
function initgraph().



                                                                                     9
setlinestyle():-
To be able to draw lines of different styles we must use the function setlinestyle().Its
prototype looks likethis
                        setlinestyle(type,pattern,thickness);
setcolor():-
Sets the current color.
rectangle():-
Draws a rectangle.
setfillstyle():-
We fill pattern and the fill color can be restored through a call setfillstyle().
                        yntax:-setfillstyle(old.pattern,old.color);
bar():-
bar() function is used to fill a rectangular area with a pattern and thenenclosedit by
calling the rectangle()function.
outtextxy():-
setbkcolor():-
settextstyle():-
The function settextstyle function settextstyle() enables us to change the font,direction
and charactersize.      Turbo provides us with ten fonts in addition
to the default font. These are iplex,small,Sansserif,Gothic,script,Simplex,triplex
script,Complex,europian and bold.we can output the text either horizontally(default)
or vertically.
          he general form of settextstyle () function is given below,


                        settextstyle (font, direction,point size)


setviewport():-
Limits graphic output & positions the logical origin within the limited area.



                                                                                      10
line():-
We drew a line using the line() function.the coordinates passed to this functions were
with respect to the origin(0,0)     ,represented by the pixel at the top-left corner of the
screen.
printf():-
It is a formated console i/o functions used to print formatted out put statements on
the screen.
       general syntax of printf("format string",list of variables);

loops:-
The versatility of the computer lies in its ability to perform a set of instructions
repeatedly. This involves repeating some portion of the program either a specified
number of times or until a particular condition is being satisfied. This repetitive
operation is done through a loop control structure.
There are 3 methods by way of it we can repeat a part of a program. They are:

              1.using a for statement
              2.using a while statement
              3.using a do-while statement




                                                                                        11
1. for loop:-
The for loop allows us to specify 3 things about a loop in a single line:
              a) Setting a loop counter to an initial value.
              b) Testing the loop counter to determine whether its value has reached
                 the number of repitions desired.
              c) Increasing the value of loop counter each time the program segment
                 within the loop has been executed .
                     The general form of for statement is
                     for (initialise counter ; test counter ; increment counter )
                     {
                            -------
                            -------
                     }

2) while loop:
The while loop is entry control loop which is used to execute repeatedly part of
program number of times.
                     The general syntax of while loop is
                     initialise loop counter ;
                     while (test loop counter using a condition)
                     {
                            -------
                            -------
                            increment loop counter ;
                     }




                                                                                    12
3. do-while loop:-
The while loop is the exit control loop which is used to execute repetedlly part of the
program. if the condition is false then also this executed the program atleast once.
       The general form of do-while loop is
               do
               {
                      -------------------
                      -------------------
                      ---------------------
               } while (condition);
pow():-
This function is used to calculates a value raised to a power.
setbkcolor():-
       This function is used to specifying the color to set.
       For example, if you want to set the background color to blue, you can call
       setbkcolor(BLUE) /* or */ setbkcolor(1)
       On CGA and EGA systems, setbkcolor changes the background color by
       changing the first entry in the palette.
          On an EGA or a VGA, if you call setpalette or setallpalette to change the
       palette colors,the defined symbolic constants     might not give the correct
       color.This is because the color parameter to              setbkcolor indicates the
       entrynumber in the
       current palette, rather than a specific color.   (Except 0, which always sets the
       background color to black).
           ≡ File Edit Search Run Compile Debug Project Options Window Help




                                                                                       13
settextjustify():-
       void far setbkcolor(int color);
       color is either a number or symbolic name settextjustify() settextjustify Sets text
       justification for graphics mode
        Declaration: void far settextjustify(int horiz, int vert);
       Remarks:
       Text output after a call to settextjustify is justified around the current position
       (CP) horizontally and vertically, as specified.
       The default justification settings are
        LEFT_TEXT (for horizontal) and
        TOP_TEXT (for vertical)
       The enumeration text_just in GRAPHICS.H provides names for the horiz and
       vert settings passed to settextjustify.
        settextjustify affects text written with outtext and can't be used with
       text-mode and stream functions.
        Return Value:
       If invalid input is passed to settextjustify, graphresult returns -11, and the
       current text justification remains unchanged.

toascii():-
        Translates characters to ASCII format
       Declaration: int toascii(int c);
       Remarks:
        toascii is a macro that converts the integer c to ASCII by clearing all but the
        lower 7 bits. This gives a value in the range 0 to 127.
        Return Value: toascii returns the converted value of c.




                                                                                          14
             INTRODCTION TO DISK SCHEDULING
One of the responsibilities of the operating system is to use the hardware efficiently.
for the disk drives, meeting this responsibility entails having a fast access time and
disk bandwidth. The access time has two major components.
   1. The Seek time
   2. The Rotational latency


The seek time is the time for the disk arm to move the heads to the cylinder
concertinaing the desired sector.
The rotational latency is the additional time waiting for the disk to rotate the desired
sector to the disk head.
The disk bandwidth is the total number of bytes transferred, divided by the total time
between the first request for service and the completion of the last transfer. We can
improve both the access time and the bandwidth by scheduling the servicing of disk
I/O request in a good order.
Whenever a process needs I/O to or from the disk, it issues a system call to the
operating system. The request specifies several pieces of information. They are :

    Whether this operation is input or output.
    What the disk address for the transfer is.
    What the memory address for the transfer is.
    What the number of bytes to be transferred is.
If the desired disk drive and controller are available, the request can be serviced
immediately. If the drive or controller is busy, any new requests for service will be
placed on the queue of pending requests for that drive. For a multi programming
system with many processes, the
disk queue may often have several pending requests. Thus, when one request is
completed, the operating system chooses which pending request to service next.

                                                                                     15
          ALGORITHMS OF DISK SCHEDULING

Algorithms of Disk Scheduling are:


     1.   First Come First Serve (F C F S)

     2.   Shortest Seek Time First (S S T F)

     3.   SCAN Scheduling

     4.   C SCAN Scheduling (C SCAN)

     5.   LOOK Scheduling




                                               16
             Graphical Notation of Algorithms

FIRST COME FIRST SERVE (F C F S)

    The simplest form of disk scheduling is, of course, the first-come, first-served
(FCFS) Algorithm. This algorithm is intrinsically fair, but it generally does not provide
the fastest service. Consider, for Ex, A disk queue with requests for I/O to blocks on
cylinders.


              98, 183, 37, 122, 14, 124, 65, 67


in that order. If the disk head is initially at cylinder 53, it will be first move from 53 to
98, then to 183,37,122,14,124,65, and finally to 67, for a total head movement of 640
cylinders. This schedule is diagrammed in figure.




                                                                                          17
              queue = 98, 183, 37, 122, 14, 124, 65, 67
                         head starts at 53


0   14   37     536567          98 122 124                183 199




               SHORTEST SEEK TIME FIRST (S S T F)




              FIRST COME FIRST SERVE (F C F S)




                                                                    18
SSTF SCHEDULING (S S T F)

It seems reasonable to service all the requests close to the current head position,
before moving the head for away to service other requests. This assumption is the
basis for the shortest-seek-time-first (SSTF) algorithm. The SSTF algorithm selects the
request with the minimum seek time from the current head position. Since seek time
increases with the number of cylinders traversed head position.


For our example request queue, the closest request to the initial head position(53) is at
cylinder 65. Once we are at cylinder 65, the next closest request is at cylinder 67. From
there, the request at cylinder 37 is closer than 98, so 37 is served next. Continuing, we
service the request at cylinder 14, then98, 122,124, and finally 183. This scheduling
method results in a total head movement of only236 cylinders---little more than one-
third of the distance needed for FCFS scheduling of this request queue. This algorithm
gives a substantial improvement in performance.


      SSTF scheduling is essentially a form of shortest-job-first(SJF) scheduling, and,
like SJE scheduling, it may cause starvation of some requests. Remember that requests
may arrive at any time. Suppose that we have two requests in the queue, for cylinders
14 and 186, and while servicing the request from 14, a new request near 14 arrives.
This new request will be serviced next, making the request at 186 wait. While this
request is being serviced, another request close to 14 could arrive. In theory, a
continual stream of requests near one another could arrive, causing the request for
cylinder 186 to wait indefinitely. This scenario becomes increasingly likely if the
pending-request queue grows long.


      Although the SSTF algorithm is a substantial improvement over the FCFS
algorithm, it is not optimal. In the example, we can do better by moving the head from


                                                                                      19
53 to 37, even though the latter is not closest, and then to 14, before turning around to
service 65, 67, 98, 122, 124, and 183. This strategy reduces the total head movement to
208 cylinders.




                      queue = 98, 183, 37, 122, 14, 124, 65, 67
                                  head starts at 53


0      14        37     536567            98 122 124                 183 199




                       SHORTEST SEEK TIME FIRST (S S T F)




                      SHORTEST SEEK TIME FIRST (S S T F)




                                                                                      20
        SCAN SCHEDULING

In the SCAN algorithm, the disk arm starts at one end of the disk, and moves toward
the other end, servicing requests as it reaches each cylinder, until it gets toward the
other end of the disk. At the other end, the direction of head movement is reversed,
and servicing continues. The head continuously scans back and forth across the disk.
We again use our example.


      Before applying SCAN to schedule the requests on cylinders 98,183, 37, 122, 14,
124, 65, and 67, we need to know the direction of head movement, in addition to the
head’s current position (53). Lf the disk arm is moving toward 0, the head will service
37 and then 14. At cylinder 0, the arm will reverse and will move toward the other
end of the disk, servicing the requests at 65,67, 98, 122, 124, and 183. If a request
arrives in the queue just in front of the head, it will be serviced almost immediately; a
request arriving just behind the head, it will be serviced almost immediately; a request
arriving just behind the head will have to wait until the arm moves to the end of the
disk, reverses direction, and comes back.
      The SCAN algorithm is sometimes called the elevator algorithm, since the disk
arm behaves just like an elevator in a building, first servicing all the requests going
up, and then reversing to service requests the other way.
      Assuming a uniform distribution of requests for cylinders, consider the density
of requests when the head reaches one end and reverses direction. At this point,
relatively few requests are immediately in front of the head, since these cylinders have
recently been serviced. The heaviest density of requests is at the other end of the disk.
These requests have also waited the longest, so why not go there first? That is the idea
of the next algorithm.




                                                                                      21
              queue = 98, 183, 37, 122, 14, 124, 65, 67
                        head starts at 53


0   14   37    53 65 67         98     122 124            183 199




                                         SCAN SHEDULING




                       SCAN SHEDULING




                                                                    22
        C-SCAN SCHEDULING (C SCAN)



Circular scan (C-SCAN) scheduling is a variant of SCAN designed to provide a more
uniform wait time. Like SCAN, C-SCAN moves the head from one end of the disk to
the other, servicing requests along the way. When the head reaches the other end,
however, it immediately returns to the beginning of the disk, without servicing any
requests on the return trip. The C-SCAN scheduling algorithm essentially treats the
cylinders as a circular list that wraps around from the final cylinder to the first one.


                      queue = 98, 183, 37, 122, 14, 124, 65, 67
                                head starts at 53

   0 14        37       536567              98      122 124              183 199




                                C SCAN SHEDULING

                                                                                           23
        LOOK SCHEDULING

       As we described them, both SCAN and C-SCAN move the disk arm across the
full width of the disk. In practice, neither algorithm is implemented this way. More
commonly, the arm goes only as the final request in each direction.
       Then, it reverses direction immediately, without going all the way to the end of
the disk. These versions of SCAN and C-SCAN are called LOOK and C-LOOK
scheduling, because they look for a request before continuing to move in a given
direction.

                     queue = 98, 183, 37, 122, 14, 124, 65, 67
                               head starts at 53

0       14      37      53 6567            98     122 124               183199




                               LOOK SCHEDULING



                                                                                    24
                  Software Implementations

                                  SOURCE CODE
                 ABOUT .C
//#include<stdio.h>
//#include<graphics.h>
//#include<conio.h>
//void main()
void about()
{
       int i;//,gd=DETECT,gm;
      // initgraph(&gd,&gm,"c:\\tc\\bgi");

setcolor(9);
for(i=1; i<=480; i++)
line(0,i,640,i);

 for(i=480; i>=240; i--)
 {     line(0,i,640,i);
       line(0,480-i,640,480-i);
       text();
}

setcolor(9);
for(i=240; i<=440; i++)
{
        line(0,i,640,i);
        line(0,480-i,640,480-i);
        delay(13);}
text();
delay(1000);
setcolor(14);
outtextxy(166,390,"Press Any Key To Continue...");

getch();
return;
}

text()
{
                                                     25
     settextstyle(7,HORIZ_DIR,4);
     setcolor(5);
     outtextxy(50,40,"PROJECT ON DISK SCHEDULING");
     setcolor(13);
     outtextxy(50,90,"*********************************************");
      settextstyle(4,HORIZ_DIR,2);
     setcolor(14);
     outtextxy(50,135,"Developed By....");
     setcolor(15);
     settextstyle(8,HORIZ_DIR,3);
     outtextxy(200,150,"DELLI PRASAD.M ");
     outtextxy(200,180,"MANJU PRAKASH ");
     outtextxy(200,210,"VARADARAJU");
     outtextxy(200,240,"VIJAY KUMAR.V");
     settextstyle(8,HORIZ_DIR,1);
     outtextxy(200,275,"6th SEM, C/S");
     outtextxy(200,295,"S.J.POLYTECHNIC");
     outtextxy(200,315,"BANGALORE");
     settextstyle(1,0,2);
     settextstyle(4,HORIZ_DIR,2);
     setcolor(14);
     outtextxy(50,340,"Guided by....");
     setcolor(11);
     settextstyle(1,HORIZ_DIR,1);
     setcolor(4);
     outtextxy(200,340,"(LECTURER NAME)");
        setcolor(13);
        settextstyle(7,HORIZ_DIR,4);
     outtextxy(50,360,"********************************************");
     setcolor(3);
    return 0;
}




                                                                         26
         ALGORITHM.C
#include<stdio.h>
#include<conio.h>
#include<stdio.h>
//void main()
void ssft(int sort[30], int process[30], int jobs)
{
       int i,temp,j,maximum,minimum,k;

        for(i=1; i<=jobs; i++) //SORT
        for(j=1; j<=jobs; j++)
        if(sort[i] < sort[j])
        {
                   temp = sort[i];
                   sort[i] = sort[j];
                   sort[j] = temp;
        }

// SSFT
 for(i=0; i<=jobs; i++)
 for(j=1; j<=jobs; j++)
 {
       if((sort[j] != -99) && (sort[j] >= process[i]))
       {
               maximum=j;
               for(k=j-1; k>=1; k--)
               if(sort[k] != -99){minimum=k; break;}

        if((sort[maximum]-process[i]) <= (process[i]-sort[minimum]))
                {process[i+1] = sort[maximum]; sort[maximum] = -99;}
        else
                {process[i+1] = sort[minimum]; sort[minimum] = -99;}

        break;
        }
    }
}




void fcfs(int unsort[30], int process[30], int jobs)
                                                                       27
{
        int i,temp,j,maximum,minimum,k;
         for(i=1; i<=jobs; i++)
         process[i]=unsort[i];
}

void scan(int sort[30], int process[30], int jobs)
{
        int i,temp,j,maximum,minimum,k;

          for(i=1; i<=jobs; i++) //SORT
          for(j=1; j<=jobs; j++)
if(sort[i] < sort[j])
{
           temp = sort[i];
           sort[i] = sort[j];
           sort[j] = temp;
 }

 i=0;
 for(j=1; j<=jobs; j++)
 {
        if(sort[j] >= process[0])
        {
                 for(k=j-1; k>=1; k--)
        {
                 i++;
                 process[i]=sort[k];
        }
        for(k=j; k<=jobs; k++)
        process[k]=sort[k];
        break;
        }
 }
 }
void c_scan(int sort[30], int process[30], int jobs)
{
        int i,temp,j,maximum,minimum,k;

       for(i=1; i<=jobs; i++) //SORT
       for(j=1; j<=jobs; j++)
       if(sort[i] < sort[j])
       {
               temp = sort[i];
               sort[i] = sort[j];
                                                       28
              sort[j] = temp;
       }

       i=0;
       for(j=1; j<=jobs; j++)
       {
              if(sort[j] >= process[0])
              {
                      for(k=j; k<=jobs; k++)
                      {
                              i++;
                              process[i]=sort[k];
                      }

                     for(k=1; k<=j-1; k++)
                     {
                             i++;
                             process[i]=sort[k];
                     }
                     break;
              }
       }
}



           CYL.C
#include<dos.h>

//int gd=DETECT,gm,
int i,j,x,prevy,cury,
         disc_count=40,start,FCFS[10]={0,15,39,6,27,4,29,8,10},flag=1,
         SSTF[10]={0,8,10,6,4,15,27,29,39},
         SCAN[10]={0,6,4,8,10,15,27,29,39},
         C_SCAN[10]={0,8,10,15,27,29,39,4,6},
         line_color=15,disc_no=40;
         long int choice;
         char string[10];




void cylender()

                                                                         29
//void main() // MAIN BLOCK
{
  //initgraph(&gd,&gm,"c:\\tc\\bgi");

do{
      cleardevice();
      menu1();
      cleardevice();
      if(choice>0 && choice<=4)
      {
             settextstyle(1,VERT_DIR,8);
             setcolor(11);
             outtextxy(5,175,"DEMO");
             settextstyle(0,HORIZ_DIR,0);
             disk(460,80);
             outtextxy(5,70,"Entered Queue");
             print_Q(FCFS,5,90,14);
             setcolor(7);
             outtextxy(5,115,"Processing Queue");

            outtextxy(350,60,"Disk");

            outtextxy(475,prevy," <-- Head Starts");

             setcolor(10);
             settextstyle(1,HORIZ_DIR,1);
 if(choice == 1){outtextxy(125,5,"DISK SCHEDULING :: F C F S ALGORITHM");
              settextstyle(0,HORIZ_DIR,0);
              print_Q(FCFS,5,135,10);
              getch();
              note(FCFS);}
 else
 if(choice == 2){outtextxy(125,5,"DISK SCHEDULING :: S S T F ALGORITHM");
              settextstyle(0,HORIZ_DIR,0);
              print_Q(SSTF,5,135,10);
              getch();
              note(SSTF);}
 else
 if(choice == 3){outtextxy(125,5,"DISK SCHEDULING :: S C A N ALGORITHM");
              settextstyle(0,HORIZ_DIR,0);
              print_Q(SCAN,5,135,10);
              getch();
              note(SCAN);}
 else
 if(choice == 4){outtextxy(125,5,"DISK SCHEDULING :: C-S C A N ALGORITHM");
                                                                          30
               settextstyle(0,HORIZ_DIR,0);
               print_Q(C_SCAN,5,135,10);
               getch();
               note(C_SCAN);}
 disc_no=40;
 x = 100;
 line_color=15;
              getch();
       }
}while(choice <= 4);
//closegraph();
//restorecrtmode();
}    //         END OF MAIN BLOCK

disk(int YY, int Y) // FUNCTION TO PRINT DISK STRUCTURE
{

        for(i=YY; i>=Y; i-=10)
        {
              setcolor(0);
              ellipse(320,i,0,360,100,15);
              x=100;
              setcolor(8);
              for(j=13; j>=0; j-=1)
              {
                      x -= 3;
                      ellipse(320,i,0,360,x,j);
              }
   if ( disc_no >= 2)
   {
              --disc_no;
              if(disc_no == 7) prevy = i-3;
              setcolor(4);
              itoa(disc_no, string, 10);
              outtextxy(167,i-3,string);
              outtextxy(460,i-3,string);
   }
}
setcolor(7);
for(i=80; i>=50; i-=2)
ellipse(320,i,0,360,10,3);
return 0;
}

note(int array[10]) // FUNCTION TO HEIGHLIGHT DISK
                                                          31
{
           for(start=1; start<=8; start++)
           {
                  disc_count=40;
                  for(i=460; i>=80; i-=10)
                  {
                          disc_count--;
       if(disc_count == array[start])
       {
                   x=100;
                  setcolor(7);
                  for(j=0; j<=13; j+=1)
                  {
                          x -= 1;
                          ellipse(320,i,0,360,x,j);
                          sound(80);
                          delay(115);
                          nosound();
                  }
                  x += 14;
                  setcolor(8);
                  for(j=13; j>=0; j-=1)
                  {
                          x -= 3;
                          ellipse(320,i,0,360,x,j);
                          sound(40);
                          delay(115);
                          nosound();
                  }
                  cury=i;
                  setcolor(--line_color);
                  if(flag == 1)
                  {flag = 0; line(460,prevy,167,cury);
                  itoa(start, string, 10);
                  outtextxy(475,prevy,string);
      }
      else {flag = 1; line(167,prevy,460,cury);
      itoa(start, string, 10);
      outtextxy(157,prevy,string);
      }
           prevy=cury;
           break;
      }
    }
    disk(i,80);
                                                         32
  delay(1500);
  }
disk(460,80);
settextstyle(0,HORIZ_DIR,0);
outtextxy(475,prevy-5," <-- End Of Jobs");
return 0;
}

print_Q(int array[10], int x, int y, int color)
{
       for(i=1; i<9; i++)
       {
              itoa(array[i],string,10);
              setcolor(color);
              outtextxy(x,y,string);
              setcolor(15);
              outtextxy(x+13,y,",");
              x += 18;
       }
       return 0;
}

menu1()
{
      setbkcolor(1);
      setcolor(8);
      rectangle(140,40,510,405);
      rectangle(145,45,505,400);
      setcolor(14);
      settextstyle(4,HORIZ_DIR,6);
      outtextxy(160,50,"DEMO MENU");
      settextstyle(1,HORIZ_DIR,3);
      setcolor(15);
      outtextxy(210,150,"1");
      outtextxy(210,190,"2");
      outtextxy(210,230,"3");
      outtextxy(210,270,"4");
      outtextxy(210,310,"5");
      setcolor(11);
      settextstyle(1,HORIZ_DIR,1);
      outtextxy(250,153,"FCFS Algorithm");
      outtextxy(250,193,"SSTF Algorithm");
      outtextxy(250,233,"SCAN Algorithm");
      outtextxy(250,273,"C-SCAN Algorithm");
      outtextxy(250,313,"MAIN MENU");
                                                  33
       setcolor(12);
       outtextxy(160,363,"ENTER A CHOICE TO VIEW DEMO...");
       gotoxy(60,24);
       scanf("%d",&choice);
       settextstyle(0,HORIZ_DIR,0);
       setbkcolor(0);
       return 0;
}


       DISK S.C
#include<graphics.h>
#include"C:dead\algoritm.c"

int max=0,scale_diff,option=5,
unsort[30],sort[30],proced=1;
long min=99999;

void disk_graph()
//void main()
{
          //int gd=DETECT,gm
          int queue[30],i,jobs,pos=25,job;
          char head[10];//      Head Start Is Stored In queue[0]
          //initgraph(&gd,&gm,"c:\\tc\\bgi");
          cleardevice();
          printf("\n\nEnter:: Number Of Jobs ");
          scanf("%d",&jobs);
          printf("\nEnter:: N Number Of Jobs (Jobs At Cylinder Number)\n");
          scanQ(jobs,queue);
   if(proced == 1)
   {
   for(i=1; i<=jobs; i++) //     FINDS THE MINIMUM AND MAXIMUM OF JOBS
   {
         if(min > queue[i]) min=queue[i];
         if(max < queue[i]) max=queue[i];
   }
  //        READS CURRENT HEAD POSITION
  printf("\nEnter:: Head Starts At (Between 1-%d) ",max);
  scanf("%d",&queue[0]);



if((queue[0] > max) || (queue[0] <= 0))
                                                                              34
{
    printf("What You Entered Should Be With In The Bounds"); getch();
    //closegraph();
    //restorecrtmode();
    proced = 0;
    //exit();
               }
    printf("\n\nPress Any Key To Continue...");
    getch();
    if(proced == 1)
    {
    while (option <= 5)
    {
           cleardevice();
           menu2();
           cleardevice();
           settextstyle(1,HORIZ_DIR,1);
           setcolor(10);
           if(option == 1)
    {
    outtextxy(155,0,"PROJECT ON:: DISK SCHEDULING (FCFS Algorithm)");
    fcfs(sort,queue,jobs);
    }
else
if(option == 2)
{
     outtextxy(155,0,"PROJECT ON:: DISK SCHEDULING (SSFT Algorithm)");
     ssft(sort,queue,jobs);
}
else
if(option == 3)
{
     outtextxy(155,0,"PROJECT ON:: DISK SCHEDULING (SCAN Algorithm)");
     scan(sort,queue,jobs);
}
else
if(option == 4)
{
     outtextxy(155,0,"PROJECT ON:: DISK SCHEDULING (C-SCAN Algorithm)");
     c_scan(sort,queue,jobs);
 }
else
break;
setcolor(15);
rectangle(90,80,639,479);
                                                                       35
 settextstyle(0,HORIZ_DIR,0);
 outtextxy(65,70,"(0,0)");
 outtextxy(290,45,"----Cylinder Numbers----->");
 outtextxy(630,70,"X");
 outtextxy(80,470,"Y");
 outtextxy(121,25,"Queue -->");
 printQ(jobs,unsort,pos);
 setcolor(15);
 outtextxy(65,35,"Process Queue-->");
 printQ(jobs,queue,35);

 setcolor(15);
 outtextxy(66,45,"Head Starts At:: ");
 setcolor(13);
 itoa(queue[0],head,10);
 outtextxy(200,45,head);

 putpixel(90,80,12);
 putpixel(91,80,12);
 putpixel(90,81,12);//     TO POINTOUT (0,0)
 putlines();
 scale();

   setcolor(9+BLINK);
   graph(jobs, queue, scale_diff);
   outtextxy(420,470,"Press Any Key To Continue...");
   for(i=1; i<=jobs; i++)
    sort[i]=unsort[i];
   getch();
  }
 }
}
proced = 1;
//closegraph();
//restorecrtmode();
}//                       END OF MAIN BLOCK

putlines() // PRINTS THE LINES IN RECTANGLE
{
        int i;
        setcolor(8);
        for(i=112; i<=640; i=i+22)
        line(i,80,i,479);
        for(i=96; i<=480; i=i+16)
                                                        36
          line(90,i,639,i);
          return 0;
}
//             FUNCTION TO CALCULATE SCALE FOR GRAPH
scale()
{
          int i,temp=112,temp1=96;
          char no[10];
          if ((min+max) >= 25)
          {
                 scale_diff = (((min+max)/23));
                 if(scale_diff == 1 && min+max <= 45) scale_diff =2;
           }
           else
                         scale_diff = 1;
                         setcolor(15);
                         settextstyle(0,VERT_DIR,0);
                         outtextxy(50,120,"Scale Is 1 Cell = ");
                         itoa(scale_diff,no,10);
                         outtextxy(50,110,no);
                         outtextxy(50,80,"Cyl");
                         settextstyle(0,HORIZ_DIR,0);
 for(i=min; i<=max; i+=scale_diff)
 {
      settextstyle(0, VERT_DIR, 1);
      setcolor(12);
      itoa(i,no,10);
      outtextxy(temp+5,55,no);
      temp += 22;
      settextstyle(0, HORIZ_DIR, 1);
      outtextxy(60,temp1-3,no);
      temp1 += 16;
 }
 settextstyle(0, VERT_DIR, 1); // TO PRINT LAST VALUE
 setcolor(12);
 itoa(i,no,10);
 outtextxy(temp+5,55,no);
 temp += 22;
 settextstyle(0, HORIZ_DIR, 1);
 outtextxy(60,temp1-3,no);
 temp1 += 16;
 return 0;
 }


                                                                       37
    printQ(int jobs, int queue[30], int pos)
    {
         int i,temp=200;
         char head[10];
         for(i=1; i<=jobs; i++) // PRINTS QUEUE
         {
                 setcolor(11);
                 itoa(queue[i],head,10);
                 outtextxy(temp,pos,head);
                 temp += 30;
         }
         return 0;
    }

    scanQ(int jobs, int queue[30])
    {
         int i;
         for(i=1; i<=jobs; i++)
         {
                scanf("%d",&queue[i]);
                unsort[i] = queue[i];
                sort[i] = queue[i];
                if(queue[i] < 1){printf("Cyclinder Count Starts From 1"); getch();
                //closegraph();
                //restorecrtmode();
                proced = 0;
                break;//exit();
         }
    }
    return 0;
}

graph(int jobs, int queue[30], int scale_diff)
{
       int x=90, y=80,i,j,pre_x,pre_y,k=1;
       for(i=0; i<=jobs; i++)
       {
              pre_x=x;
              pre_y=y;
              x=90;
              y=80;



         for(j=min; j<=queue[i]; j+=scale_diff)
                                                                                     38
       if(j <= queue[i])
       {
               x += 22;
               y += 16;
       }
       if(j > queue[i])
       {
               x += (24/scale_diff)* (scale_diff - (j-queue[i]));
               y += (16/scale_diff)* (scale_diff - (j-queue[i]));
       }

       if(i != 0)
       if(k==0){ k=1; setcolor(i); delay(2000); line(x,80,90,pre_y);}
       else {k=0; setcolor(i); delay(2000); line(90,y,pre_x,80);}
}
return 0;
}

menu2()
{
            setbkcolor(8);
            setcolor(1);
            rectangle(140,40,510,405);
            rectangle(145,45,505,400);
            setcolor(14);
            settextstyle(4,HORIZ_DIR,4);
            outtextxy(220,50,"ALGORITHM");
            outtextxy(170,90,"IMPLEMENTATION");
            settextstyle(1,HORIZ_DIR,3);
            setcolor(15);
            outtextxy(210,150,"1");
            outtextxy(210,190,"2");
            outtextxy(210,230,"3");
            outtextxy(210,270,"4");
            outtextxy(210,310,"5");
            setcolor(11);
            settextstyle(1,HORIZ_DIR,1);
            outtextxy(250,153,"FCFS Algorithm");
            outtextxy(250,193,"SSTF Algorithm");
            outtextxy(250,233,"SCAN Algorithm");
            outtextxy(250,273,"C-SCAN Algorithm");
            outtextxy(250,313,"MAIN MENU");
            setcolor(12);
            outtextxy(200,363,"ENTER YOUR CHOICE...");
            gotoxy(52,24);
                                                                        39
         scanf("%d",&option);
         settextstyle(0,HORIZ_DIR,0);
         setbkcolor(0);
         return 0;
}




       END.C
int p,q=640;
void thank_you() //main()
{
   int colour=7;

   corner(colour);
   q=640;
   corner(0);
/*     setcolor(colour);
     settextstyle(1,HORIZ_DIR,6);
     outtextxy(q,p,"THANK YOU");*/
     delay(200);
    down(colour);
    down(0);
    setcolor(colour);
     settextstyle(7,0,8);
     setbkcolor(1);
     outtextxy(90,200,"THANK YOU");
}
corner(int colour)
{
      for(p=480; p>=1; p-=5)
      {
              q -= 5;
              setcolor(colour);
              settextstyle(10,HORIZ_DIR,5);
              if(p==0 && q==0)
              {
                      setbkcolor(1);
                      outtextxy(q,p,"THANK YOU");
                      delay(200);
              }
              setbkcolor(1);
              outtextxy(q,p,"THANK YOU");
                                                    40
             delay(5);
      }
      return 0;
}

down(int colour)
{
     for(q=0; q<=240; q+=5)
     {
             setcolor(colour);
             settextstyle(10,HORIZ_DIR,5);
             setbkcolor(1);
             outtextxy(160,q,"THANK YOU");
             delay(5);
     }
     return 0;
}

main_os.c
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include"C:dead\cyl.c"
#include"C:dead\disk_s.c"
#include"C:dead\about.c"
#include"C:dead\end.c"

int choose;
void main()
{
       int gd=DETECT,gm;
       initgraph(&gd,&gm,"c:\\tc\\bgi");
       about();
       while(choose <= 3)
       {
              cleardevice();
              menu();
              cleardevice();
              if(choose == 1) cylender();
       else
              if(choose == 2) disk_graph();
       else
       {
                                              41
           thank_you();
           getch();
           closegraph();
           restorecrtmode();
           exit();
     }
}
}
menu()
{
     setbkcolor(0);
     setcolor(8);
     rectangle(140,40,510,405);
     rectangle(145,45,505,400);
     setcolor(14);
     settextstyle(4,HORIZ_DIR,6);
     outtextxy(160,50,"MAIN MENU");
     settextstyle(1,HORIZ_DIR,3);
     setcolor(15);
     outtextxy(185,190,"1");
     outtextxy(185,230,"2");
     outtextxy(185,270,"3");
     setcolor(11);
     settextstyle(1,HORIZ_DIR,1);
     outtextxy(210,193,"VIEW DEMO");
     outtextxy(210,233,"ALGORITHM IMPLEMENTATION");
     outtextxy(210,273,"EXIT");
     setcolor(12);
     outtextxy(160,363,"ENTER A CHOICE TO VIEW DEMO...");
     gotoxy(59,24);
     scanf("%d",&choose);
     settextstyle(0,HORIZ_DIR,0);
     return 0;
}




                                                            42
SNAP SHOTS




             43
44
45
46
47
48
49
50
51
52
53
54
                             LIMITATIONS

          We have implemented only four algorithms of Disk Scheduling.

          The illustration of Look-Scheduling has been left without
          implementation.




                   SCOPE FOR IMPROVEMENTS


          We can extend this project by adding Look and C-Look scheduling
          algorithms


          If any new scheduling algorithms were introduced, then
          implementing them can enhance the project




          TEAM MEMBERS ROLE

     All the members in developing the project have taken combined
effort.




                                                                         55
                          CONCLUSION


   The project has really been a fruitful, informative. It has made us learn
and understand many of the ‘C’ language concepts and also improved over
knowledge.


   It also explains about the various scheduling operation produced by the
operating system. With the help of this project, each person is able to
understand the process of scheduling performed by the operating system.


    Finally, it has taught us valuable lesson about the improvements of
working and interacting in a group and also achieving targets within a
given time frame.




                                                                          56
              BIBLIOGRAPHY

Operating System by Galvin

Computer Architecture by John P Hayes

Let us C by Yeshwanth Kanetkar

Computer Graphics by Yeshwanth Kanetkar

Computer Graphics by Hearn

System Software and Operating System by Dhamdhere




                                                    57

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:461
posted:12/4/2011
language:English
pages:57