Skip to main content

Posts

Showing posts with the label os program

Write a program to implement following UNIX commands.

Write a program to implement following UNIX commands. wc -c <filename> displays number of characters for the given file. wc -w <filename> display number of words for given file. wc -l <filename> display number of line for given file. Program: #include <stdio.h> #include <stdlib.h> #include <string.h> void main(){ setbuf(stdout,NULL); FILE *fp; char s[80],a[5],c[5],temp[100],f[50],p[50],ch; int n; while(1){ printf("\nAP:>"); gets(s); if(strcmp(s,"exit")==0){ exit(0); } sscanf(s,"%s%s%s",&c,&a,&f); fp=fopen(f,"r"); if(strcmp(c,"wc")!=0){ printf("Invalid Command."); }else if(fp==NULL){ printf("File cannot be found."); }else if(strcmp(a,"-c")==0){ n=0; while(!feof(fp)){ ch = fgetc(fp); n++; } printf("\nNumber of character present in file:%d",n); }else if(strcmp(a,"-l")==0){ ...

Write simulation program for demand paging and show the page scheduling and total number of page faults according to LFU page replacement algorithm. Assume the memory of n frames.

Write simulation program for demand paging and show the page scheduling and total number of page faults according to LFU page replacement algorithm. Assume the memory of n frames. Program: #include <stdio.h> #include <stdlib.h> void main(){ setbuf(stdout,NULL); int f, tp ,al[50][50]={-1, -1}, i,j,pg[50],pf,x,queue[50]; printf("\nEnter total number of frames:"); scanf("%d",&f); printf("\nEnter total number of pages:"); scanf("%d",&tp); printf("\nEnter page string:"); for(i=0;i<tp;i++){ scanf("%d",&pg[i]); } pf=0; for(i=0;i<tp;i++){ for(j=0;j<f;j++){ if(al[j][i]==pg[i]){ break; } } if(f==j){ for(j=0;j<f;j++){ if(al[j][i]==-1){ al[j][i]=pg[i]; queue[++x]=pg[i]; pf++; break; } } if(f==j){ for(j=0;j<f;j++){ if(al[j][i]==queue[x]){ al[j][i]=pg[i]; pf++; x--; } } } } else{ queue[++...

Write a program to implement following UNIX commands

Write a program to implement following UNIX commands mv <source file> <target file> it moves file into target file. cp <source file> <target file> it copies file into target file. rm <target file> it deletes the file. Program: #include <stdio.h> #include <stdlib.h> #include <string.h> void main(){ setbuf(stdout,NULL); FILE *fp1, *fp2; char s[50], cm[20], path1[20], path2[20], ch; while(1){ printf("\nAP:>"); gets(s); if(strcmp(s,"exit")==0){ exit(0); }else{ sscanf(s,"%s%s%s",&cm,&path1,&path2); if(strcmp(cm,"rm")==0){ if(remove(path1)==0){ printf("File Deleted."); }else{ printf("File not deleted."); } }else if(strcmp(cm,"mv")==0){ fp1 = fopen(path1,"r"); fp2 = fopen(path2,"w"); while(!feof(fp1)){ ch = fgetc(fp1); fputc(ch,fp2); } remove(path1); }...

Write a program to implement ls command of UNIX with following options on DOS.

Write a program to implement ls command of UNIX with following options on DOS. ls -l to display long listing of files rowwise. ls -Q to display the filename in double quotes. ls -c to sort the files on last modification time of the files Program: #include <stdio.h> #include <stdlib.h> #include <dirent.h> #include <string.h> void main(){ setbuf(stdout,NULL); DIR *dir; struct dirent *ent; char s[80], c[5], f[50], ar[2], ch[2]; while(1){ printf("\nAP:>"); gets(s); if(strcmp(s,"exit")==0){ exit(0); } sscanf(s,"%s %s %s",&c,&ch,&f); if(strcmp(c,"ls")!=0){ printf("Invalid Command"); }else if(strcmp(ch,"-l")==0){ if((dir = opendir(f))==NULL){ perror("Unable to open directory."); exit(1); } while((ent=readdir(dir))!=NULL){ printf("\n%s",ent->d_name); } if(closedir(dir)!=0){ perror("Unable to close dir...

Write a simulation program for disk scheduling using FCFS algorithm. Accept total number of disk blocks, disk request string, direction of head movement and current head position from the user. Display the list of request order in which it is served. Also display the total number of head movements.

