OS LAB Final
OS LAB Final
To write a C program using system calls fork(), getpid(), exit() and wait(). ALGORITHM: Step 1: Start the program. Step 2: Initialize the process id number. Step 3: Create a process using fork() system call. Step 4: If process id<0 print error. Step 5: If process id=0 means then print child process id number and parent process id number. Step 6: Else wait until the process gets completed
Pageno:1
PROGRAM:
#include<stdio.h> int main(void) { int pid; pid=fork(); if(pid<0) { printf("error"); exit(0); } else if(pid==0) { printf("\n child processid is %d",getpid()); printf("\n parent processid is %d",getppid());
Pageno:2
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 executed successfully.
Pageno:3
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.
Pageno:4
PROGRAM: #include<stdio.h> #include<sys/types.h> #include<dirent.h> 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); }
Pageno:5
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.
Pageno:6
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.
Pageno:7
PROGRAM: #include<stdio.h> #include<fcntl.h> #include<sys/types.h> 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); }
Pageno:8
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
Pageno:9
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.
Pageno:10
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<pattern><file>\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++) {
Pageno:11
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.
Pageno:12
IMPLEMENTATION OF LS COMMANDS
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.
Pageno:13
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); }
Pageno:14
OUTPUT: [student@localhost ~]$ vi ex3b.c [student@localhost ~]$ gcc ex3b.c [student@localhost ~]$./a.out muni calls3.c . a.out one .. two
RESULT:
Thus the above program using ls commands has been executed successfully.
Pageno:15
EX.NO:4(a) DATE:
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.
Pageno:16
Printf(enter the number of process:); Scanf(%d,&n); For(i=0;i<n;i++) { Printf(enter the process name,arrival time and brust time:); Sacnf(%s%d%d,&pn[i],&arr[i],&bur[i]); } For(i=0;i<n;i++) { For(j=0;j<0;j++) { If (arr[i]<arr[j]) { Temp=arr[i]; Arr[i]=arr[j]; Arr[j]=temp; Temp=bur[i]; Bur[i]=bur[j]; Bur[j]=temp; Strcpy(t,pn[i]); Strcpy(pn[i];pn[j]); Strcpy(pn[j],t); } } } For(i=0;i<n;i++) { If(i==0) Star[i]=arr[i]; Else star[i]=finish[i-1]; wt[i]=star[i]arr[i];
Register No: 100606314011
Pageno:17
finish[i]=atar[i]+bur[i]; tat[i]=finish[i]-arr[i]; } Printf(\npname arrtime burtime waittime start tat finish); For(i=0;i<n;i++) {
Pageno:18
OUTPUT:
RESULT:
Thus the above program FCFS scheduling has been executed successfully.
Pageno:19
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.
Pageno:20
Pageno:21
{ 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; }
Pageno:22
OUTPUT:
[student@localhost ~]$ vi ex4b.c [student@localhost ~]$ gcc ex4b.c [student@localhost ~]$ ./a.out Enter the no of process:5 Process Burst 1 6 2 7 3 4 4 1 5 3 Process 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
Pageno:23
EX.NO:5(a) DATE:
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.
Pageno:24
} for(i=1;i<=k;i++) for(j=i+1;j<=k;j++) { if(a[i].p>a[j].p) { temp=a[i].p; a[i].p=a[j].p; a[j].p=temp; temp=a[i].process; a[i].process=a[j].process; a[j].process=temp; temp1=a[i].no; a[i].no=a[j].no; a[j].no=temp1; }
Pageno:25
} for(i=1;i<=k;i++) a[i].waiting=a[i1].waiting+a[i].process; for(i=1;i<k;i++) { waiting1=waiting1+a[i].waiting; } printf("\nProcess\t\tWaiting\t\tTurn around\tPriority\n"); for(i=0;i<k;i++) { l=i+1; printf("\n%d\t\t%d\t\t%d\t\t%d",a[l].no,a[i].waiting,a[l].waiting,a[i].p+1); 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; }
Pageno:26
OUTPUT:
[student@localhost ~]$ vi ex5a.c [student@localhost ~]$ gcc ex5a.c [student@localhost ~]$ ./a.out Enter the no of process:5 Process Burst 1 94 2 7 3 12 4 1 5 6 Enter 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.
Pageno:27
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.
Pageno:28
PROGRAM: #include <stdio.h> #include <stdlib.h> 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<n; i++) { printf("Enter burst time of the process %d: ",i+1); pr[i].pid = i+1;
scanf("%d",&pr[i].bt); pr[i].bt_bal = pr[i].bt;
} printf("Enter the time quantum no. : "); scanf("%d",&tq); for( i=0;i<n;i++) sum_bt += pr[i].bt; printf("\nsum of bt = %d\n",sum_bt); k=0; do { for( i=0;i<n;i++) if( pr[i].bt_bal > 0 && pr[i].bt_bal <= tq ) {
tq_used += pr[i].bt_bal; pr[i].tat = tq_used;
pr[i].wt = pr[i].tat pr[i].bt; pr[i].bt_bal = 0; gantt[0][k] = pr[i].pid; gantt[1][k] = tq_used; k++; } else if( pr[i].bt_bal >0 )
Pageno:29
{ 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 GANTT Chart\n\n"); printf("PID: ");
for( i=0; i<k; i++) printf("%4d",gantt[0][i]); printf("\n\nTime: "); for( i=0; i<k; i++) printf("%4d",gantt[1][i]); for( i=0;i<n;i++) sum_wt += pr[i].wt; for( i=0;i<n;i++) sum_tat += pr[i].tat; printf("\n\nPID: "); for( i=0;i<n;i++) printf("%4d",i+1); printf("\nBtime:"); for( i=0;i<n;i++) printf("%4d",pr[i].bt); printf("\nTAT: "); for( i=0;i<n;i++) printf("%4d",pr[i].tat); printf("\nWtime:"); for( i=0;i<n;i++) printf("%4d",pr[i].wt);
printf("\n\nTotal waiting time = %d\n",sum_wt); printf("Average waiting time = %.2f\n",(float)sum_wt/n); printf("\nTotal turn around time = %d\n",sum_tat); printf("Average turn around time = %.2f\n\n",(float)sum_tat/n); return 0; }
Pageno:30
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 5 TAT: 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
Pageno:31
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.
Pageno:32
Pageno:33
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 application has been executed successfully.
Pageno:34
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.
Pageno:35
Pageno:36
buffer[in].roll=roll1;
signal(full); in=(in+1)%BUFFER_SIZE; counter++;
}
break; case 2: if(in!=out) { wait(full);
} } }
Pageno:37
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:2012 Enter 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 1 1. Producer 2. Consumer 3. Display 4. Exit Enter 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.
Pageno:38
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.
Pageno:39
PROGRAM: #include<stdio.h>
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<nmp;i++) scanf("%d",&mp[i]); memcpy(mp1,mp,10); printf("\nEnter no.of processes:"); scanf("%d",&np); printf("Enter the size of each process:\n"); for(i=0;i<np;i++) {
printf("\nP-%d :",i); scanf("%d",&p[i]); }
printf("\nFirstFit Strategy\n"); Firstfit(); memcpy(mp,mp1,10); printf("\n\nBestFit Strategy\n"); Bestfit(); memcpy(mp,mp1,10); printf("\n\nWorstFit Strategy\n"); Worstfit(); } Firstfit() { for(i=0;i<np;i++) { aflag=0; for(j=0;j<nmp;j++) { if(mp[j]>=p[i]) { printf("\nPrs %d(%dkb) alctd to Mmy Ptn %d(%dkb)",i,p[i],j,mp[j]); mp[j]=mp[j]-p[i]; aflag=1; break; }
Pageno:40
fsize=mp[j]p[i]; bfmp=j; aflag=1; } } 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=10000; } } } Worstfit() {
int bfmp,fsize=0; for(i=0;i<np;i++) { aflag=0; for(j=0;j<nmp;j++) { if(mp[j]>=p[i] && ((mp[j]-p[i])>fsize)) {
Pageno:41
} } 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; } } }
Pageno:42
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 Strategy Prs 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 been executed successfully.
Pageno:43
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.
Pageno:44
printf(\n\n Memory Management Scheme II); printf("\n\nEnter the No. of Frames:"); scanf("%d",&nf); printf("\nEnter the Size of Reference String:"); scanf("%d",&sref); printf("\nEnter the Reference String:"); for(i=0;i<sref;i++) scanf("%d",&refstr[i]); printf("\n\n1.FIFO\t2.LRU\n"); printf("\n\nEnter the choice:"); scanf("%d",&ch); switch(ch) {
case 1: fifo(); break; case 2: lru(); break; default: return 0; } } fifo() { printf("\n\t********FIFO**********"); printf("\n\nReference Str\tFrame\n"); for(i=0;i<sref;i++) { printf("\n%d\t\t",refstr[i]); pfaultcheck(); if(flag!=1) {
Pageno:45
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<nf;k++) { if(frame[k]==refstr[i]) { flag=1; break; }
else flag=0; } } void lru() { printf("\n\t********LRU********\n"); printf("\nReference Str\tFrame\n"); for(i=0;i<sref;i++) { printf("\n%d\t\t",refstr[i]); pfaultcheck1(); if(flag!=1) { if(count[nf-1]==0)//intial frame filling-fifo { frame[j]=refstr[i]; count[j]=rctcnt++; j++; } else//rest---lru { findminframe();
Pageno:46
frame[minfr]=refstr[i]; count[minfr]=rctcnt++; } printframe(); pfault++; } } printf("\nNo. of page faults occured : %d ",pfault); } pfaultcheck1() { for(k=0;k<nf;k++) { if(frame[k]==refstr[i]) { count[k]=rctcnt++; flag=1; break; }
else flag=0; } } findminframe() { mincnt=count[0]; minfr=0; for(i1=0;i1<nf;i1++)//finding mincount-lru frame { if(mincnt>count[i1]) { mincnt=count[i1]; minfr=i1; } } } printframe() { for(l=0;l<nf;l++) {
Pageno:47
printf("%d ",frame[l]); } }
Pageno:48
OUTPUT: Enter 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 1 1.FIFO 2.LRU Enter the choice:1 ********FIFO********** Reference Str Frame 7 7** 0 70* 1 701 2 201 0 3 0 4 2 3 0 3 2 1 2 0 1 7 712 0 702 1 701 No. of Page Faults Occured : 15 [080606314005@localhost ~]$
[student@localhost ~]$ ./a.out Enter 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 1 1. FIFO 2.LRU Enter the choice:2 ********LRU******** Reference Str Frame 7 7** 0 70* 1 701 2 201
013 012
203
RESULT: Thus the above program for the implementation of memory management scheme-II has been executed successfully .
Pageno:50
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.
Pageno:51
PROGRAM: #include<stdio.h>
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<num;i++) printf("%d\t\t%d\t\t%d\n",fid[i],start[i],length[i]); } void display() {
int i; for(i=0;i<16;i++) printf("%2d ",i); printf("\n"); for(i=0;i<16;i++) printf("%2d ",a[i]); } int main() {
int i,n,k,temp,st,id,l,flag=0,cho; for(i=0;i<16;i++) a[i]=0;
printf("\n\tFile Allocation Technique: CONTIGUOUS ALLOCATION METHOD\n"); printf("\n\nMemory Before Allocation:\n"); display(); while(1) { printf("\n\nEnter the FILE ID:"); scanf("%d",&id); printf("\nEnter the Number of Blocks the File Occupies:"); scanf("%d",&l); fid[num]=id; length[num]=l; printf("\nEnter the Starting Address:"); l:scanf("%d",&st); flag=0; if((st+l)>16) { printf("\nSorry the given Memory goes out of Space!!!"); printf("\nEnter the Starting Address:");
Pageno:52
goto l; } for(i=st;i<(st+l);i++) { if(a[i]!=0) { flag=1; break; } } if(flag==0) { start[num]=st; for(i=st;i<(st+l);i++) a[i]=id; } else {
printf("\n\nSorry the given blocks are already occupied"); printf("\n\nEnter the NEW Starting Address:"); goto l; } flag=0; num++; fieldescriptor();
printf("\n\nMemory After Allocation\n"); display(); printf("\n\nDO you want to Continue ?\n1.Yes\n2.No\n"); scanf("%d",&cho); if(cho==2) exit(0); } return 0; }
Pageno:53
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.Yes 2.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
Pageno:55