os lab final (2)

Upload: thangamkarna

Post on 04-Jun-2018

243 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 OS LAB Final (2)

    1/56

  • 8/13/2019 OS LAB Final (2)

    2/56

    PROGRAM: 

    #include

    int main(void) 

    {

    int pid;

     pid=fork();

    if(pid

  • 8/13/2019 OS LAB Final (2)

    3/56

    OUTPUT: 

    [student@localhost ~]$ vi ex1.c

    [student@localhost ~]$ gcc ex1.c

    [student@localhost ~]$ ./a.out 

    child processid is 7984

     parent processid is 7983Wed Mar 28 16:24:10 IST 2012

    RESULT: 

    Thus the above program using system calls fork(), getpid(), exit() and wait() has been executedsuccessfully.

    Register No: 100606314011  Pageno:3 

  • 8/13/2019 OS LAB Final (2)

    4/56

    EX.NO:1(b)  IMPLEMENTATION OF UNIX SYSTEM CALLS: 

    DATE: (stat, opendir, readdir, close) 

    AIM: To write a C program using system calls stat(), opendir() and readdir() and close().

    ALGORITHM: 

    Step 1: Start the program.

    Step 2: Initialize the process id number.

    Step 3: Create a process using stat(), opendir(), readdir() and close().

    Step 4: Start the process at first and close the process at last.

    Step 5: Open and read directory are used for opening the files and reading the files.

    Step 6: Stop the program.

    Register No: 100606314011  Pageno:4 

  • 8/13/2019 OS LAB Final (2)

    5/56

    PROGRAM: 

    #include

    #include

    #include

    int main(int argc,char * argv[])

    {

    DIR * dp;

    struct dirent *dirp; if(argc!=2)

    {

     printf("A single argument (the directory name )is required\n");exit(1);

    }

    if((dp=opendir(argv[1]))==0)

    {

     printf("can't open

    %s\n",argv[1]); exit(1);}

    while((dirp=readdir(dp))!=0)

     printf("%s\n",dirp-

    >d_name); closedir(dp);

    exit(0);

    }

    Register No: 100606314011  Pageno:5 

  • 8/13/2019 OS LAB Final (2)

    6/56

    OUTPUT: 

    [student@localhost ~]$ vi ex1b.c

    [student@localhost ~]$ gcc ex1b.c

    [student@localhost ~]$ ./a.out surya

    One

    Two

    … 

    … 

    RESULT: 

    Thus the above program using system calls stat(), close(), opendir() and readdir() has been executed successfully.

    Register No: 100606314011  Pageno:6 

  • 8/13/2019 OS LAB Final (2)

    7/56

    EX.NO:2  IMPLEMENTATION OF I/O SYSTEM CALLS: 

    DATE: (open, read, write) 

    AIM: To write a file operation using system calls.

    ALGORITHM: 

    Step 1: Start the program.

    Step 2: Create a file in read mode.

    Step 3: Read the content of a file in buffer.

    Step 4: Check the condition if[->seek==-1].

    Step 5: If it is true read the content of the buffer.

    Step 6: Else terminate the process.

    Step 7: Repeat step-4 until all the are read.

    Step 8: Stop the process.

    Register No: 100606314011  Pageno:7 

  • 8/13/2019 OS LAB Final (2)

    8/56

    PROGRAM: 

    #include

    #include

    #include

    main()

    {

    int s,fd,n,l=0;char buff[80];

    fd=open("ram.txt",O_RDWR,0);

     printf("the file in reverse order

    is:\n"); lseek(fd,-1,2);

    while (1)

    {

    n=read(fd,buff,1);

    write(1,buff,1);

    if((lseek(fd,-2,1))==-1) break;

    }

    close(fd);

    }

    Register No: 100606314011  Pageno:8 

  • 8/13/2019 OS LAB Final (2)

    9/56

    OUTPUT: 

    [student@localhost ~]$ vi ex2.c

    [student@localhost ~]$ gcc ex2.c

    [student@localhost ~]$ ./a.out

    The file in reverse order is hanujnam

    RESULT: 

    Thus the above program using i/o system calls of unix operating system open(), write(),and read() has been executed successfully

    Register No: 100606314011  Pageno:9 

  • 8/13/2019 OS LAB Final (2)

    10/56

    EX.NO:3(a)  IMPLEMENTATION OF GREP COMMANDS 

    DATE: 

    AIM: To write a c program using the commands like grep.

    ALGORITHM: 

    Step1: Start the process.

    Step2: Create a file pointer and pointer to a string.

    Step3: Open a file in read mode and the pointer points the position in the buffer.

    Step4: If string is #NULL then printf statement will get execute.

    Step5: Particular pattern of string will be displayed without using grep command.

    Step6: Stop the process.

    Register No: 100606314011  Pageno:10 

  • 8/13/2019 OS LAB Final (2)

    11/56

    PROGRAM: #include

    #include

    int substr(char *line,char *pat);

    int main(int argc,char *argv[]) 

    {

    FILE *fp;

    char line[128];

    if(argc==2)

    {

    fp=stdin;

    }

    else if(argc==3)

    {

    fp=fopen(argv[2],"r");

    if(fp==NULL)

    {

     printf("file %s cannot be opened \n",argv[1]);}

    }

    else

    {

     printf("usage:%s\n",argv[0]);

    exit(1);

    }

    while(fgets(line,sizeof(line),fp))

    if(substr(line,argv[1]))

     printf("%s",line);

    fclose(fp);return 0;

    }

    int substr(char *line,char *pat)

    {

    int i,j,k;for(i=0;line[i]!='\0';i++) 

    {

    for(j=i,k=0;line[j]==pat[k] && pat[k]!='\0';j++,k++); if(pat[k]=='\0')

    return 1;

    }

    return 0;

    }

    Register No: 100606314011  Pageno:11 

  • 8/13/2019 OS LAB Final (2)

    12/56

    OUTPUT: 

    [student@localhost ~]$ vi ex3a.c

    [student@localhost ~]$ gcc ex3a.c

    [student@localhost ~]$ ./a.out substr

    grep.c\ int substr( char *line, char *pat);

    if ( substr(line, argv[1]) )

    int substr( char *line, char *pat)

    RESULT: 

    Thus the above program using grep commands has been executed successfully. 

    Register No: 100606314011  Pageno:12 

  • 8/13/2019 OS LAB Final (2)

    13/56

    EX.NO:3(b)  IMPLEMENTATION OF LS COMMANDS 

    DATE: 

    AIM: To write a c program using the commands like ls.

    ALGORITHM: 

    Step 1: Start the program.

    Step 2: Initialize the ls command.

    Step 3: Create a directory with help of the commands.

    Step 4: The directories like open and read are used in the program.

    Step 5: Run the program.

    Step 6: Display the result.

    Step 7: Stop the program.

    Register No: 100606314011  Pageno:13 

  • 8/13/2019 OS LAB Final (2)

    14/56

    PROGRAM: 

    #include

    #include

    #include

    int main(int argc,char*argv[])

    {

    DIR*dp;

    struct dirent*dirp;if(argc!=2) 

    {

     printf("a single argument(the directory name)isrequired\n"); exit(1);

    }

    if((dp=opendir(argv[1]))==0)

    {

     printf("can\'t open %s\n",argv[1]);

    exit(1);}

    while((dirp=readdir(dp))!=0)

     printf("%s\n",dirp-

    >d_name); closedir(dp);

    exit(0);

    }

    Register No: 100606314011  Pageno:14 

  • 8/13/2019 OS LAB Final (2)

    15/56

    OUTPUT: [student@localhost ~]$ vi ex3b.c

    [student@localhost ~]$ gcc ex3b.c

    [student@localhost ~]$./a.out muni

    calls3.c.

    a.outone ..two

    RESULT: 

    Thus the above program using ls commands has been executed successfully. 

    Register No: 100606314011  Pageno:15 

  • 8/13/2019 OS LAB Final (2)

    16/56

    EX.NO:4(a)  IMPLEMENTATION OF FCFS SCHEDULING 

    DATE: 

    AIM: To write a C program for the implementation of FCFS scheduling.

    ALGORITHM: 

    Step 1: Start the program.

    Step 2: Initialize the variable.

    Step 3: Read the number of process.

    Step 4: Get the runtime of each process using for loop.

    Step 5: Burst time, Turn around time and Waiting time is calculated using while loop.

    Step 6: Calculate average Turn around time, average waiting time and print it.

    Step 7: Exit the program.

    Register No: 100606314011  Pageno:16 

  • 8/13/2019 OS LAB Final (2)

    17/56

    PROGRAM: 

    #include

    #include

    #include

    Main()

    Char pn[10] [10],t[10];

    Int array[10],bur[10],star[10],finish[10],tat[10],wt[10],I,j,n,temp;

    Int totwt=0,tottat=0; 

    //clrscr();

    Printf(“enter the number of process:”);Scanf(“%d”,&n); 

    For(i=0;i

  • 8/13/2019 OS LAB Final (2)

    18/56

    finish[i]=atar[i]+bur[i];

    tat[i]=finish[i]-arr[i];  

    }

    Printf(“\npname arrtime burtime waittime start tat finish”); 

    For(i=0;i

  • 8/13/2019 OS LAB Final (2)

    19/56

    OUTPUT: 

    RESULT: 

    Thus the above program FCFS scheduling has been executed successfully. 

    Register No: 100606314011  Pageno:19 

  • 8/13/2019 OS LAB Final (2)

    20/56

    EX.NO:4(b)  IMPLEMENTATION OF SJF SCHEDULING 

    DATE: 

    AIM: To write a C program for the implementation of SJF scheduling.

    ALGORITHM: 

    Step 1: Start the program.

    Step 2: Initialize the variable.

    Step 3: Read the number of process.

    Step 4: Enter the runtime of each process using for loop.

    Step 5: Process having shortest burst time will be executed using swapping

    Step 6: Using while loop print the burst and waiting time.

    Step 7: Calculate and print the average Turnaround time.

    Step 8: Stop the program.

    Register No: 100606314011  Pageno:20 

  • 8/13/2019 OS LAB Final (2)

    21/56

    PROGRAM: 

    #include

    struct sjf  

    {

    int burst,turn,process,no,waiting;

    char name; 

    }

    a[10];

    int main()

    {

    int i,j,k,l,temp,temp1;

    float avgwait,waiting1=0,burst1=0,avgburst;

     printf("Enter the no of process:");

    scanf("%d",&k);

     printf("\nProcess\t\tBurst\n");

    for(i=1;i

  • 8/13/2019 OS LAB Final (2)

    22/56

    {

    l=i+1;

     printf("\n%d\t\t%d\t\t%d",a[l].no,a[i].waiting,a[l].waiting);

     burst1=burst1+a[l].waiting;

    }

    avgwait=(waiting1/k);

    avgburst=(burst1/k);

     printf("\nAverage waiting time is:%f",avgwait); printf("\nAverage turn around time

    is:%f\n",avgburst); return 0;

    }

    Register No: 100606314011  Pageno:22 

  • 8/13/2019 OS LAB Final (2)

    23/56

    OUTPUT: 

    [student@localhost ~]$ vi ex4b.c

    [student@localhost ~]$ gcc ex4b.c

    [student@localhost ~]$ ./a.out

    Enter the no of process:5 

    Process Burst

    1  62  73  44  15  3Process Waiting Burst time 

    4 0 1

    5 1 4

    3 4 8

    1 8 14

    2 14  21

    Average waiting time is:5.400000

    Average turn around time is:9.600000

    RESULT: 

    Thus the above program SJF scheduling has been executed successfully

    Register No: 100606314011  Pageno:23 

  • 8/13/2019 OS LAB Final (2)

    24/56

    EX.NO:5(a) 

    DATE: 

    IMPLEMENTATION OF PRIORITY SCHEDULING 

    AIM: To write a C program for the implementation of priority scheduling.

    ALGORITHM: 

    Step1: Start the program.

    Step2: Get the arrival time and burst time for each process.

    Step3: Get priority for execution of each process.

    Step4: Allocate cpu for process pi depends on the priority assign to it.

    Step5: Process with highest priority is allocated to cpu first

    Step6: Repeat step4 &step5 until all the process have been completed

    Step7: Stop the program.

    Register No: 100606314011  Pageno:24 

  • 8/13/2019 OS LAB Final (2)

    25/56

    PROGRAM: 

    #include

    struct ps 

    {

    int burst,turn,process,p,no,waiting;

    char name; 

    }a[10];

    int main() 

    {

    int i,j,k,l,temp,temp1;

    float avgwait,waiting1=0,burst1=0,avgburst;

     printf("Enter the no of process:");

    scanf("%d",&k);

     printf("\nProcess\t\tBurst\n");

    for(i=1;i

  • 8/13/2019 OS LAB Final (2)

    26/56

    }

    for(i=1;i

  • 8/13/2019 OS LAB Final (2)

    27/56

    OUTPUT: 

    [student@localhost ~]$ vi ex5a.c

    [student@localhost ~]$ gcc ex5a.c

    [student@localhost ~]$ ./a.out

    Enter the no of process:5 

    Process  Burst 

    942  73  124  15  6Enter the priority

    For process1:5

    For process2:2

    For process3:1

    For process4:3

    For process5:4

    Process  Waiting  Turn around Priority 3  0  12  1 

    2  12  19  2 

    4  19  20  3 

    5  20  26  4 

    1  26  120  5 

    Average waiting time is:15.400000 

    Average turn around time is:39.400002 

    RESULT: Thus the above program for PRIORITY scheduling has been executed successfully.

    Register No: 100606314011  Pageno:27 

  • 8/13/2019 OS LAB Final (2)

    28/56

    EX.NO:5(b)  IMPLEMENTATION OF ROUND ROBIN SCHEDULING 

    DATE: 

    AIM: To write a C program for the implementation of ROUND ROBIN scheduling.

    ALGORITHM: 

    Step 1: Start the program.

    Step 2: Declare the data types.

    Step 3: Initialize the ROUND ROBIN scheduling process.

    Step 4: Get input and output values.

    Step 5: Display the result.

    Step 6: Stop the program.

    Register No: 100606314011  Pageno:28 

  • 8/13/2019 OS LAB Final (2)

    29/56

    PROGRAM: 

    #include

    #include

    typedef struct pcb 

    {

    int pid, bt, bt_bal, tat,wt; } PCB;

    int main()

    {

    PCB pr[10];

    int i,j,k,n,tq; 

    int sum_bt=0,sum_tat=0,sum_wt=0,tq_used=0;

    int gantt[2][50]; 

     printf("Enter the no. of process :"); scanf("%d",&n);

    for(i=0;i

  • 8/13/2019 OS LAB Final (2)

    30/56

    {

    tq_used += tq;

     pr[i].bt_bal -= tq;

    gantt[0][k] =

     pr[i].pid; gantt[1][k]

    = tq_used; k++;

    }

    else if( pr[i].bt_bal < 0 )

    {

     printf("\nError: bt --ve\n"); exit(1);

    }

    }

    while( tq_used != sum_bt);

     printf("\nROUND ROBBIN Scheduling GANTTChart\n\n"); printf("PID: ");

    for( i=0; i

  • 8/13/2019 OS LAB Final (2)

    31/56

    OUTPUT: 

    [student@localhost ~]$ vi ex5b.c

    [student@localhost ~]$ gcc ex5b.c

    [student@localhost ~]$ ./a.out

    Enter the no. of process : 5

    Enter burst time of the process 1: 4  

    Enter burst time of the process 2: 3  

    Enter burst time of the process 3: 7  

    Enter burst time of the process 4: 9  

    Enter burst time of the process 5: 5  

    Enter the time quantum no. : 2

    sum of bt = 28

    ROUND ROBBIN Scheduling GANTT Chart

    PID: 1 2 3 4 5 1 2  3 4 5 3 4 5  3 4 4

    Time: 2 4 6 8 10 12 13  15 17  19 21 23 24  25 27 28

    PID: 1 2 3 4 5

    Btime: 4 3 7 9 5TAT: 12 13 25 28 24

    Wtime:  8 10 18 19 19

    Total waiting time = 74

    Average waiting time = 14.80

    Total turn around time = 102 

    Average turn around time = 20.40

    RESULT: 

    Thus the above program ROUND ROBIN scheduling has been executed successfully

    Register No: 100606314011  Pageno:31 

  • 8/13/2019 OS LAB Final (2)

    32/56

    EX.NO:6  DEVELOPING APPLICATION USING INTER PROCESS 

    DATE: COMMUNICATION 

    AIM: To write a C program using Inter Process Communication for developing an application.

    ALGORITHM: 

    Step 1: Create the child process using fork().

    Step 2: Create the shared memory for parent process using shmget() system call.

    Step 3: Now allow the parent process to write in shared memory using shmpet pointer which

    is turn type a shmget().

    Step 4: Now across and attach the same shared memory to the child process.

    Step 5: The data in the shared memory is read by the child process using the shmpet pointer.

    Step 6: Now, detach and rebase the shared memory.

    Register No: 100606314011  Pageno:32 

  • 8/13/2019 OS LAB Final (2)

    33/56

    PROGRAM: #include

    #include

    #include

    int main(void) 

    {

    int child,shmid;

    char *shmptr;

    int n;

    child=fork(); 

    if (child)

    {

    sleep(5);

    shmid=shmget(2041,32,066);

    shmptr=shmat(shmid,0,0);

    for(n=0;n

  • 8/13/2019 OS LAB Final (2)

    34/56

    OUTPUT: 

    [student@localhost ~]$ vi ex6.c

    [student@localhost ~]$ gcc

    ex6.c [student@localhost ~]$

    ./a.out 123456789 123456789

    \

    RESULT: 

    Thus the above C program using Inter Process Communication for developing an applicationhas been executed successfully.

    Register No: 100606314011  Pageno:34 

  • 8/13/2019 OS LAB Final (2)

    35/56

    EX.NO: 7  IMPLEMENTATION OF PRODUCER-CONSUMER PROBLEM USING 

    DATE: SEMAPHORES 

    AIM: To write a C program using semaphores for the implementation of producer-consumer problem.

    ALGORITHM: 

    Step1: start the program.

    Step2: Initialize semaphore full=0, empty= buffer size.

    Step3: Assign two pointer in and act respectively for producer and consumer.

    Step4:Using call construct get the choice for producer consumer ,display & exit respectively.

    Step5: For the producer write the item in to the buffer if it is not empty.

    Step6: for the consumer read the item from the buffer it it is not full.

    Step7: Repeat the step 5 and 6 until the buffer is empty.

    Step8: Stop the process.

    Register No: 100606314011  Pageno:35 

  • 8/13/2019 OS LAB Final (2)

    36/56

    PROGRAM: 

    # define BUFFER_SIZE

    3 #include

    typedef int semaphore;

    semaphore full=0;

    semaphore empty=BUFFER_SIZE;

    typedef struct 

    {

    int year;

    int roll; 

    }item;

    item buffer[BUFFER_SIZE];int counter=0,i=0; 

    int in=0;

    int out=0;

    main() 

    {

    int choice;int year1,roll1;

    int I; 

    while(1)

    {

     printf("\n1.Producer");

     printf("\n2.Consumer");

     printf("\n3.Display");

     printf("\n4.Exit");

     printf("\n\nEnter your choice:");

    scanf("%d",&choice);

    switch(choice) 

    {

    case 1:

    if(counter>=2) 

    {

     printf("\n\n*****Buffer Full*****\n\n");

    }

    if(((in+1)%BUFFER_SIZE)!=out)

    {

     printf("\n\nEnter the Year:");

    scanf("%d",&year1);

     printf("\n\nEnter Roll no:");

    scanf("%d",&roll1);

    wait(empty);

     buffer[in].year=year1; 

    Register No: 100606314011  Pageno:36 

  • 8/13/2019 OS LAB Final (2)

    37/56

     buffer[in].roll=roll1;

    signal(full);

    in=(in+1)%BUFFER_SIZE;

    counter++; 

    }

     break;

    case 2:

    if(in!=out) 

    {

    wait(full);

     printf("\n\nThe Year is %d",buffer[out].year);

     printf("\n\nThe Roll No. is

    %d\n\n",buffer[out].roll); signal(empty);

    out=(out+1)%BUFFER_SIZE;

    counter--; 

    }

    if(in

  • 8/13/2019 OS LAB Final (2)

    38/56

    OUTPUT: 

    [student@localhost ~]$ vi ex7.c

    [student@localhost ~]$ gcc

    ex7.c [student@localhost ~]$

    ./a.out 1.Producer

    2.Consumer

    3.Display

    4.Exit

    Enter your choice:1

    Enter the Year:2011

    Enter Roll no:11

    1.Producer

    2.Consumer

    3.Display 

    4.Exit

    Enter your choice:1

    Enter the Year:2012Enter Roll no:12

    1.Producer

    2.Consumer

    3.Display 

    4.Exit

    Enter your choice: 1

    *****Buffer Full*****

    Enter your choice: 2

    The Name is 1900 

    The Roll No. is 11. Producer2. Consumer3. Display4. ExitEnter your choice:2

    The Name is 2000

    The Roll No. is 2 

    *****Buffer is Empty!!!!*****

    RESULT: 

    Thus the above C program using semaphores for the implementation of producer-consumer problem has been executed successfully.

    Register No: 100606314011  Pageno:38 

  • 8/13/2019 OS LAB Final (2)

    39/56

    EX.NO:8  IMPLEMENTATION OF MEMORY MANAGEMENT SCHEME-I 

    DATE: 

    AIM: To write a C program for the implementation of memory management scheme-I.

    ALGORITHM: 

    Step 1: Get the number of memory partitions and memory partitions one by one.

    Step 2: Get the number of processes and size of each process.

    Step 3: In first fit strategy allocate the first hole that is big enough. Searching can start either at

    the  beginning of the set of holes or where the previous first-fit search ended. Stop searching as soon as

    find a free hole that is large enough.

    Step 4: In best fit strategy allocate the smallest hole that is big enough. Search the entire

    list, unless the list is kept ordered by size. This strategy produces the smallest leftover hole.

    . Step 5: In worst fit strategy allocate the largest hole. Again, search the entire list, unless it is sorted by

    size. This strategy produces the largest left over hole, which may be more useful than the smaller leftover

    hole from a best-fit approach.

    Register No: 100606314011  Pageno:39 

  • 8/13/2019 OS LAB Final (2)

    40/56

    PROGRAM: #include

    int aflag=0,np,nmp,p[10],mp[10],mp1[10],i,j,ch;

    main( ) 

    {

     printf(“\n\nMemory Management Scheme

    I”); printf("\n\nEnter No. of memory

     partitions:"); scanf("%d",&nmp);

     printf("Enter the Memory

    Partitions:\n"); for(i=0;i

  • 8/13/2019 OS LAB Final (2)

    41/56

    }

    if(aflag==0)

     printf("\nPrs %d(%dkb) can't be allocated! ",i,p[i]);

    }

    }

    Bestfit()

    {

    int bfmp,fsize=10000;for(i=0;i

  • 8/13/2019 OS LAB Final (2)

    42/56

    }

    }

    if(aflag==0)

     printf("\nPrs %d(%dkb) can't be allocated!",i,p[i]); else

    {

     printf("\nPrs %d(%dkb) alctd to Mmy Ptn%d(%dkb)",i,p[i],bfmp,mp[bfmp]); mp[bfmp]=mp[bfmp]-p[i];

    fsize=0;

    }

    }

    }

    Register No: 100606314011  Pageno:42 

  • 8/13/2019 OS LAB Final (2)

    43/56

    OUTPUT: 

    Enter no.of memory

     partitions:3 Enter the Memory

    Partitions: 125 100 250

    Enter no.of processes:5

    Enter the size of each process: P-0: 100

    P-1: 75

    P-2: 200

    P-3: 50

    P-4: 90

    FirstFit Strategy

    Prs 0(100kb) alctd to Mmy Ptn 0(125kb)

    Prs 1(75kb) alctd to Mmy Ptn 1(100kb)Prs 2(200kb) alctd to Mmy Ptn 2(250kb)

    Prs 3(50kb) alctd to Mmy Ptn 2(50kb) Prs

    4(90kb) can't be allocated! 

    BestFit Strategy

    Prs 0(100kb) alctd to Mmy Ptn 1(100kb)

    Prs 1(75kb) alctd to Mmy Ptn 0(125kb)

    Prs 2(200kb) alctd to Mmy Ptn 2(250kb)

    Prs 3(50kb) alctd to Mmy Ptn 0(50kb) Prs

    4(90kb) can't be allocated! 

    WorstFit StrategyPrs 0(100kb) alctd to Mmy Ptn 2(250kb)

    Prs 1(75kb) alctd to Mmy Ptn 2(150kb)

    Prs 2(200kb) can't be allocated! 

    Prs 3(50kb) alctd to Mmy Ptn 0(125kb)

    Prs 4(90kb) alctd to Mmy Ptn 1(100kb) 

    RESULT: 

    Thus the above program for the implementation of memory management scheme-I has beenexecuted successfully.

    Register No: 100606314011  Pageno:43 

  • 8/13/2019 OS LAB Final (2)

    44/56

    EX.NO:9  IMPLEMENTATION OF MEMORY MANAGEMENT SCHEME-II 

    DATE: 

    AIM: To write a C program for the implementation of memory management scheme-II.

    ALGORITHM: Step 1: Obtain the number of frames and sequence string from the user.

    Step 2: In the FIFO page replacement method if the page is not available in the frame

    increase  page fault by one and then remove the page based on FIFO manner.

    Step 3: In the LRU page replacement method replace the page that has not been need for

    the longest period of time.

    Step 4: Display the number of page faults in each method.

    Register No: 100606314011  Pageno:44 

  • 8/13/2019 OS LAB Final (2)

    45/56

    PROGRAM: 

    #include intnf,i,j=0,k,l,sref,refstr[30],frame[5]={-1,-1,-1,-1,-

    1},count[5]={0,0,0,0,0}; int flag=0,pfault=0;

    int mincnt=0,minfr,i1,rctcnt=0;

    void lru(); 

    int main()

    {

    int ch;

     printf(“\n\n Memory Management Scheme

    II”); printf("\n\nEnter the No. of Frames:");

    scanf("%d",&nf);

     printf("\nEnter the Size of ReferenceString:"); scanf("%d",&sref);

     printf("\nEnter the Reference

    String:"); for(i=0;i

  • 8/13/2019 OS LAB Final (2)

    46/56

    frame[j]=refstr[i];

     printframe();

     pfault++;

    flag=0;

     j++;

    if(j==nf)

     j=0;

    }

    }

     printf("\nNo. of Page Faults Occured : %d ",pfault); 

    }

     pfaultcheck()

    {

    for(k=0;k

  • 8/13/2019 OS LAB Final (2)

    47/56

    frame[minfr]=refstr[i];

    count[minfr]=rctcnt++;

    }

     printframe();

     pfault++;

    }

    }

     printf("\nNo. of page faults occured : %d ",pfault); 

    }

     pfaultcheck1()

    {

    for(k=0;k

  • 8/13/2019 OS LAB Final (2)

    48/56

     printf("%d ",frame[l]); 

    }

    }

    Register No: 100606314011  Pageno:48 

  • 8/13/2019 OS LAB Final (2)

    49/56

    OUTPUT: 

    Enter the no. of frames:3Enter the size of reference string:20

    Enter the reference string:7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 11.FIFO 2.LRUEnter the choice:1

    ********FIFO**********Reference Str Frame7 7 * *0  7 0 *1  7 0 12  2 0 1

    0 3  2 3 10  2 3 04  4 3 0

    2  4 2 03  4 2 30 

    0 2 33 2 

    1  0 1 32  0 1 2

    0 1 

    7 7 1 20  7 0 21  7 0 1 No. of Page Faults Occured : 15 [080606314005@localhost ~]$

    [student@localhost ~]$ ./a.outEnter the no. of frames:3 Enter the size of reference string:20

    Enter the reference string:7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 11. FIFO 2.LRUEnter the choice:2

    ********LRU********Reference Str Frame7 7 * *0  7 0 *1 

    7 0 12  2 0 10 

    3  2 0 30 

    4  4 0 32  4 0 23  4 3 20 0 3 2

    Register No: 100606314011  Pageno:49 

  • 8/13/2019 OS LAB Final (2)

    50/56

    3 2 1  1 3 22 0  1 0 21 7  1 0 70 1 

     No. of page faults occured : 12

    RESULT: 

    Thus the above program for the implementation of memory management scheme-II has been executed successfully .

    Register No: 100606314011  Pageno:50 

  • 8/13/2019 OS LAB Final (2)

    51/56

    EX.NO:10  IMPLEMENTATION OF CONTINUOUS FILE ALLOCATION 

    DATE:  TECHNIQUES 

    AIM: To write a C program for the implementation of continuous file allocation techniques.

    ALGORITHM: 

    Step 1: Get the file id , starting location and number of blocks, from the user.

    Step 2: Disk addresses define a linear ordering on the disk.

    .  Step 3: If the file is n blocks /arg and starts at location b, then it occupies blocks

     b,b+1,b+2,……b+n. 

    Step 4: If two files process to the save address block an error message will be displayed.

    Register No: 100606314011  Pageno:51 

  • 8/13/2019 OS LAB Final (2)

    52/56

    PROGRAM: #include

    int a[20],num=0,fid[10],length[10],start[10];

    void fieldescriptor(); 

    void fieldescriptor()

    {

    int i;

     printf("\nFile id\tStarting address\tLength\n");for(i=0;i

  • 8/13/2019 OS LAB Final (2)

    53/56

    goto l;

    }

    for(i=st;i

  • 8/13/2019 OS LAB Final (2)

    54/56

    OUTPUT: 

    [student@localhost ~]$ vi ex10.c

    [student@localhost ~]$ gcc ex10.c

    [student@localhost ~]$ ./a.out

    File Allocation Technique: CONTIGUOUS ALLOCATION METHOD

    Memory Before Allocation:

    0 1 2 3 4 5 6 7 8 9 10  11 12 13 14 15

    0 0 0 0 0 0 0 0 0 0 0  0 0 0 0  0

    Enter the FILE ID:2

    Enter the Number of Blocks the File Occupies:5

    Enter the Starting Address:2

    File id Starting address Length 

    2 2 5

    Memory After Allocation 

    0 1 2 3 4 5 6 7 8 9 10  11 12 13 14 15

    0 0 2 2 2 2 2 0 0 0 0  0 0 0 0  0

    DO you want to Continue ?

    1.Yes2.No

    1

    Enter the FILE ID:3

    Enter the Number of Blocks the File Occupies:6

    Enter the Starting Address:9

    File id Starting address Length 

    2 2 5

    3 9 6

    Memory After Allocation 

    0 1 2 3 4 5 6 7 8 9 10  11 12 13 14 15

    0 0 2 2 2 2 2 0 0 3 3  3 3 3 3  0

    DO you want to Continue? 1.Yes

    2.No

    2

    RESULT: 

    Thus the above program for the implementation of continuous file allocation techniques has been executed successfully.

    Register No: 100606314011  Pageno:54 

  • 8/13/2019 OS LAB Final (2)

    55/56

     

    Register No: 100606314011  Pageno:55 

  • 8/13/2019 OS LAB Final (2)

    56/56