Write a simulation program for disk scheduling using FCFS algorithm. Accept total number of disk blocks, disk request string, direction of head movement and current head position from the user. Display the list of request order in which it is served. Also display the total number of head movements. Program: #include <stdio.h> #include <stdlib.h> void main(){ setbuf(stdout,NULL); int ap[50],i,th,n,cp; printf("\nEnter the number of memory blocks:"); scanf("%d",&n); printf("\nEnter the current position:"); scanf("%d",&cp); printf("\nEnter request string:"); for(i=0;i<n;i++){ scanf("%d",&ap[i]); } th=0; for(i=0;i<n;i++){ if(cp>ap[i]){ th+=cp-ap[i]; cp=ap[i]; } else{ th+=ap[i]-cp; cp=ap[i]; } printf(" %d",ap[i]); } printf("\nTotal head movements:%d",th); }

Write a program to implement cat command of UNIX on DOS.

Write a program to implement cat command of UNIX on DOS. cat <filename> to display files on the screen. cat < filename it is same as type command. cat > filename it is same as copy command. Program: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dirent.h> void main(){ setbuf(stdout,NULL); DIR *dir; struct dirent *ent; FILE *fp; char s[80],temp[80],c[5],f[50],a[2],p[2]; while(1){ printf("\nAP:>"); gets(s); if(strcmp(s,"exit")==0){ exit(0); } sscanf(s,"%s%s%s%s",c,a,f,p); printf("%s|%s|%s|%s",c,a,f,p); if(strcmp(c,"cat")!=0){ printf("invalid command"); }else if(strcmp(a,"<")==0 && strcmp(p,">")==0){ if((dir=opendir(f))==NULL){ perror("Unable to open direcotry."); exit(0); } while((ent= readdir(dir))!=NULL){ printf("%s\n",ent->d_name); } if(closedi...

Write the simulation program for Round Robin with time quantum of 2 units. The arrival of time and first CPU bursts of different jobs should be input to the system. The output should give the Gantt chart and waiting time for each process and average waiting time.

Write the simulation program for Round Robin with time quantum of 2 units. The arrival of time and first CPU bursts of different jobs should be input to the system. The output should give the Gantt chart and waiting time for each process and average waiting time. Program: #include <stdio.h> #include <stdlib.h> #include <conio.h> struct ps{ int at,wt,bt,ft,st; }pr[50], temp[50]; int rq[50], time,x,n,t; void add(){ int i; for(i=0;i<n;i++){ if(time==pr[i].at){ rq[x++]=i; } } } int select(){ int pp, i; if(x==0){ return(-1); }else{ pp = rq[0]; for(i=0;i<x;i++){ rq[i]=rq[i+1]; } x--; return(pp); } } int main(void){ setbuf(stdout,NULL); float awt; int i,p; t=0; time=0; x=0; printf("Enter the Number of processes:"); scanf("%d",&n); for(i=0;i<n;i++){ printf("\nEnter Arrival Time:"); scanf("%d",&pr[i].at); printf("\nEnter CPU burst time:"); scanf("%d...

Write a simulation program for scheduling algorithm using FCFS. The arrival time and first CPU burst of different jobs should be input to the system. The output should give the Gantt chart & turnaround time for each process and average turnaround time.

Write a simulation program for scheduling algorithm using FCFS. The arrival time and first CPU burst of different jobs should be input to the system. The output should give the Gantt chart & turnaround time for each process and average turnaround time. Program: #include <stdio.h> #include <stdlib.h> struct sch{ int at,st,bt,tat,ft; }pr[50]; int rq[50],x,n,timer; void addP(){ int i; for(i=0;i<n;i++){ if(pr[i].at==timer){ rq[x++]=i; } } } int selectP(){ int pp,i; if(x<0){ return(-1); }else{ pp=rq[0]; for(i=0;i<n;i++){ rq[i]=rq[i+1]; } x--; return(pp); } } int main(void){ setbuf(stdout,NULL); int i,t,p; float atat; timer = 0; x=-1; printf("Enter the number of processes:"); scanf("%d",&n); for(i=0;i<n;i++){ printf("\nEnter the Arrival time:"); scanf("%d",&pr[i].at); printf("\nEnter the Burst time:"); scanf("%d",&pr[i].bt); } t=0; addP(...

Write a Program to implement "ls" command of UNIX with following options on DOS

Write a Program to implement "ls" command of UNIX with following options on DOS. "ls" to display files. "ls -a" to display all the hidden files. "ls -m" to display the files separated with commas. Program: #include<stdio.h> #include<stdlib.h> #include<string.h> #include<dirent.h> void ls(){ DIR *d; struct dirent *dn; char dr[20]; printf("Enter the Directory name:"); gets(dr); if((d=opendir(dr))==NULL){ printf("\nDirectory can't open"); } else { while((dn=readdir(d))!=NULL){ printf(" %s",dn->d_name); } } } void lsm(){ DIR *d; struct dirent *dn; char dr[20]; printf("Enter the Directory name:"); gets(dr); if((d=opendir(dr))==NULL){ printf("\nDirectory can't open"); } else{ while((dn=readdir(d))!=NULL){ printf("%s,",dn->d...