Operating System Lab Manual
Operating System Lab Manual
Ex.No:1 Date:
PROBLEM STATEMENT:
To write a C program to illustrate the use of system calls of UNIX operating system such as fork, exec, getpid, exit, wait, close, stat, opendir, readdir.
PROBLEM DESCRIPTION:
A system call is the mechanism used by an application program to request service from the operating system. A child process is created by forking the shell, and the child process is overlaid, once again by exec, with the code associated with the program to be executed. In most systems, a parent process can create an independently executing child process. The parent process may then issue a wait system call, which suspends the execution of the parent process while the child executes. When the child process terminates, it returns an exit status to the operating system, which is then returned to the waiting parent process. The parent process then resumes execution fcntl.h - defines file control option. sys/types.h - defines data type used in system source code or it define primitive system datatype sys/stat.h - defines data return by the stat function. pid - process identification number fork() - creation of new process or child process. exit(-1) - denotes the failure of the program. execlp - replaces the current process image with the new process image created from the executable file specified in file name. wait(0) - suspends the execution of the current process. exit(0) - denotes the success of the program. stat - get file status. mode - permission given to the user to access file. user ID - identify user within the kernel by an unsigned integer. group ID - numeric value used to represent specific group. getpid() - to retrive the process ID. getppid() - to retrive parent process ID. sleep(1) - suspend execution for an interval 1sec. dirent.h - format of directory entries.
Opendir(.) to open a current directory Readdir - to read a current directory Closedir to close a current directory Direntp->d_name to list all file names of the current directory.
PROGRAM:
#include<fcntl.h> #include<sys/types.h> int main(int argc,char *argv[]) { int pid; pid=fork(); printf("Process ID is%d",pid); if(pid<0) { printf("Fork failed"); exit(-1); } else if(pid==0) { execlp("/bin/ls","ls",0); } else { wait(0); printf("Childcomplete"); exit(0); } }
PROGRAM:
#include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> void main() { struct stat s; char fname[20]; printf("Enter the file name"); scanf("%s",fname); stat(fname,&s); printf("File Inode\t%d\n",s.st_ino); printf("File Size\t%d\n",s.st_size); printf("File Mode\t%d\n",s.st_mode); printf("User ID\t%d\n",s.st_uid); printf("Group ID\t%d\n",s.st_gid); }
PROGRAM:
#include<stdio.h> #include<sys/types.h> #include<unistd.h> int main(void) { pid_t childpid; int x; childpid = fork(); if ( childpid == 0) {
printf("In the child process\n"); printf("------------------------\n"); printf("This is process %d \n", getpid()); printf("The parent of this process has id %d \n", getppid()); printf("childpid = %d \n", childpid); } else { printf("In the parent process\n"); printf("--------------------------\n"); printf("This is process %d \n", getpid()); printf("The parent of this process has id %d \n", getppid()); printf("childpid = %d \n", childpid); sleep(1); } return 0; }
PROGRAM:
#include <stdio.h> #include <dirent.h> main() { DIR *dirp; struct dirent *direntp; dirp = opendir( "." ); while ( (direntp = readdir( dirp )) != NULL ) (void)printf( "%s\n", direntp->d_name ); (void)closedir( dirp ); return (0); }
CONCLUSION:
The use of system calls of UNIX operating system such as fork,exec,getpid,exit,wait,close,stat,opendir,readdir was successfully executed.
PROBLEM STATEMENT:
To write a C program using the I/O system calls of UNIX operating system such as open, read, write.
PROBLEM DESCRIPTION:
A program that needs access to a file stored in a filesystem uses the open system call. This system call allocates resources associated to the file (the file descriptor), and returns a handle that the process will use to refer to that file from then on.After using the file, the process should use the close system call. creat create new file. S_IWRITE|S_IREAD permitted to read and write. open to open a file. O_CREAT if file exist it opens or else it will create a new file. Strlen() count the number of bytes. write write from buffer to file. read reads from file to buffer. malloc allocates memory close to close a file
PROGRAM:
#include<stdio.h> #include<sys/stat.h> #include<fcntl.h> void main() { if(creat("sree.c",S_IWRITE|S_IREAD)!=-1)
PROGRAM:
#include<stdio.h> #include<sys/stat.h> #include<fcntl.h> void main() { if(open("sree.c",O_CREAT)==-1) printf("file is not opened"); else printf("File is opened"); }
PROGRAM:
#include<stdio.h> #include<sys/stat.h> #include<string.h> void main() { int n,i; char s[20]; n=creat("sree.c",S_IWRITE|S_IREAD); printf("Enter the string where '.' denotes end of file\n"); for(i=0;s[i]!='.';i++) { scanf("%s",s); if(s[i]=='.') break; else write(n,s,strlen(s)); }
close(n); }
PROGRAM:
#include<stdio.h> #include<fcntl.h> #include<malloc.h> void main() { int n; void *buf; buf=malloc(20); n=open("sree.c",O_CREAT); read(n,buf,20); printf("Contents of file is:\n%s",buf); close(n); }
2.OPEN A FILE:
cc op.c ./a.out File is opened
3.WRITE A FILE:
cc wri.c ./a.out Enter the string where '.' denotes end of file os system.
CONCLUSION:
I/O system calls of UNIX operating system such as open, read, write using C was successfully executed.
PROBLEM STATEMENT:
To write a C program to simulate UNIX commands like ls and grep.
PROBLEM DESCRIPTION:
This program simulates the ls command and grep command to list all the files in the current directory and finds for the specified pattern within a given file. ls to list all the files grep it allows us to search for a pattern in a file argc count of command line arguments argv[] list of command line arguments scandir list files and directories inside the specified path alphasort used as the comparison function for the scandir() function to sort the directory entries into alphabetical order strstr - locates the first occurrence in the string pointed by the sequence of bytes fgets reads in atmost one less than size characters from stream and stores them into the buffer
PROGRAM:
#include<stdio.h> #include<dirent.h> int main() { struct dirent **namelist; int n,i;
PROGRAM:
#include<stdio.h> #include<string.h> #define max 1024 void usage() { printf("usage:\t./grep filename pattern \n"); printf("example: ./grep grep.c int\n"); } int main(int argc,char *argv[]) { FILE *fp; char fline[max]; char *newline; int count=0; int occurences=0; if(argc!=3) { usage(); exit(1); }
if(!(fp=fopen(argv[1],"r"))) { printf("grep : Couldnot open file : %s\n",argv[1]); exit(1); } while(fgets(fline,max,fp)!=NULL) { count++; if(newline=strchr(fline,'\n')) *newline='\0'; if(strstr(fline,argv[2])!=NULL) { printf("%s: %d %s\n",argv[1],count,fline); occurences++; } } printf(total number of occurrences %d,occurrences); }
2.SIMULATION OF GREP:
Cc sgrep.c ./a.out gv.c a gv .c : 4a gv..c : 6a total number of occurrences : 2
CONCLUSION:
Thus the simulation of UNIX commands is executed successfully.
CPU SCHEDULING - I
Ex.No: 4 Date:
PROBLEM STATEMENT:
To implement FCFS and SJF scheduling algorithms using C.
1.FCFS: ALGORITHM:
1: Get the number of processes and burst time. 2: The process is executed in the order given by the user. 3: Calculate the waiting time and turn around time. 4: Display the gantt chart,avg waiting time and turn around time.
PROGRAM:
#include<stdio.h> void main(int argc,char *argv[]) { int i,j=0,n,burst[10],wait[10],turn[10]; float w=0,t=0; printf("Enter the no. of processes"); scanf("%d",&n); burst[0]=0;
printf("Enter the burst time"); for(i=1;i<=n;i++) { scanf("%d",&burst[i]); } printf("\n\nGantt chart\n"); printf("\n________________________________________________________\n"); for(i=1;i<=n;i++) printf("\tP%d\t|",i); printf("\n________________________________________________________\n"); for(i=0;i<=n;i++) { j=j+burst[i]; wait[i+1]=j; turn[i]=j; printf("%d\t\t",j); } for(i=1;i<=n;i++) w=w+wait[i]; for(i=0;i<=n;i++) t=t+turn[i]; w=w/n; t=t/n; printf("\nAverage waiting time %0.2f",w); printf("\nAverage turnaroundtime %0.2f",t); }
2.SJF: ALGORITHM:
1: Get the number of processes and burst time. 2: Sort the process based on the burst time in ascending order. 3: Calculate the waiting time and turn around time. 4: Display the gantt chart,avg waiting time and turn around time.
PROGRAM:
#include<stdio.h> void main(int argc,char *argv[]) { int b[10],temp,i,j,n,wait[10],burst[10],turn[10]; float w=0,t=0; printf("Enter the no. of processes"); scanf("%d",&n); burst[0]=0; b[0]=0; printf("Enter the burst time"); for(i=1;i<=n;i++)
{ scanf("%d",&burst[i]); } for(i=1;i<=n;i++) b[i]=burst[i]; for(i=1;i<n;i++) for(j=i+1;j<=n;j++) if(b[i]>b[j]) { temp=b[i]; b[i]=b[j]; b[j]=temp; } printf("\nGantt chart"); printf("\n________________________________________________________\n"); for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(b[i]==b[j]) printf("P%d|\t",j); printf("\n_________________________________________________________\n"); j=0; for(i=0;i<=n;i++) { j=j+b[i]; wait[i+1]=j; turn[i]=j; printf("%d\t",j); } for(i=1;i<=n;i++) w=w+wait[i]; for(i=0;i<=n;i++) t=t+turn[i]; w=w/n; t=t/n; printf("\nAverage waiting time is %0.2f",w); printf("\nAverage turnaroundtime is %0.2f",t); }
2.SJF:
cc sjf.c ./a.out Enter the no. of processes 3 Enter the burst time2 1 3 Gantt chart ________________________________________________________ P1| P2| P3| ________________________________________________________ 0 1 3 6 Average waiting time is 1.33 Average turn around time is 3.33
CONCLUSION:
FCFS and SJF scheduling algorithms is implemented using C and executed.
CPU SCHEDULING - II
Ex.No:5 Date:
PROBLEM STATEMENT:
To implement Round Robin and Priority scheduling algorithms using C.
ALGORITHM:
1: Initialize all the structure elements 2: Receive inputs from the user to fill process id,burst time and arrival time. 3: Calculate the waiting time for all the process id. i) The waiting time for first instance of a process is calculated as: a[i].waittime=count + a[i].arrivt ii) The waiting time for the rest of the instances of the process is calculated as: a) If the time quantum is greater than the remaining burst time then waiting time is calculated as: a[i].waittime=count + tq b) Else if the time quantum is greater than the remaining burst time then waiting time is calculated as: a[i].waittime=count - remaining burst time 4: Calculate the average waiting time and average turnaround time 5: Print the results of the step 4.
PROGRAM:
#include<stdio.h> void main() { int b[10],i,j=1,n,temp,burst[10],wait[10],turn[10],p[10],a=1,q,tat[10],t1=0; float t=0,w=0; printf("Enter the no of process & Q"); scanf("%d%d",&n,&q); burst[0]=0;
b[0]=0; tat[0]=0; p[0]=0; printf("Enter burst time"); for(i=1;i<=n;i++) scanf("%d",&burst[i]); for(i=1;i<=n;i++) b[i]=burst[i]; printf("\n\n\t\t Gantt chart\n"); printf("-------------------------------------------------------\n"); for(i=1;i<=n;i++) { if(b[i]>0) { a=1; printf("P%d\t|",i); if(b[i]>=q) { t1=t1+q; p[j]=t1; j++; } else if(b[i]<q) { t1=t1+b[i]; p[j]=t1; j++; } b[i]=b[i]-q; if(b[i]<=0) tat[i]=t1; } else a++; if(a==n+1) break; if(i==n) i=0; } printf("\n---------------------------------------------------------\n"); for(i=0;i<j;i++) printf("%d\t",p[i]); for(i=1;i<=n;i++) { t=t+tat[i]; w=w+tat[i]-burst[i];
} w=w/n; t=t/n; printf("\nThe average waiting time is %0.2f",w); printf("\nThe average turn around time is %0.2f",t); }
ALGORITHM:
1: Get the number of processes, priority and burst time. 2: Sort the process based on the priority in ascending order 3: Calculate the waiting time and turn around time. 4: Display the gantt chart,avg waiting time and turn around time.
PROGRAM:
#include<stdio.h> void main(int argc,char *argv[]) { int temp,i,n,j,p[10],burst[10],b[10],wait[10],turn[10],b1[10],p1[10]; float w=0,t=0; printf("Enter the number of processes"); scanf("%d",&n); burst[0]=0; for(i=1;i<=n;i++) { printf("Enter the Burst Time and Priority"); scanf("%d%d",&b1[i],&p[i]); } for(i=1;i<=n;i++) p1[i]=p[i]; for(j=1;j<=n;j++) p1[j]=p[j]; for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) if(p[i]>p[j]) { temp=p[i]; p[i]=p[j];
p[j]=temp; temp=b[i]; b[i]=b[j]; b[j]=temp; } for(i=1;i<=n;i++) printf("%d",p[i]); printf("\n\t\t\tGanttChart\n"); printf("\t_______________________\n"); for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(p[i]==p1[j]) { b[i]=b1[j]; printf("\t\tp%d",j); } printf("\t\n\t____________________\n\t"); j=0; for(i=0;i<=n;i++) { j=j+b[i]; wait[i+1]=j; turn[i]=j; printf("%d\t\t",j); } for(i=1;i<=n;i++) { t=t+turn[i]; w=w+wait[i]; } w=w/n; t=t/n; printf("\nThe average Waiting Time %f",w); printf("\nThe average Turnaround Time %f",t); }
PRIORITY SCHEDULING:
Enter the number of processes 3 Enter the Burst Time and Priority 2 3 Enter the Burst Time and Priority 2 1 Enter the Burst Time and Priority 4 2 123 GanttChart _______________________ p2 p3 p1 ____________________ 0 2 6 8 The average Waiting Time 2.666667 The average Turnaround Time 5.333333
CONCLUSION:
Round Robin and priority scheduling algorithms is implemented using C and executed.
PRODUCER-CONSUMER PROBLEM
Ex.No:6 Date:
PROBLEM STATEMENT:
To write a C program to implement the Producer & consumer Problem (Semaphore).
PROBLEM DESCRIPTION:
The producer-consumer problem (also known as the bounded-buffer problem) is a classical example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer. The producer's job is to generate a piece of data, put it into the buffer and start again. At the same time the consumer is consuming the data (i.e. removing it from the buffer) one piece at a time. The problem is to make sure that the producer won't try to add data into the buffer if it's full and that the consumer won't try to remove data from an empty buffer. The solution for the producer is to go to sleep if the buffer is full. The next time the consumer removes an item from the buffer, it wakes up the producer who starts to fill the buffer again. In the same way the consumer goes to sleep if it finds the buffer to be empty. The next time the producer puts data into the buffer, it wakes up the sleeping consumer. The solution can be reached by means of inter-process communication, typically using semaphores. An inadequate solution could result in a deadlock where both processes are waiting to be awakened.
ALGORITHM:
1: The Semaphore mutex, full & empty are initialized. 2: In the case of producer process a)Produce an item in to temporary variable. b)If there is empty space in the buffer check the mutex value for enter into the critical section. c)If the mutex value is 0, allow the producer to add value in the temporary variable to the buffer. 3: In the case of consumer process a)It should wait if the buffer is empty b)If there is any item in the buffer check for mutex value, if the mutex==0,remove item from buffer c)Signal the mutex value and reduce the empty value by 1.Consume the item. 4: Print the result
PROGRAM :
#include<stdio.h> char buf[20],p[20],cos[20]; int mutex,i,k,c,sz,n; mutex=0; void prosig() { mutex=mutex+1; } void consig() { mutex=mutex-1; } int buffer(int mutex) { if(mutex==0) return 1; else return 0; } void producer(int sz) { int c; c=buffer(mutex); if(c==1) { printf("\nProducer can produce the item and give $ for exit\n"); i=0; while(i<sz&&(p[i]=getchar())!='$') { buf[i]=p[i]; i++; } k=i; prosig(); printf("\nProduction done successfully\n"); } else if(k<sz) { printf("Producer can also produce items"); while((p[k]=getchar())!='$') { buf[k]=p[k]; k++; } prosig();
printf("\nProduction done successfully\n"); } else if(k>=sz) { printf("\nBuffer is full,can't produce\n"); } } void consumer() { int c1; c1=buffer(mutex); if(c1==0) { printf("\nConsumer can consume item\n"); for(i=0;i<k;i++) cos[i]=buf[i]; printf("\nConsumed item is:\n"); for(i=0;i<k;i++) printf("\n%c",cos[i]); consig(); printf("\nSuccessfully done\n"); } else { printf("\nBuffer is empty,can't consume\n"); } } int main() { int op,sz; printf("Enter the buffer size"); scanf("%d",&sz); do { printf("\n1.Producer\t2.Consumer\t3.Exit\n"); printf("\nEnter your choice\n"); scanf("%d",&op); switch(op) { case 1: producer(sz); break; case 2: consumer(); break; case 3:
30 30 40 100
CONCLUSION:
The Producer & consumer Problem (Semaphore) is implemented using C and executed.
PROBLEM STATEMENT:
To implement first fit, best fit and worst fit using C.
ALGORITHM:
1: Get the number of free space available. 2: Get the starting address of each free space and how much space available. 3:.While getting the address and space we have to check whether there is duplication, if there is duplication then give the error message for duplication & get the address and space once again. 4: Get the space for the process. 5: If choice is first fit, then search the first memory location from the available list its size should be greater than or equal to the process size an or equal to available space in fifo order. 6: .If choice is best fit, and then sort the available list in ascending order based on the space. and search the first memory location from the available list its size should be greater than or equal to the process size an or equal to available space in FIFO order. 7: .If choice is worst fit, then sort the available list in descending order based on the space. and search the first memory location from the available list its size should be greater than or equal to the process size an or equal to available space in FIFO order. 8: If there is no sufficient space output the error message. 9: Display the process and its corresponding allocated memory space
PROGRAM:
#include<stdio.h> #include<conio.h> int ps[20],ms[20],bs[20],ws[20]; int op,p,m,j,i,k,temp,mm,mm1=0,b[20],w[20]; void firstfit(int *ps,int *ms,int p,int m) { printf("\nPROCESS\t MEMORYBLOCK\tREMAINING MEMORY\n"); for(i=0;i<p;i++) {
for(j=0;j<m;j++) { if(ps[i]<=ms[j]) { printf("\n%d(%dk)\t\t%d(%dk)\t%d",i+1,ps[i],j+1,ms[j],ms[j]-ps[i]); ms[j]=0; break; } } } } void bestfit(int *ps,int *bs,int *b,int p,int m) { printf("\nPROCESS\t MEMORYBLOCK\tREMAINING MEMORY\n"); for(i=0;i<p;i++) { for(j=0;j<m;j++) { if(ps[i]<=bs[j]) { printf("\n%d(%dk)\t\t%d(%dk)\t%d",i+1,ps[i],b[j]+1,bs[j],bs[j]-ps[i]); bs[j]=0; break; } } } } void worstfit(int *ps,int *ws,int *w,int p,int m) { printf("\nPROCESS\t MEMORYBLOCK\tREMAINING MEMORY\n"); for(i=0;i<p;i++) { for(j=0;j<m;j++) { if(ps[i]<=ws[j]) { printf("\n%d(%dk)\t\t%d(%dk)\t%d",i+1,ps[i],w[j]+1,ws[j],ws[j]-ps[i]); ws[j]=0; break; } } } } void main() { int choice,b[20],w[20];
clrscr(); for(i=0;i<20;i++) { bs[i]=0; ws[i]=0; } printf("\nENTER THE SIZE OF MEMORY\t"); scanf("%d",&mm); printf("\nENTER THE NO.OF MEMORY BLOCKS:\t"); scanf("%d",&m); for(i=0;i<m;i++) { printf("\nMEMORY BLOCK %d:\t",i+1); scanf("%d",&ms[i]); mm1=ms[i]+mm1; if(mm<mm1) { printf("\nINSUFFICIENT MEMORY"); printf("\n\nNO. OF BLOCKS :%d",i++); m=i; break; } bs[i]=ms[i]; ws[i]=bs[i]; } printf("\n\nENTER THE NO. OF PROCESS:\t"); scanf("%d",&p); printf("\nENTER THE PROCESS SIZE\n"); for(i=0;i<p;i++) { printf("\nPROCESS %d:\t",i+1); scanf("%d",&ps[i]); } for(i=0;i<m;i++) { for(j=i+1;j<m;j++) { if(bs[i]>bs[j]) { temp=bs[i]; bs[i]=bs[j]; bs[j]=temp; } } } for(i=0;i<m;i++)
{ for(j=0;j<m;j++) { if(bs[i]==ms[j]) b[i]=j; } } for(i=0;i<m;i++) { for(j=i+1;j<m;j++) { if(ws[i]<ws[j]) { temp=ws[i]; ws[i]=ws[j]; ws[j]=temp; } } } for(i=0;i<m;i++) { for(j=0;j<m;j++) { if(ws[i]==ms[j]) w[i]=j; } } do { printf("\n\nENTER UR CHOICE\t"); scanf("%d",&choice); switch(choice) { case 1: firstfit(ps,ms,p,m); break; case 2: bestfit(ps,bs,b,p,m); break; case 3: worstfit(ps,ws,w,p,m); break; case 4: exit(0); break; }
} while(choice<=3); getch(); }
CONCLUSION:
Thus first fit, best fit and worst fit using C is implemented and executed.
PROBLEM STATEMENT:
To implement the concept of paging.
PROBLEM DESCRIPTION:
In computer operating systems that have their main memory divided into pages, paging (sometimes called swapping) is a transfer of pages between main memory and an auxiliary store, such as hard disk drive.Paging is an important part of virtual memory implemention in most contemporary general-purpose operating systems, allowing to easily use disk storage for data that do not fit into physical RAM. Paging is usually implemented as a task built into the kernel of the operating system. The Main functions of paging are performed when a program tries to access pages that do not currently reside in RAM, a situation causing page fault.
ALGORITHM:
1: Read the base address, page size, number of pages and memory unit. 2: If the memory limit is less than the base address display the memory limit is less than limit. 3: Create the page table with the number of pages and page address. 4: Read the page number and displacement value. 5: If the page number and displacement value is valid, add the displacement value with the address corresponding to the page number and display the result. 6: Display the page is not found or displacement should be less than page size.
PROGRAM:
#include<stdio.h> int i,j,k,ps,np,l,op,np1,np2,fn,f=0; char p1[50][50],p2[50][50]; int pgtb(int r,int fn,int np) { for(i=0;i<np;i++) { printf("\n\t%d\t\t%d",i,r++); if(i>np) printf("\n\t%d\t\tPage Fault",i); }return(r); } void frame(int np1,int np2,int fn,int ps,char p1[50][50],char p2[50][50]) {
for(i=0;i<np1;i++) { if(i<fn) { printf("\n--------------------\n"); printf("\nFrame No:%d\n",i); for(j=0;j<ps;j++) printf("\t%c",p1[i][j]); }} k=np1; for(i=0;i<np2;i++) { if(k<fn) { printf("\n--------------------\n"); printf("\nFrame No:%d\n",k); k++; for(j=0;j<ps;j++) printf("\t%c",p2[i][j]); }}} int main() { printf("\nENTER THE PAGE SIZE:"); scanf("%d",&ps); printf("\nENTER NO OF FRAMES:"); scanf("%d",&fn); printf("\nENTER NO OF PAGES FOR PROCESS1:"); scanf("%d",&np1); printf("\nENTER NO OF PAGES FOR PROCESS2:"); scanf("%d",&np2); if(np1+np2>fn) printf("\nPage Fault will occur\n"); printf("\nPROCESS1"); printf("\n--------------------\n"); p1[np1][ps]; p2[np2][ps]; for(i=0;i<np1;i++) { printf("Enter CHAR for PAGE%d:",i); scanf("%s",&p1[i]); } printf("\nPROCESS2"); printf("\n--------------------\n"); for(i=0;i<np2;i++) { printf("Enter CHAR for PAGE%d:",i);
scanf("%s",&p2[i]); } while(1) { printf("\n1.Page Table for PROCESS1\n2.Page Table for PROCESS2\n3.Frame allotment\n4.Free Frame List\n5.Exit\n"); printf("ENTER YOUR CHOICE:"); scanf("%d",&op); switch(op) { case 1: printf("Page Table for PROCESS1"); printf("\nPAGE INDEX\tFRAME INDEX\n"); f=pgtb(f,fn,np1); break; case 2: printf("Page Table for PROCESS2"); printf("\nPAGE INDEX\tFRAME INDEX\n"); f=pgtb(f,fn,np2); break; case 3: frame(np1,np2,fn,ps,p1,p2); break; case 4: if(np1+np2>fn) printf("Page Fault has occurred"); else if(np1+np2==fn) printf("\nNo Free Frames"); else { printf("Free Frame List"); printf("\n----------------\n"); for(i=np1+np2;i<fn;i++) printf("%dth frame",i); } break; case 5: return(0); break; } } }
SAMPLE INPUT AND OUTPUT Enter the page size:2 Enter the number of frames :9 Enter the no of pages for process1: 2 Enter the no of pages for process2: 2 Process 1 ----------Enter char for page 0:a Enter char for page1:b Process 2 ----------Enter char for page 0:e Enter char for page 1:d 1.pagetable for process 1 2.pagetable for process2 3.frame allotment 4.free framelist 5.exit Enter your choice :1 Page table for process 1 Page index 0 1 frame index 0 1
Enter your choice :1 Page table for process 1 Page index 0 1 frame index 2 3
1.Page table for process 1 2.page table for process 2 3.frame allotment 4.free framelist 5.exit Enter your choice
--------------------Frame no :0 a --------------------Frame no: 1 b --------------------Frame no:2 c ---------------------Frame no:3 d ---------------------Free framelist 4th framelist 5th frame list 6th framelist 7th framelist 8th framelist
CONCLUSION:
Thus concept of paging is implemented and executed.
SAMPLE INPUT OUTPUT: Child:writing to the pipe Child:Executing Parent:Reading from pipe Parent:read test
30 30 40 100
void con(char fn,int n,int m) { int j; printf("Starting address:%d",m); pritnf("The address alloted are:"); for(j=0;j<n;j++) { printf("%d',m+j); } }
SAMPLE INPUT AND OUTPUT: Enter the no of files:2 Enter the diskspace:50 Enter the file name:t enter the size of the file:2 Enter the starting address:51 Invalid Enter the filename:y Enter the size of the file:2 Enter the starting address:49 Starting address:49 The address alloted are: 49 50
30 30 40 100